欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2106|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

DS1302與液晶1602顯示時(shí)鐘

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
/************************************************
名稱:DS1302實(shí)時(shí)時(shí)鐘顯示程序
說(shuō)明:從DS1302中讀取時(shí)鐘數(shù)據(jù),在LCD上顯示日期和時(shí)間
*************************************************/
#include <reg51.h>
#include <intrins.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
sbit IO   = P1^0;    //數(shù)據(jù)線
sbit SCLK = P1^1;        //時(shí)鐘線
sbit RST  = P1^2;    //復(fù)位線
sbit RS = P2^0;
sbit RW = P2^1;     
sbit EN = P2^2;         
uchar *WEEK[] = {"SUN","MON","TUS","WEN","THU","FRI","SAT"};   //周一至周六
uchar LCD_BUF_1[]={"DATE 00-00-00     "};
uchar LCD_BUF_2[]={"TIME 00:00:00     "};  //寫此條時(shí)注意空格
void GetDateTime();
uchar DateTime[7];
void Delayms(uint ms)
{
  uchar i;
while(ms--)
{
   for(i=0;i<120;i++);
}
}
void Write_LCD_Command(uchar cmd)
{
  //while((Busy_Check()&0x80)==0x80);
//Busy_Check();     //兩種寫法都行
RS = 0;
RW = 0;   //寫狀態(tài)
EN = 0;
P0 = cmd;
EN = 1;
Delayms(1);
EN = 0;
}
void Write_LCD_Data(uchar dat) //發(fā)送數(shù)據(jù)
{
// while((Busy_Check()&0x80)==0x80);
   // Busy_Check();
RS = 1;    //數(shù)據(jù)寄存器
RW = 0;   //寫狀態(tài)
EN = 0;
P0 = dat; //數(shù)據(jù)字節(jié)放到LCD端口
EN = 1;
Delayms(1);
EN = 0;
}
void Initialize_LCD() //初始化
{
  Write_LCD_Command(0x38);  //置功能 ,8位,雙行,5*7點(diǎn)陣
Delayms(1);
Write_LCD_Command(0x01);  //清屏
Delayms(1);
Write_LCD_Command(0x06); //字符進(jìn)入模式遞增
Delayms(1);
Write_LCD_Command(0x0c); //顯示開關(guān)
Delayms(1);
}
void ShowString(uchar x,uchar y,uchar *str)   //在指定位置顯示
{
  uchar i = 0;
if(y == 0)
  Write_LCD_Command(0x80 | x);  //x為第x列字符位置,y為第y行
if(y == 1)
  Write_LCD_Command(0xc0 | x);
for(i=0;i<16;i++)
{
   Write_LCD_Data(str[i]);
}
}

//向DS1302寫入一字節(jié)
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;
}
}
//從DS1302讀取一個(gè)字節(jié)
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;
}
//從DS1302指定位置讀數(shù)據(jù)
uchar Read_Date(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;
}
//讀取當(dāng)前日期時(shí)間
void GetDateTime()
{
  uchar i,addr = 0x81;
for(i=0;i<7;i++)
{
   DateTime[i]=Read_Date(addr);addr+=2;
}
}

void Format_DateTime(uchar d,uchar *a)
{
// *a=(d>>4) + '0';
// *(a+1) = (d & 0x0f) + '0';
    a[0]=d/10+'0';
a[1]=d%10+'0';
}
void main()
{
Initialize_LCD();
while(1)
{
   GetDateTime();
   Format_DateTime(DateTime[6],LCD_BUF_1 + 5);
   Format_DateTime(DateTime[4],LCD_BUF_1 + 8);
   Format_DateTime(DateTime[3],LCD_BUF_1 + 11);
   strcpy(LCD_BUF_1 + 13,WEEK[DateTime[5]-1]);
   Format_DateTime(DateTime[2],LCD_BUF_2 + 5);
   Format_DateTime(DateTime[1],LCD_BUF_2 + 8);
   Format_DateTime(DateTime[0],LCD_BUF_2 + 11);
   ShowString(0,0,LCD_BUF_1);
   ShowString(0,1,LCD_BUF_2);
}
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

無(wú)效樓層,該帖已經(jīng)被刪除
板凳
ID:244748 發(fā)表于 2017-11-20 20:41 | 只看該作者
你這個(gè)時(shí)間為什么不走,附件有圖片

IMG_20171120_203932.jpg (1.37 MB, 下載次數(shù): 16)

IMG_20171120_203932.jpg
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表