单片机万年历(LCD12864、DS18B20、DS1302)
想要更多项目私wo!!!
一、简介
此电路由AT89C51最小电路板和LCD12864显示模块、DS18B20温度模块、DS1302时钟模块组成。
主要的功能是:显示实时的时间和当前的温度。
二、运行效果
三、部分代码
/*想要更多项目私wo!!!*/
#include <reg51.h>
#include <DS18B20.H>
#include <DS1302.H>
#include <LCD12864.H>unsigned char j[8];
sbit KEY1=P3^2;
sbit KEY2=P3^3;
sbit KEY3=P3^4;
sbit LED1=P3^5;
sbit LED2=P3^6;
sbit LED3=P3^7;uchar time0_count; //time0?????÷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_2=1;bit flag_3=1;bit flag_4=1;int i; char a; unsigned char choose=0x01;InitLCD(); //??????LCD12864for(i=0;i<13;i++){
ShowNumber(6,i*8+16,i+14);}Show32x32(0,0,0);ShowChina(4,0,7);ShowChina(4,16,8);ShowChina(4,32,9);ShowChina(4,48,10);ShowNumber(4,64,10); //????????????read_serial(j); //????DS1302???±??ShowNumber(2,32,j[2]>>4&0x03);ShowNumber(2,40, j[2]&0x0f);ShowChina(2,48,3);ShowNumber(2,64,j[1]>>4&0x07);ShowNumber(2,72, j[1]&0x0f);ShowChina(2,80,4);ShowNumber(2,96,j[0]>>4&0x07);ShowNumber(2,104, j[0]&0x0f);ShowChina(2,112,5);ShowNumber(0,32,j[6]>>4&0x0f);ShowNumber(0,40, j[6]&0x0f);ShowChina(0,48,0);ShowNumber(0,64,j[4]>>4&0x01);ShowNumber(0,72, j[4]&0x0f);ShowChina(0,80,1);ShowNumber(0,96,j[3]>>4&0x03);ShowNumber(0,104, j[3]&0x0f);ShowChina(0,112,2);ShowChina(4,104,6); ShowNumber(4,120,j[5]-1&0x07);while(1){
if(flag_2==1)read_serial(j); //????DS1302???±??else write_date_time(j);a=Read_Temperature(); //????DS18B20??????if(a<0) //???í????????{
a = (-1)*a; // ????ShowNumber(4,72,11); //????????????}else {
ShowNumber(4,72,12); //????????????}ShowNumber(4,80,a/100); //????????????ShowNumber(4,88,a/10%10); //????????????ShowNumber(4,96,a%10); //????????????LED3=1;LED2=0;LED1=1;if(a>40){
LED3=0;LED2=1;LED1=1;}if(a<30){
LED3=1;LED2=1;LED1=0;}if(KEY1==0) //°??ü1--???í?è?¨?±????·???{
delay10();if(KEY1==1){
delay10();flag_2=~flag_2; }}if(KEY2==0) //°??ü2--???í?????è?¨?±????????{
delay10();if(KEY2==1){
delay10();choose++;if(choose==8)choose=0x01;} }if(KEY3==0) //°??ü3--???í?è?¨?±????·???{
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;//?±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???±??else write_date_time(j);//?±·???ShowNumber(2,32,j[2]>>4&0x03);ShowNumber(2,40, j[2]&0x0f);ShowChina(2,48,3);ShowNumber(2,64,j[1]>>4&0x07);ShowNumber(2,72, j[1]&0x0f);ShowChina(2,80,4);ShowNumber(2,96,j[0]>>4&0x07);ShowNumber(2,104, j[0]&0x0f);ShowChina(2,112,5);// ?ê????ShowNumber(0,32,j[6]>>4&0x0f);ShowNumber(0,40, j[6]&0x0f);ShowChina(0,48,0);ShowNumber(0,64,j[4]>>4&0x01);ShowNumber(0,72, j[4]&0x0f);ShowChina(0,80,1);ShowNumber(0,96,j[3]>>4&0x03);ShowNumber(0,104, j[3]&0x0f);ShowChina(0,112,2);ShowChina(4,104,6); ShowNumber(4,120,j[5]-1&0x07);}
}