资源描述
Proteus仿真图: LCD! Lh/blELI/OSCLKRST:1VCC2VCC1JXTAL1PO.OfADDP0.KAD1P0.2fAD2XTAL2P0.3fAD3PO.4fAC4P0.5fAD5po.erADBRSTP0.7iAD7P2 0/A8P2.1/A9P2.2/A10PSENP2.3/AT1ALEP2.4/A12EAP2.5/A13P2.6/A14P2.7/A15P1 .DP3.0JRXDPI .1P3.1 iTXDPI .2P3.2JINT0PI .3P3.3JINT1P1.4P3.4.-TDPI .5P3.5JTIPI .BP3.6JWRP1 7F37.iRD仿真程序:#include#include#include#define uint unsigned int#define uchar unsigned char/*LCD*sbit LCDRS=P2A0;/LCD数据/命令选择端sbit LCDRW=P2A1;sbit LCDEN=P2A2;/LCD使能新号端/*DS1302*sbit IO=P1A0;/1302数据线sbit SCLK=P1A1;sbit RST=P1A2;/1302时钟线复位uint num=0;/uchar *week=SUN,*,MON,TUS,WEN,THU,FRI,SAT;uchar Date=Date: 2000-00-00 ;uchar Time=Time: *00:00-00* ;uchar date_time7;/从ds1302读取的当前日期时间/=延时= void delay(uint z)uint x,y;for(x=z;x0;x-)for(y=110;y0;y-);*向 1302 写数据*void write_ds1302(uchar dat)uchar i;for(i=0;i= 1;/*从 1302 读数据*uchar read_ds1302()uchar i,b=0x00;for(i=0;i8;i+)b 1= _crol_(uchar)IO,i);SCLK=1;delay(1);SCLK=0;return b/16*10+b%16;*从指定位置读数据*uchar read_data(uchar addr)uchar dat;RST=0;SCLK=0;RST=1;write_ds1302(addr);dat=read_ds1302();SCLK=1;RST=0;return dat;/*读取当前日期时间*void read_date_time()uchar i,addr=0x81;for(i=0;i7;i+)date_timei=read_data(addr);addr+=2;/与BCD码转换LCD写指令void lcd_write_com(uchar com)LCDRS=0;/RS为0时,写指令,RS为1时,P0=com;delay(5);写数据LCDEN=1;delay(5);LCDEN=0;/LCD写数据void lcd_write_data(uchar dat) LCDRS=1; P0=dat; delay(5); LCDEN=1; delay(5); LCDEN=0; /LCD初始化/LCD显示模式设置/LCD显示开/关及光标设置当写一个字符后地址指针加1,且光标显示清屏void lcd_init() LCDEN=0; lcd_write_com(0x38); lcd_write_com(0x0c); lcd_write_com(0x06);加1 lcd_write_com(0x01);/设置液晶显示位置void set_lcd_pos(uchar p)lcd_write_com(p | 0x80);/液晶显示程序void lcd_print(uchar p,uchar *s) set_lcd_pos(p);for(num=0;num16;num+) lcd_write_data(snum);delay(10);/日期时间转换void format_datetime(uchar d,uchar *p)p0=d/10+0;p1=d%10+0;/主程序void main()LCDRW=0;lcd_init();while(1)read_date_time();format_datetime(date_time6,Date+8);/年月日format_datetime(date_time4,Date+11);format_datetime(date_time3,Date+14);/ strcpy(Date+13,weekdate_time5);format_datetime(date_time2,Time+7);时间转换format_datetime(date_time1,Time+10);format_datetime(date_time0,Time+13);lcd_print(0x00,Date);lcd_print(0x40,Time);
展开阅读全文