sửa lại như hình gửi kèm thì nó chạy thôi.
code của em chạy cũng được ,nhưng có nhược điểm khi chuyển chế độ khác nó phải làm hết chế độ cũ rồi mới chuyển.
Code:
#include <16F877A.h>
#FUSES NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=4000000)
int8 mode,i;
byte temp;
#byte portb=0x06
#byte portd=0x08
#byte trisb=0x86
#byte trisd=0x88
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#INT_EXT
EXT_ISR(){
mode++;
if(mode==5) mode=0;
}
void pro1();
void pro2();
void pro3();
void pro4();
void main(){
trisd=0x00;
trisb=0b00000001;
portd=0xff;
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
mode=0;
while(1)
{ switch(mode){
case 0:
portd=0xff;
break;
case 1:pro1();break;
case 2:pro2();break;
case 3:pro3();break;
case 4:pro4();break;
}}
}
//+++++++++++++++++++++++++++++++++++
void pro1(){
portd=0b11111111;
delay_ms(200);
portd=0b00000000;
delay_ms(200);
}
//+++++++++++++++++++++++++++++++++
void pro2(){
temp=0xFF;
for(i=0;i<=8;i++)
{ portd=temp;
delay_ms(50);//chèn thêm lệnh này cho dễ quan sát
temp>>=1;
}
}
//+++++++++++++
void pro3(){
temp=0xFF;
for(i=0;i<=8;i++)
{ portd=temp;
delay_ms(50);//chèn thêm lệnh này cho dễ quan sát
temp<<=1;
}}
//++++++++++++++++++
void pro4(){
portd=0b11110000;
delay_ms(200);
portd=0b00001111;
delay_ms(200);
}