|
基于單片機(jī)的萬年歷
系統(tǒng)由單片機(jī)AT89C51、LCD12864液晶顯示屏、DS18B20和1302時(shí)鐘芯片組成
可顯示年月日,時(shí)間,溫度,星期。
仿真圖如下:
批注 2020-03-26 213515.png (65.79 KB, 下載次數(shù): 58)
下載附件
2020-3-26 21:42 上傳
#include <reg51.h>
#include <LCD1602.C>
#include <DS18B20.C>
#include <DS1302.C>
#include <SERIAL.C>
sbit KEY=P2^6; //定義日期和時(shí)間轉(zhuǎn)換按鍵
sbit KEY1=P3^2;
sbit KEY2=P3^3;
sbit KEY3=P3^4;
sbit KEY4=P3^5;
void delay10(void)
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<200;j++);
}
unsigned char conver(unsigned char a,unsigned char b,unsigned char c)
{
if((a&0x0f)==0x0a) a=a+6;
if(a==b) a=c;
return a;
}
main()
{
bit flag_1=1;
bit flag_2=1;
bit flag_3=1;
bit flag_4=1;
char a;
unsigned char j[8],choose=0x01;
init_serialcomm();//初始化串行口
LCD_initial(); //初始化LCD
LCD_prints("Temperature: C") ; //顯示"Temperature: C"
while(1)
{
send_char_com(0x31);
a=Read_Temperature(); //讀取DS18B20的溫度
LCD_set_position(0xc); //定位LCD到指定位置
if(a<0) //處理溫度正負(fù)
{
a = (-1)*a; // 取補(bǔ)
LCD_printc(0x2D);
}
else
{
LCD_printc(0x2B);
}
LCD_printc(a/10+0x30); //顯示溫度高位
LCD_printc(a%10+0x30); //顯示溫度低位
LCD_set_position(0x40);
if(KEY==0) //按鍵--處理時(shí)間和日期的輪換
{
delay10();
if(KEY==1)
delay10();
flag_1=~flag_1;
}
if(KEY1==0) //按鍵1--處理設(shè)定時(shí)間和返回
{
delay10();
if(KEY1==1)
delay10();
flag_2=~flag_2;
}
if(KEY2==0) //按鍵2--處理選擇設(shè)定時(shí)間
{
delay10();
if(KEY2==1)
delay10();
choose++;
if(choose==8)
choose=0x01;
}
if(KEY3==0) //按鍵3--處理設(shè)定時(shí)間和返回
{ delay10();
if(KEY3==1)
delay10();
switch(choose)
{
case 1: j[6]++; j[6]=conver(j[6],0xa0,0x00);break;//年
case 2: j[5]++; j[5]=conver(j[5],0x07,0x00);break;//周
case 3: j[4]++; j[4]=conver(j[4],0x13,0x01);break;//月
case 4: j[3]++; j[3]=conver(j[3],0x32,0x01);break;//日
case 5: j[2]++; j[2]=conver(j[2],0x24,0x00);break;//時(shí)
case 6: j[1]++; j[1]=conver(j[1],0x60,0x00);break;//分
case 7: j[0]++; j[0]=conver(j[0],0x60,0x00);break;//秒
}
}
if(flag_2==1)
read_serial(j); //讀取DS1302的時(shí)間
else
write_date_time(j);
if(flag_1==1)
{
LCD_prints("Time: ") ;
LCD_printc((j[2]>>4&0x07)+0x30); //時(shí)
LCD_printc((j[2]&0x0f)+0x30);
LCD_printc(0x3A); //":"號(hào)
LCD_printc((j[1]>>4&0x07)+0x30); //分
LCD_printc((j[1]&0x0f)+0x30);
LCD_printc(0x3A); //":"號(hào)
LCD_printc((j[0]>>4&0x07)+0x30); //秒
LCD_printc((j[0]&0x0f)+0x30);
LCD_printc(0x20); //空格
LCD_printc(0x20); //空格
}
else
{
LCD_prints("Date: ") ;
LCD_printc((j[6]>>4&0x0f)+0x30); //年
LCD_printc((j[6]&0x0f)+0x30);
LCD_printc(0x2D); //"-"號(hào)
LCD_printc((j[4]>>4&0x01)+0x30);//月
LCD_printc((j[4]&0x0f)+0x30);
LCD_printc(0x2D); //"-"號(hào)
LCD_printc((j[3]>>4&0x03)+0x30);//日
LCD_printc((j[3]&0x0f)+0x30);
LCD_printc(0x2D); //"-"號(hào)
LCD_printc((j[5]>>4&0x07)+0x30); //星期
}
}
}
全部資料51hei下載地址:
萬年歷protues仿真 實(shí)時(shí)時(shí)鐘仿真 12864萬年歷仿真 51萬年歷設(shè)計(jì).zip
(149.93 KB, 下載次數(shù): 128)
2020-3-26 21:44 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|