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

標題: DS1302與液晶1602顯示時鐘 [打印本頁]

作者: fcl    時間: 2017-7-30 10:29
標題: DS1302與液晶1602顯示時鐘
/************************************************
名稱:DS1302實時時鐘顯示程序
說明:從DS1302中讀取時鐘數據,在LCD上顯示日期和時間
*************************************************/
#include <reg51.h>
#include <intrins.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
sbit IO   = P1^0;    //數據線
sbit SCLK = P1^1;        //時鐘線
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_BUF_1[]={"DATE 00-00-00     "};
uchar LCD_BUF_2[]={"TIME 00:00:00     "};  //寫此條時注意空格
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;   //寫狀態
EN = 0;
P0 = cmd;
EN = 1;
Delayms(1);
EN = 0;
}
void Write_LCD_Data(uchar dat) //發送數據
{
// while((Busy_Check()&0x80)==0x80);
   // Busy_Check();
RS = 1;    //數據寄存器
RW = 0;   //寫狀態
EN = 0;
P0 = dat; //數據字節放到LCD端口
EN = 1;
Delayms(1);
EN = 0;
}
void Initialize_LCD() //初始化
{
  Write_LCD_Command(0x38);  //置功能 ,8位,雙行,5*7點陣
Delayms(1);
Write_LCD_Command(0x01);  //清屏
Delayms(1);
Write_LCD_Command(0x06); //字符進入模式遞增
Delayms(1);
Write_LCD_Command(0x0c); //顯示開關
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寫入一字節
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讀取一個字節
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指定位置讀數據
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;
}
//讀取當前日期時間
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);
}
}


作者: 陌路狂花    時間: 2017-11-20 20:41
你這個時間為什么不走,附件有圖片

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

IMG_20171120_203932.jpg





歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1