|
Tài trợ cho PIC Vietnam |
PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip |
|
Ðiều Chỉnh | Xếp Bài |
21-05-2011, 12:59 AM | #1 |
Nhập môn đệ tử
Tham gia ngày: Oct 2010
Bài gửi: 8
: |
help!! lcd bị giật
em đang làm đồ án ds1307 hiển thị lcd nhưng sao lcd nó bị giật.
;////////////////// đây là code////////// #include <16F877A.h> #include <def_877a.h> #FUSES NOWDT, HS, PUT, NOPROTECT #use DELAY(clock=12000000) #use i2c(master,fast,sda=PIN_C4,scl=PIN_C3) // Hai chan RC4 RC3 dung de giao tiep i2c #define giay_ch 0x8b #define giay_dv 0x8c #define phut_ch 0x88 #define phut_dv 0x89 #define gio_ch 0x85 #define gio_dv 0x86 #define ngay_ch 0xc5 #define ngay_dv 0xc6 #define thang_ch 0xc8 #define thang_dv 0xc9 #define nam_ch 0xcb #define nam_dv 0xcc #define RS RB5 #define RW RB6 #define E RB7 #define LCD PORTD int8 sec,min,hour,date,month,year,day; int8 sec1,sec2,min1,min2,hour1,hour2,date1,date2,month1 ,month2,year1,year2; void commwrite(); void datawrite(); void setup_lcd(); void update_time(); void bin_bcd(); void ht_lcd_text(); void ht_lcd_data(); void commwrite() //Ham yeu cau goi lenh de dieu khien LCD { RS=0; RW=0; E=1; E=0; delay_ms(1); } void datawrite() //Ham yeu cau goi du lieu hien thi len LCD { RS=1; RW=0; E=1; E=0; delay_ms(1); } void setup_lcd() //Ham cai dat che do cho LCD { LCD=0x01; //Xoa man hinh LCD commwrite(); LCD=0x38; //Cai dat LCD hien thi 2 dong commwrite(); LCD=0x0C; //Dieu khien hien thi commwrite(); } void update_time() { i2c_start(); i2c_write(0xD0); //Gui lenh ghi du lieu */dia chi DS1307<<1|write=0 bat dau ghi i2c_write(0x07); //thiet lap d/c - thanh ghi thiet lap trang thai lam viec ds1307 i2c_write(0x10); //tao f=1hz tai chan 7 (ds1307) i2c_stop(); //|restar i2c i2c_start(); //| i2c_write(0xD0); i2c_write(0x00); i2c_start(); i2c_write(0xD1); //dia chi DS1307<<1|read=1 bat dau doc sec = i2c_read(); min = i2c_read(); hour = i2c_read(); day = i2c_read(); date = i2c_read(); month = i2c_read(); year = i2c_read(0); i2c_stop(); } void bin_bcd() { sec1=sec & 0x0F; sec2=sec & 0x70;//convert to BCD SEC sec2=sec2>>4; sec1=sec1+0x30;//dua ve ma chuan de hien thi LCD sec2=sec2+0x30;//dua ve ma chuan de hien thi LCD min1=min & 0x0F; min2=min & 0x70;//convert to BCD SEC min2=min2>>4; min1=min1+0x30;//dua ve ma chuan de hien thi LCD min2=min2+0x30;//dua ve ma chuan de hien thi LCD hour1=hour & 0x0F; hour2=hour & 0x30;//convert to BCD SEC hour2=hour2>>4; hour1=hour1+0x30;//dua ve ma chuan de hien thi LCD hour2=hour2+0x30;//dua ve ma chuan de hien thi LCD //ngay date1=date & 0x0F; date2=date & 0x30;//convert to BCD SEC date2=date2>>4;//dich 4bit cao xuong 4bit thap date1=date1+0x30;//dua ve ma chuan de hien thi LCD date2=date2+0x30;//dua ve ma chuan de hien thi LCD //thang month1=month & 0x0F; month2=month & 0x10;//convert to BCD SEC month2=month2>>4;//dich 4bit cao xuong 4bit thap month1=month1+0x30;//dua ve ma chuan de hien thi LCD month2=month2+0x30;//dua ve ma chuan de hien thi LCD //nam year1=year & 0x0F; year2=year & 0xf0;//convert to BCD SEC year2=year2>>4;//dich 4bit cao xuong 4bit thap year1=year1+0x30;//dua ve ma chuan de hien thi LCD year2=year2+0x30;//dua ve ma chuan de hien thi LCD } void ht_lcd_text() { setup_lcd(); LCD=0x80; commwrite(); LCD=('T'); datawrite(); LCD=('i'); datawrite(); LCD=('m'); datawrite(); LCD=('e'); datawrite(); LCD=(':'); datawrite(); LCD=0x38; commwrite(); LCD=0xC0; commwrite(); LCD=('D'); datawrite(); LCD=('a'); datawrite(); LCD=('t'); datawrite(); LCD=('e'); datawrite(); LCD=(':'); datawrite(); } void ht_lcd_data() { setup_lcd(); LCD=0x85; commwrite(); LCD=(hour2); datawrite(); LCD=(hour1); datawrite(); LCD=(' '); datawrite(); LCD=(min2); datawrite(); LCD=(min1); datawrite(); LCD=(' '); datawrite(); LCD=(sec2); datawrite(); LCD=(sec1); datawrite(); LCD=0xC5; commwrite(); LCD=(date2); datawrite(); LCD=(date1); datawrite(); LCD=('/'); datawrite(); LCD=(month2); datawrite(); LCD=(month1); datawrite(); LCD=('/'); datawrite(); LCD=(year2); datawrite(); LCD=(year1); datawrite(); } void main() { trisa=0x00; // Cong A lam dau ra trisb=0x01; // Cong B lam dau ra (tru RB0) trisd=0x00; // Cong D lam dau ra while(true) { update_time(); bin_bcd(); ht_lcd_text(); ht_lcd_data(); delay_ms(10); } } thay đổi nội dung bởi: minhkhoa1990, 21-05-2011 lúc 01:15 AM. |