標(biāo)題:
單片機(jī)萬年歷設(shè)計(jì)簡單1602顯示ds1302采集系統(tǒng) Proteus仿真程序
[打印本頁]
作者:
搬哪去啊
時間:
2019-12-18 16:49
標(biāo)題:
單片機(jī)萬年歷設(shè)計(jì)簡單1602顯示ds1302采集系統(tǒng) Proteus仿真程序
根據(jù)電路圖,編寫程序使得LCD1602顯示器顯示DS1302時鐘芯片當(dāng)前年、月、日、十、分和秒信息。
附件包含對應(yīng)仿真和C程序
51hei.png
(28.37 KB, 下載次數(shù): 50)
下載附件
2019-12-18 21:33 上傳
單片機(jī)源程序如下:
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char
sbit IO=P1^1;
sbit SCLK=P1^0;
sbit RST=P1^2;
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
uchar *WEEK[]=
{
"SUN","***","MON","TUS","WEN","THU","FRI","SAT"
};
uchar LCD_DSY_BUFFER1[]={"DATE 00-00-00 "};
uchar LCD_DSY_BUFFER2[]={"TIME 00:00:00 "};
uchar DateTime[7];
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{ for(i=0;i<120;i++); }
}
void Write_A_Byte_TO_DS1302(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{ IO=x&0x01;SCLK=1;SCLK=0;x>>=1; }
}
uchar Get_A_Byte_FROM_DS1302()
{
uchar i,b=0x00;
for(i=0;i<8;i++)
{
b |= _crol_((uchar)IO,i);
SCLK=1;SCLK=0;
}
return b/16*10+b%16;
}
uchar Read_Data(uchar addr)
{
uchar dat;
RST=0;SCLK=0;RST=1;
Write_A_Byte_TO_DS1302(addr);
dat=Get_A_Byte_FROM_DS1302();
SCLK=1;RST=0;
return dat;
}
void GetTime()
{
uchar i,addr=0x81;
for(i=0;i<7;i++)
{ DateTime[i]=Read_Data(addr);addr+=2; }
}
uchar read_lcd_state()
{
uchar state;
RS=0;RW=1;EN=1;DelayMS(1);
state=P0;
EN=0;DelayMS(1);
return state;
}
void lcd_busy_wait()
{
while((read_lcd_state()&0x80)==0x80);
DelayMS(5);
}
void write_lcd_data(uchar dat)
{
lcd_busy_wait();
RS=1;RW=0;EN=0;P0=dat;EN=1;DelayMS(1);
EN=0;
}
void write_lcd_command(uchar dat)
{
lcd_busy_wait();
RS=0;RW=0;EN=0;P0=dat;EN=1;DelayMS(1);
EN=0;
}
void init_lcd()
{
write_lcd_command(0x38);
DelayMS(1);
write_lcd_command(0x01);
DelayMS(1);
write_lcd_command(0x06);
DelayMS(1);
write_lcd_command(0x0c);
DelayMS(1);
}
void set_lcd_pos(uchar p)
{
write_lcd_command(p|0x80);
}
void Display_LCD_String(uchar p,uchar *s)
{
uchar i;
set_lcd_pos(p);
for(i=0;i<16;i++)
{
write_lcd_data(s[i]);
DelayMS(1);
}
}
void Format_DateTime(uchar d,uchar *a)
{
a[0]=d/10+'0';
a[1]=d%10+'0';
}
void main()
{
init_lcd();
while(1)
{
GetTime();
Format_DateTime(DateTime[6],LCD_DSY_BUFFER1+5);
Format_DateTime(DateTime[4],LCD_DSY_BUFFER1+8);
Format_DateTime(DateTime[3],LCD_DSY_BUFFER1+11);
strcpy(LCD_DSY_BUFFER1+13,WEEK[DateTime[5]]);
Format_DateTime(DateTime[2],LCD_DSY_BUFFER2+5);
Format_DateTime(DateTime[1],LCD_DSY_BUFFER2+8);
Format_DateTime(DateTime[0],LCD_DSY_BUFFER2+11);
Display_LCD_String(0x00,LCD_DSY_BUFFER1);
Display_LCD_String(0x40,LCD_DSY_BUFFER2);
}
}
復(fù)制代碼
所有資料51hei提供下載:
萬年歷設(shè)計(jì).zip
(150.13 KB, 下載次數(shù): 25)
2019-12-18 16:46 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1