目的:將8個led燈分成兩組,這兩組輪流點亮 程序1: #include<iom128v.h> #include<macros.h> #define uint unsigned int #define uchar unsigned char
void delay(uint del) { uint i,j; for(i=0;i<del;i++) for(j=0;j<1241;j++) ; } void main() { DDRA=0xff; PORTA=0xf0; while(1) { DDRE=DDRE|BIT(2); PORTE=PORTE|BIT(2); DDRA=0xff; PORTA=~PORTA; delay(1000); //延遲1s } }
程序2: #include<iom128v.h> #include<macros.h> #define uint unsigned int #define uchar unsigned char
void main() { DDRA=0xff; PORTA=0xf0; while(1) { uint i,j; DDRE=DDRE|BIT(2); PORTE=PORTE|BIT(2); DDRA=0xff; PORTA=~PORTA; for(i=0;i<1000;i++) //延遲1s { for(j=0;j<1241;j++) ; } } }
第二個程序可以實現(xiàn),第一個卻不能實現(xiàn),為什么呢?
|