14-01-2008, 09:06 AM | #10 |
Đệ tử 5 túi
Tham gia ngày: Sep 2006
Bài gửi: 100
: |
Đầu tiên là thử quét phím bằng timer0 (chưa thử bấm nhanh hay bấm lấu)
Code:
#include <16F877A.h> #include <def_877a.h> #device *=16 adc=10 #FUSES NOWDT, XT, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=4000000) #use fast_io (b) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9) #define OK PIN_B6 #define Cancel PIN_B7 #define OK_PRESSED !input(OK) #include <lcd_lib_4bit.c> int8 count; char phim; int8 isr_count; #int_TIMER0 void interrupt_timer0() { if(OK_PRESSED) { isr_count++; if(isr_count==81) { isr_count==0; disable_interrupts(GLOBAL); disable_interrupts(INT_TIMER0); } } else { disable_interrupts(GLOBAL); disable_interrupts(INT_TIMER0); } } //----------------------------------------------------------------- void main(void) { output_b(0xC0); set_tris_a(0xC0); set_tris_b(0xC1); port_b_pullups (TRUE); LCD_init(); delay_ms(500); LCD_putcmd(0x80); Printf(LCD_putchar,"Hi ev'body"); //Hien thi man hinh 1 LCD_putcmd(0xC0); Printf(LCD_putchar,"Khoi tao..."); if(OK_PRESSED) { //enable timer0 enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); } if(isr_count==0) { LCD_putcmd(0x01); //xoa man hinh LCD_putcmd(0x80); Printf(LCD_putchar,"Enter Pressed"); //Hien thi man hinh 2 } }
__________________
Do more than exist, LIVE |
Ðiều Chỉnh | |
Xếp Bài | |
|
|