![]() |
![]() |
#12 | |
Đệ tử 7 túi
Tham gia ngày: May 2005
Bài gửi: 258
: |
Trích:
Một vài gợi ý cho bạn: Code:
#include <16F877A.h> #device *=16 adc=10 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=4000000) #include <lcd.c> #define LCD_DATA_PORT getenv("SFR:PORTD") #define LCD_ENABLE_PIN PIN_D0 //// #define LCD_RS_PIN PIN_D1 //// #define LCD_RW_PIN PIN_D2 #define LCD_DATA4 PIN_D4 //// #define LCD_DATA5 PIN_D5 //// #define LCD_DATA6 PIN_D6 //// #define LCD_DATA7 PIN_D7 //// #byte portB =0x06 //// #bit B1= portB.1 //// #bit B2= portB.2 //// #bit B3= portB.3 int8 K,I,D,chon=0; void push_key(void); main() { set_tris_b(0b00001110); port_b_pullups(true); set_tris_c(0b00000000); lcd_init(); lcd_gotoxy(1,1); // cot 1 hang 1 lcd_putc("Menu controler"); lcd_gotoxy(1,2); lcd_putc("K="); while(1) { push_key(); } } void push_key() { int count; if(B1==0) //nut o chan B1 duoc nhan[tăng] { delay_ms(10); //delay qua xung nhieu while(B1==0) //cho den khi tha {;} // tại đây so sánh biến chọn[dùng switch] // nếu chon=1 tăng K,rồi xuất ra LCD // nếu chon=2 tăng I,rồi xuất ra LCD // nếu chon=3 tăng D,rồi xuất ra LCD count++; //dem so lan bam nut lcd_gotoxy(3,2); lcd_putc(" "); lcd_gotoxy(3,2); Printf(LCD_putc,"%u",count); // hiển thị số count đếm lên LCD delay_ms(10); //delay qua xung nhieu } else if(B2==0) //nut o chan b2 duoc nhan[giảm] { delay_ms(10); while(B2==0) {;} // tại đây so sánh biến chọn // nếu chon=1 giảm K,rồi xuất ra LCD // nếu chon=2 giảm I,rồi xuất ra LCD // nếu chon=3 giảm D,rồi xuất ra LCD count--; //dem so lan bam nut lcd_gotoxy(3,2); lcd_putc(" ");// lcd_gotoxy(3,2); Printf(LCD_putc,"%u",count); // hiển thị số count đếm lên LCD delay_ms(10); //delay qua xung nhieu } else if(B3==0) //nut o chan b3 duoc nhan[chọn K,I,D] { delay_ms(10); while(B3==0) {;} chon++; if(chon>=4) { chon=0; } delay_ms(10); } else { }
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề. thay đổi nội dung bởi: tdm, 21-02-2011 lúc 01:47 PM. |
|
![]() |
![]() |
|
|