这个实验结合lcd1602和ds1302实现实时时钟.详情见附件.
平台:FDRAVR开发板
主程序代码:
#include <mega16.h>
#asm
.equ __ds1302_port=0x12 ;PORTD
.equ __ds1302_io=3
.equ __ds1302_sclk=2
.equ __ds1302_rst=4
#endasm
#include <ds1302.h>
#include "lcd1602.h"
unsigned char date,year,month,hour,minute,second;
void display_dat() //显示时间和温度的函数
{
CLEARSCREEN;
LCD_write_flash(0,0,"DAT:");
LCD_write_int(5,0,2000+year); //显示年份
LCD_en_dat('-');
LCD_write_int(10,0,month/10); //显示月份
LCD_write_int(11,0,month%10);
LCD_en_dat('-');
LCD_write_int(13,0,date/10); //显示日期
LCD_write_int(14,0,date%10);
LCD_write_flash(0,1,"TIME:"); //显示时间
LCD_write_int(5,1,hour/10); //显示小时
LCD_write_int(6,1,hour%10);
LCD_en_dat(':');
LCD_write_int(8,1,minute/10); //显示分钟
LCD_write_int(9,1,minute%10);
LCD_en_dat(':');
LCD_write_int(11,1,second/10); //显示秒
LCD_write_int(12,1,second%10);
}
void main(void)
{
LCD_init();//初时化液晶
LCD_write_flash(0,0,"Ready");
rtc_init(0,0,0);//初时化时钟
rtc_set_date(29,3,7);
rtc_set_time(17,2,30);
while (1)
{
delay_ms(100);
rtc_get_date(&date,&month,&year);
rtc_get_time(&hour,&minute,&second);
display_dat();//显示时间
};
}
文章评论(0条评论)
登录后参与讨论