Em dùng CSS để viết thì chương trình chạy ngon rồi, nhưng ko hiểu sao ra không đúng, mà hình như là nó ko chạy cái ngắt ngoài, các bác xem hộ em có sai chỗ nào không ạ:
#include <16F877A.h>
#include <DEFS_16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High power osc > 5Mhz
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=20000000)
//Thiet lap USART rate 9600,xuat chan C6, nhan chan C7, 8 bits
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
int i,j;
// Ngat ngoai
#INT_EXT
void EXT_isr(void)
{ i=i+1; // Bien i tang 1 khi co xung vao
if(i==100)
{i=0;
j=j+1;
write_eeprom(0x00,j);
}
TXREG=i;
}
// Ham chinh
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_EXT); //Cho ngat
enable_interrupts(GLOBAL);
ext_int_edge(L_TO_H); //Suon len
// TODO: USER CODE!!
TRISC=0b10111111; // Chan C6 la output
TRISB=0b11111110; // Chan B0 la input
if (read_eeprom(0x00)==0xff)
{write_eeprom(0x00,0);};
while(1)
{
// Dua du lieu vao thanh ghi USART
}
}
|