E đã viết nhiều chương trình cho con 8051 sử dụng ngắt ngoài, nhưng vẫn chưa hiểu khi có ngắt ngoài xảy ra >> VĐK nó thực hiện xong chương trình con phục vụ ngắt thì nó sẽ chạy từ chỗ nào trong chương trình chính?
Chẳng hạn chương trình này:
Khi có ngắt ngoài thì biến n tăng lên 1, nhưng chương trình chính vẫn chạy như không có gì thay đổi??
Bác nào đã gặp phải vấn đề này rồi thì giúp e với!
Chẳng hạn chương trình này:
Code:
#include<stdio.h> #include<reg52.h> // Chuong trinh 10leds quay trong khong gian hien thi dong chu DHCNHN unsigned char code START[]={0x33,0xCC,0x33,0xCC}; unsigned char code DHCN1[140]={ //Port 0 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //space 0xEF,0,0,0xEE,0xFE,0xFD,1,3,0xFF, //D 0,0,0xEF,0xEF,0xEF,0,0,0xFF,0xFF, //H 3,1,0xFE,0xFE,0xFE,0xFD,0xFF, //C 3,1,0xFE,0xFE,0xFE,1,3,0xFF, //O 0,0,0xF9,0xF3,0xE7,0,0,0xFF, //N 3,1,0xFE,0xFE,0xDE,0x1D,0x1F,0xFF,0xFF, //G 0,0,0xF9,0xF3,0xE7,0,0,0xFF, //N 3,1,0xFE,0xFE,0xDE,0x1D,0x1F,0xFF, //G 0,0,0xEF,0xEF,0xEF,0,0,0xFF, //H 0,0,0xFF, //I 0,0,0xEE,0xEE,0xEE,0xEE,0xFF, //E 0,0,0xDE,0xDE,0xDE,0xE1,0xE3,0xFF,0xFF, //P 0,0,0xEF,0xEF,0xEF,0,0,0xFF, //H 3,1,0xEE,0xEE,0xEE,1,3,0xFF,0xFF, //A 0,0,0xF9,0xF3,0xE7,0,0,0xFF, //N 3,1,0xFE,0xFE,0xFE,1,3,0xFF, //O 0,0, //I 0xFF,0xFF }; unsigned char code DHCN2[140]={ //Port 2 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //space 0xFF,0xFC,0xFC,0xFD,0xFD,0xFE,0xFE,0xFF,0xFF, //D 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF,0xFF, //H 0xFF,0xFE,0xFD,0xFD,0xFD,0xFE,0xFF, //C 0xFF,0xFE,0xFD,0xFD,0xFD,0xFE,0xFF,0xFF, //O 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF, //N 0xFF,0xFE,0xFD,0xFD,0xFD,0xFE,0xFE,0xFF,0xFF, //G 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF, //N 0xFF,0xFE,0xFD,0xFD,0xFD,0xFE,0xFE,0xFF, //G 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF, //H 0xFC,0xFC,0xFF, //I 0xFC,0xFC,0xFD,0xFD,0xFD,0xFD,0xFF, //E 0xFC,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //P 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF, //H 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF,0xFF, //A 0xFC,0xFC,0xFF,0xFF,0xFF,0xFC,0xFC,0xFF, //N 0xFF,0xFE,0xFD,0xFD,0xFD,0xFE,0xFF,0xFF, //O 0xFC,0xFC, //I 0xFF,0xFF }; unsigned long int i,k,n,m; void delay (long int t) { unsigned long int j; for(j=0;j<=t;j++); } void main(void) { IE=0x81; //Cho phep ngat ngoai 0 while(n<10) //kiem tra so vong quay motor nho hon 10 //muc dich de buc anh duoc quet 10 lan for(k=0;k<=100;k++) for(i=0;i<=1;i++) { P0= START[i]; P2= START[i+2]; delay(10000); } while(n>=10) //lon hon 10 thi hien thi dong chu DHCNHN for(i=0;i<=139;i++) { P0=DHCN1[i]; P2=DHCN2[i]; delay(10000); } } void ngat0(void) interrupt 0 //ngat ngoai 0 dem so vong quay motor { n++; }
Bác nào đã gặp phải vấn đề này rồi thì giúp e với!
Comment