![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#2 |
Đệ tử 6 túi
Tham gia ngày: Jul 2007
Bài gửi: 154
: |
lcd
bạn điều chỉnh biết trở để điều chỉnh độ sáng của lcd xem sao
các bài dưới chạy tốt bạn đổi các chân theo đúng phần cứng của bạn rồi test thử nhé #include <16F877a.h> #fuses XT,NOWDT,NOPROTECT,NOLVP #device 16F877*=16 ADC=8 #use delay(clock=4000000) #use fast_io(a) #byte porta=0x05 #use fast_io(b) #byte portb=0x06 #use fast_io(c) #byte portc=0x07 #use fast_io(d) #byte portd=0x08 #use fast_io(e) #byte porte=0x09 #bit RS = portA.0 #bit RW = portA.1 #bit E = portA.2 #define LCD PORTB /*Ham yeu cau goi lenh dieu khien LCD*/ void command() { RS = 0; RW = 0; E = 1; E = 0; delay_ms(1); } /*Ham yeu cau goi du lieu hien thi len LCD*/ void display() { RS = 1; RW = 0; E = 1; E = 0; delay_ms(1); } ///////////////////////////////////////////////// void main(void) { set_tris_B(0); set_tris_A(0); delay_ms(100); // Tao tre 100ms cho LCD khoi dong LCD = 0x38; // Hai hang, ma tran dot 5*7, 8 bit interface command(); LCD = 0x0C; // Bat hien thi, tat con tro command(); //------------------------------------------------- LCD = 0x85; // Vi tri hang 1,cot 6 command(); //------------------------------------------------- // Xuat dong chu "HOC PIC" ra LCD LCD = 'H'; display(); LCD = 'O'; display(); LCD = 'C'; display(); LCD = ' '; display(); LCD = 'P'; display(); LCD = 'I'; display(); LCD = 'C'; display(); //-------------------------------------------- LCD = 0xc4; // Vi tri hang 2,cot 5 command(); //------------------------------------------------- // Xuat dong chu "HOC PIC" ra LCD LCD = 'B'; display(); LCD = 'A'; display(); LCD = 'N'; display(); LCD = 'G'; display(); LCD = ' '; display(); LCD = ' '; display(); LCD = 'C'; display(); LCD = 'C'; display(); LCD = 'S'; display(); } /======================== #include <16F877a.h> #fuses XT,NOWDT,NOPROTECT,NOLVP #device 16F877*=16 ADC=8 #use delay(clock=4000000) #use fast_io(a) #byte porta=0x05 #use fast_io(b) #byte portb=0x06 #use fast_io(c) #byte portc=0x07 #use fast_io(d) #byte portd=0x08 #use fast_io(e) #byte porte=0x09 #bit RS = portA.0 #bit RW = portA.1 #bit E = portA.2 #define LCD PORTB unsigned char hocpic[] = "HOC PIC DUNG CCS"; /*Ham yeu cau goi lenh dieu khien LCD*/ void command() { RS = 0; RW = 0; E = 1; E = 0; delay_ms(1); } /*Ham yeu cau goi du lieu hien thi len LCD*/ void display() { RS = 1; RW = 0; E = 1; E = 0; delay_ms(1); } ///////////////////////////////////////////////// void main(void) { INT I; set_tris_B(0); set_tris_A(0); delay_ms(100); // Tao tre 100ms cho LCD khoi dong LCD = 0x38; // Hai hang, ma tran dot 5*7, 8 bit interface command(); LCD = 0x0C; // Bat hien thi, tat con tro command(); //------------------------------------------------- LCD = 0x85; // Vi tri hang 1,cot 6 command(); //------------------------------------------------- // Xuat dong chu "HOC PIC" ra LCD for(i=0;i<7;i++) { LCD = hocpic[i]; display(); } //------------------------------------------------- LCD = 0xC4; // Vi tri hang 1,cot 6 command(); //------------------------------------------------- // Xuat dong chu "HOC PIC" ra LCD for(i=8;i<17;i++) { LCD = hocpic[i]; display(); } delay_ms(1000); for (i=0;i<=2;i++) { lcd = 0x08; command(); delay_ms(500); //=========================== lcd = 0x0C; command(); delay_ms(1000); } } /================== thay đổi nội dung bởi: tungtot_vl, 16-04-2009 lúc 04:32 PM. Lý do: thieu |
![]() |
![]() |
|
|