|
無(wú)按鍵操作
# 元器件
LCD1602的元器件是LM016L
# 文件介紹
除了未測(cè)試文件夾下的代碼不能使用,其它三份都可以在仿真圖上使用。
ds1302+lcd1602_1:摘抄自仿真圖鏈接中的代碼;
ds1302+lcd1602_2:是對(duì)仿真圖鏈接代碼的分解版本;
my1302:是修改過(guò)的版本,按照需要條件,可以加入別的項(xiàng)目直接調(diào)用;
未測(cè)試:忘了是從哪摘抄的了,沒有對(duì)應(yīng)得仿真圖,無(wú)法測(cè)試。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機(jī)源程序如下:
- /*
- 時(shí)間:2019/01/30 11:47
- */
- /*
- 51單片機(jī):DS1302+LCD1602 Proteus 仿真程序。
- 功能:LCD1602時(shí)鐘與日期的顯示。
- 仿真結(jié)果:LCD1602顯示設(shè)定的時(shí)間與日期。
- */
- #include <reg52.h>
- #include "ds1302.h"
- /**********LCD1602接口程序**********/
- #define LCD_PORT P1//液晶LCD1602數(shù)據(jù)
- sbit RS = P2^4;
- sbit RW = P2^5;
- sbit E= P2^6;
- bit ReadRTC_Flag; //讀DS1302標(biāo)志。1為讀 0為不讀。
- unsigned char time_buf1[7] = {34,2,16,23,59,50,7}; // 年月日時(shí)分秒周 2014-02-16 23:59:50 7周
- unsigned char time_buf[7] ;
- char data str1[16]="Date: ? ?";
- char data str2[16]="Time: ? ?";
- void InitTIMER0(void);//inital timer0
- // LCD1602函數(shù)聲明
- void Delay_1ms(unsigned char i);
- void Delay_10us(unsigned char i);
- void Write_Cmd(unsigned char cmd);
- void Write_Dat(unsigned char dat);
- void Addr_x_y(unsigned char x,bit y);
- void Show_Char(unsigned char x,bit y,unsigned char p);
- void Show_String(unsigned char x,bit y,char *ptr);
- void LCD_Init(void);
- void main(void)
- {
- LCD_Init();
- DS1302_Init();
- DS1302_Write_Time();
- InitTIMER0();
- //P2=0xff; ? //51默認(rèn)為輸入
- while(1)
- {
- if(ReadRTC_Flag==1)
- {
- ReadRTC_Flag=0;
- DS1302_Read_Time();
- }
- str1[5]=time_buf1[0]/10 + '0'; //年 數(shù)據(jù)的轉(zhuǎn)換,
- str1[6]=time_buf1[0]%10 + '0'; //因我們采用數(shù)碼管0~9的顯示,將數(shù)據(jù)分開
- str1[7]=0x2d; //加入"-"
- str1[8]=time_buf1[1]/10 + '0'; //月
- str1[9]=time_buf1[1]%10 + '0';
- str1[10]=0x2d;
- str1[11]=time_buf1[2]/10 + '0'; //日
- str1[12]=time_buf1[2]%10 + '0';
- str1[13]=0x20;
- str1[14]='W';
- str1[15]=time_buf1[6] + '0'; //周幾
- str2[5]=time_buf1[3]/10 + '0'; //時(shí) 數(shù)據(jù)的轉(zhuǎn)換,
- str2[6]=time_buf1[3]%10 + '0'; //因我們采用數(shù)碼管0~9的顯示,將數(shù)據(jù)分開
- str2[7]=0x3a;//加入"-"
- str2[8]=time_buf1[4]/10 + '0'; //分
- str2[9]=time_buf1[4]%10 + '0';
- str2[10]=0x3a;
- str2[11]=time_buf1[5]/10 + '0'; //秒
- str2[12]=time_buf1[5]%10 + '0';
- Show_String(0,0,str1);
- Show_String(0,1,str2);
- }
- }
- /********************************/
- void Delay_1ms(unsigned char i) //最小延時(shí)1ms
- {
- unsigned char j;
- while(i--)
- ;
- for(j=0;j<125;j++)
- ;
- }
- void Delay_10us(unsigned char i) //最小延時(shí)10us
- {
- unsigned char j;
- while(i--)
- for(j=0;j<10; j++)
- ;
- }
- void Write_Cmd(unsigned char cmd)//寫指令
- {
- Delay_10us(5);
- E=0;
- RS=0;
- RW=0;
- LCD_PORT=cmd;
- Delay_10us(5); //>40us
- E=1;
- Delay_1ms(2); //>150us
- E=0;
- Delay_10us(4); //>25+10us?
- }
- void Write_Dat(unsigned char dat) //寫數(shù)據(jù)
- {
- Delay_10us(5);
- E=0;
- RS=1;
- RW=0;
- LCD_PORT = dat;
- Delay_10us(5);
- E=1;
- Delay_10us(5);
- E=0;
- Delay_10us(4);
- }
- void Addr_x_y(unsigned char x,bit y) //寫坐標(biāo),定位置
- {
- unsigned char temp=0x80; //默認(rèn)最高位:D7為1 即以0x80開始。 ?
- if(y) //y :0為第一行 ?1為第二行
- {
- temp|=0x40;
- }
- temp|=x;
- Write_Cmd(temp);
- }
- void Show_Char(unsigned char x,bit y,unsigned char p)
- //在指定位置顯示一個(gè)字符。
- {
- Addr_x_y(x,y);
- Write_Dat(p);
- }
- void Show_String(unsigned char x,bit y,char *ptr)
- {
- unsigned char i;
- for (i=0;i<16;i++)
- Show_Char(x++,y,*(ptr+i));//循環(huán)顯示16個(gè)字符
- }
- void LCD_Init(void) //1602初始化代碼
- {
- Delay_1ms(1500);
- Write_Cmd(0x38);
- Delay_1ms(5);
- Write_Cmd(0x38);
- Delay_1ms(5);
- Write_Cmd(0x38);
- Delay_1ms(5);
- Write_Cmd(0x38);
- Write_Cmd(0x08);
- Write_Cmd(0x06);
- Write_Cmd(0x0c);
- Write_Cmd(0x01);
- }
- /*------------------------------------------------
- ? ? ? ? ? ?Timer0 初始化,開中斷,2ms定時(shí)
- ------------------------------------------------*/
- void InitTIMER0(void)
- {
- TMOD|=0x01; //定時(shí)器設(shè)置 16位
- TH0=(65536-2000)/256; //定時(shí)時(shí)間 ? 2ms
- TL0=(65536-2000)%256;
- EA=1;
- ET0=1;
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
LCD1602+DS1302-201903110942.zip
(38.62 KB, 下載次數(shù): 102)
2019-3-12 09:01 上傳
點(diǎn)擊文件名下載附件
顯示時(shí)間
|
評(píng)分
-
查看全部評(píng)分
|