Mình đang làm một đề tài viết chương trình đồng hồ hiển thị lên LCD dùng DS1307. mình đã viết code nhưng khi nạp vào thì LCD chỉ hiện lên màn hình trắng mà không hoạt động gì nữa! Mình nghi ngờ chương trình bị rơi vào vòng lặp vô hạn nhưng mình tìm mãi cũng chưa biết lý do. Các bạn làm ơn giúp mình xem mình sai chõ nào. Cảm ơn nhiều.
Đây là chương trình
//////////////////////////////////////////////////////////////////
#include <16f877a.h>
#include <def_877a.h>
#device *=16 ADC=8
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#include <DS1307.c>
#include <LCD420.c>
//====================Global variable declaration===============================
int8 second, minute, hour;/*, date, day, mon, year,limit,limit1;
int16 year1;
int8 mode=-1;*/
//====================================MAIN========== ============================
void main(){
TRISB = 0x00;
PORTB = 0x00;
lcd_init();
delay_ms(10);
//================Hien Thi Ban Dau===================
init_DS1307();
// Set date : 12-4-2012
// Set time : thu 5 - 12 gio, 59 phút 10 giây
setDateDs1307(12,4,12,5,12,59,10);
delay_ms(10);
while(1)
{ Printf(lcd_putc,"\f"); //=========Clear LCD=========================
lcd_gotoxy( 1,1);
Printf(lcd_putc,"TIME: ");
second =read_DS1307(0x0);
lcd_gotoxy( 7,1);
Printf(lcd_putc,second/16 + 0x30);
Printf(lcd_putc,second%16 + 0x30);
lcd_gotoxy( 8,1);
Printf(lcd_putc,":");
minute =read_DS1307(0x01);
lcd_gotoxy( 9,1);
Printf(lcd_putc,minute/16 + 0x30);
Printf(lcd_putc,minute%16 + 0x30);
lcd_gotoxy( 10,1);
Printf(lcd_putc,":");
hour = read_DS1307(0x02);
lcd_gotoxy( 11,1);
Printf(lcd_putc,hour/16 + 0x30);
Printf(lcd_putc,hour%16 + 0x30);
}
}
/*
LCD_putcmd(0xC0);//=========Put Cursor on line 2: thu ngay thang nam ============
//thu
day =read_DS1307(0x03);
switch (day) {
case 1: Printf(LCD_putchar," SUN"); break;
case 2: Printf(LCD_putchar," MON"); break;
case 3: Printf(LCD_putchar," TUE"); break;
case 4: Printf(LCD_putchar," WEN"); break;
case 5: Printf(LCD_putchar," THU"); break;
case 6: Printf(LCD_putchar," FRI"); break;
case 7: Printf(LCD_putchar," SAT"); break;
}
Printf(LCD_putchar," ");
//ngay
date =read_DS1307(0x04);
LCD_putchar(day/16 + 0x30);
LCD_putchar(day%16 + 0x30);
Printf(LCD_putchar,"/");
//thang
mon=read_DS1307(0x05);
LCD_putchar(mon/16 + 0x30);
LCD_putchar(mon%16 + 0x30);
Printf(LCD_putchar,"/");
// nam
year=read_DS1307(0x06);
year=bcdToDec(year);
year1 = 2000 + year;
printf(lcd_putchar,"%ld",year1);
}
}
}
}
*/
/////////////////////////////////////////////////////////////////////////
Mình vừa từ 89c51 chuyển qua Pic nên lập trình còn có nhiều chỗ chưa biết....
Đây là chương trình
//////////////////////////////////////////////////////////////////
#include <16f877a.h>
#include <def_877a.h>
#device *=16 ADC=8
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#include <DS1307.c>
#include <LCD420.c>
//====================Global variable declaration===============================
int8 second, minute, hour;/*, date, day, mon, year,limit,limit1;
int16 year1;
int8 mode=-1;*/
//====================================MAIN========== ============================
void main(){
TRISB = 0x00;
PORTB = 0x00;
lcd_init();
delay_ms(10);
//================Hien Thi Ban Dau===================
init_DS1307();
// Set date : 12-4-2012
// Set time : thu 5 - 12 gio, 59 phút 10 giây
setDateDs1307(12,4,12,5,12,59,10);
delay_ms(10);
while(1)
{ Printf(lcd_putc,"\f"); //=========Clear LCD=========================
lcd_gotoxy( 1,1);
Printf(lcd_putc,"TIME: ");
second =read_DS1307(0x0);
lcd_gotoxy( 7,1);
Printf(lcd_putc,second/16 + 0x30);
Printf(lcd_putc,second%16 + 0x30);
lcd_gotoxy( 8,1);
Printf(lcd_putc,":");
minute =read_DS1307(0x01);
lcd_gotoxy( 9,1);
Printf(lcd_putc,minute/16 + 0x30);
Printf(lcd_putc,minute%16 + 0x30);
lcd_gotoxy( 10,1);
Printf(lcd_putc,":");
hour = read_DS1307(0x02);
lcd_gotoxy( 11,1);
Printf(lcd_putc,hour/16 + 0x30);
Printf(lcd_putc,hour%16 + 0x30);
}
}
/*
LCD_putcmd(0xC0);//=========Put Cursor on line 2: thu ngay thang nam ============
//thu
day =read_DS1307(0x03);
switch (day) {
case 1: Printf(LCD_putchar," SUN"); break;
case 2: Printf(LCD_putchar," MON"); break;
case 3: Printf(LCD_putchar," TUE"); break;
case 4: Printf(LCD_putchar," WEN"); break;
case 5: Printf(LCD_putchar," THU"); break;
case 6: Printf(LCD_putchar," FRI"); break;
case 7: Printf(LCD_putchar," SAT"); break;
}
Printf(LCD_putchar," ");
//ngay
date =read_DS1307(0x04);
LCD_putchar(day/16 + 0x30);
LCD_putchar(day%16 + 0x30);
Printf(LCD_putchar,"/");
//thang
mon=read_DS1307(0x05);
LCD_putchar(mon/16 + 0x30);
LCD_putchar(mon%16 + 0x30);
Printf(LCD_putchar,"/");
// nam
year=read_DS1307(0x06);
year=bcdToDec(year);
year1 = 2000 + year;
printf(lcd_putchar,"%ld",year1);
}
}
}
}
*/
/////////////////////////////////////////////////////////////////////////
Mình vừa từ 89c51 chuyển qua Pic nên lập trình còn có nhiều chỗ chưa biết....
Comment