用51写的带键控带温度的万年历在LCD12864上显示
时间:11-29
来源:互联网
点击:
1,温度只显示整数部份,简单了许多;
2,之前星期不可调,问题出在读DS1302后数值没转换成十进制数;
3,因为主函数始终要更新LCD的座标,所以光标会随之更新;这个对自已不做要求,有兴趣的可以试一下;
4,网站代码下载:http://www.51hei.com/f/124wnl.rar
#include
#define uchar unsigned char
#define uint unsigned int
#define LCMdata P0
#define Busy 0x80
//--------Lcd_part ----------------
sbit RS = P2^0;
sbit RW = P2^1;
sbit E = P2^2;
sbit REST = P2^5;
sbit PSB = P2^3;
//---------Key_part----------------
sbit Key_1 = P1^4;
sbit Key_2 = P1^5;
sbit Key_3 = P1^6;
sbit Key_4 = P1^7;
//----------Ds1302_part----------------
sbit Sclk = P1^0;
sbit IO = P1^1;
sbit Rst = P1^2;
sbit Buz = P3^7;
sbit DQ = P3^6;
uchar Key_Select,Key_Flag,Key_Count,Set1,Temp;
uchar Time_Flag,TimeCount,Week_Count=0;
uchar Sec=0;uchar Min=30;uchar Hour=7;
uchar Date=8;uchar Mouth=4;uchar Year=12;uchar Week=5;
uchar Display_number[14] = {"0123456789: -"};
uchar Rd_addr[] = {0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
uchar Wr_addr[] = {0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
uchar Display[] = {"2012年04月06日//"};
uchar Display_1[]={"19时36分00秒////"};
uchar Display_T[]={"室温25℃"};
uchar Display_2[]={"星期"};
uchar code string_2[] = {" ----时钟---- "};
uchar code string_3[] = {" ----日历---- "};
void Wr_Data(uchar wrdata);
void Wr_Word(uchar *s);
void Wr_Command(uchar wrcommand,busyc);
void Display_String(uchar line,uchar Y,uchar *string);
void Delay5Ms(void) //延时 5ms
{
unsigned int TempCyc=5552;
while(TempCyc--);
}
//-------------------------------------------------------
void Delay_Ms(uint Mtime)
{
uint i,j;
for(i=Mtime;i>0;i--)
for(j=122;j>0;j--)
{;}
}
//--------------------------------------------------------
void Delay_Us(uchar Utime)//*2us
{
while(--Utime);
}
void Delay(uint utime) //9Us
{
while(utime--);
}
/////////////////////////////////////////////////////////
void Inint_ds18b20(void)
{
uchar DQZT=0;
DQ=1;
Delay(8);
DQ=0;
Delay(50);
DQ=1;
Delay(5);
DQZT=DQ;
Delay(10);
}
uchar Read_ds18b(void)
{
uchar i,dat=0;
for(i=0;i<8;i++)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat=dat|0x80;
Delay(5);
}
return dat;
}
void Write_ds18b20(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DQ=0;
DQ=dat&0x01;
Delay(5);
DQ=1;
dat>>=1;
}
}
void Read_Temp(void)
{
uchar a,b;
Inint_ds18b20();
Write_ds18b20(0xcc);
Write_ds18b20(0x44);
Delay_Ms(100);
Inint_ds18b20();
Write_ds18b20(0xcc);
Write_ds18b20(0xbe);
Delay_Ms(50);
a=Read_ds18b();
b=Read_ds18b();
a&=0xf0;
a>>=4;
b<=4;
Temp=a|b;
Display_T[4]=Display_number[Temp/10];
Display_T[5]=Display_number[Temp%10];
Delay_Us(100);
}
/////////////////////////////////////////////////////////
void Wr_ds1302_byte(uchar data_13)
{
uchar i;
for(i=0;i<8;i++)
{
Sclk = 0;
IO = data_13 &0x01;
data_13=data_13>>1;
Sclk = 1;
}
}
///////////////////////////////////////////////////
uchar Rd_ds1302_byte()
{
uchar i,value;
for(i=0;i<8;i++)
{
value=value>>1;
Sclk = 1;
Sclk = 0;
if(IO)
value=value|0x80;
}
return value;
}
///////////////////////////////////////////////////////
void Wr_1302(uchar addr,uchar dat)
{
Rst = 0;
Sclk = 0;
Rst = 1;
Wr_ds1302_byte(addr);
Wr_ds1302_byte(dat);
Rst = 0;
Sclk = 1;
IO = 1;
}
////////////////////////////////////////////////////
Rd_1302(uchar addr)
{
uchar value;
Rst = 0;
Sclk = 0;
Rst = 1;
Wr_ds1302_byte(addr);
value=Rd_ds1302_byte();
Rst = 0;
IO = 1;
Sclk = 1;
return value;
}
////////////////////////////////////////////////////////////////////
void Set_RTC(void)
{
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x80);
Wr_1302(Wr_addr[6],(Sec/10)<4|Sec%10); //Sec
Wr_1302(Wr_addr[5],(Min/10)<4|Min%10); //Min
Wr_1302(Wr_addr[4],(Hour/10)<4|Hour%10); //Hour
Wr_1302(Wr_addr[3],(Date/10)<4|Date%10); //Date
Wr_1302(Wr_addr[2],(Mouth/10)<4|Mouth%10); //Mouth
Wr_1302(Wr_addr[1],(Week/10)<4|Week%10); //Weak
Wr_1302(Wr_addr[0],(Year/10)<4|Year%10); //Year
Wr_1302(0x8e,0x80);
}
/////////////////////////////////////////////////////////////////
void Rd_RTC(void)
{
Sec = Rd_1302(0x81); //Sec
Min = Rd_1302(0x83); //Min
Hour = Rd_1302(0x85); //Hour
Date = Rd_1302(0x87); //Date
Mouth = Rd_1302(0x89); //Mouth
Year = Rd_1302(0x8d); //Year
Week = Rd_1302(0x8b); //Week
}
////////////////////////////////////////////////////////////
void change(void)
{
//Year
Display[2] = Display_number[Year/16];
Display[3] = Display_number[Year%16];
//Mouth
Display[6] = Display_number[Mouth/16];
Display[7] = Display_number[Mouth%16];
//Date
Display[10] = Display_number[Date/16];
Display[11] = Display_number[Date%16];
//Hour
Display_1[0] = Display_number[Hour/16];
Display_1[1] = Display_number[Hour%16];
//Min
Display_1[4] = Display_number[Min/16];
Display_1[5] = Display_number[Min%16];
//Sec
Display_1[8] = Display_number[Sec/16];
Display_1[9] = Display_number[Sec%16];
Week = Week%16;
switch(Week)
{
case 1: Display_String(4,2,"一"); break;
case 2: Display_String(4,2,"二"); break;
//case 3: Display_String(4,2,"三"); break;
case 3 :Wr_Command(0x9a,1);Wr_Data(0xc8);Wr_Data(0xfd);break;
case 4: Display_String(4,2,"四");break;
case 5: Display_String(4,2,"五"); break;
case 6: Display_String(4,2,"六"); break;
case 7: Display_String(4,2,"日"); break;
default:
break;
}
}
//--------------------------------------------------------
void RDbf(void) //读忙状态
{
while(1)
{
RS=0;
RW=1;
E=0;
LCMdata=0xFF;
E=1;
if((LCMdata&Busy)==0)
break;
}
}
//--------------------------------------------------------
void Wr_Data(uchar wrdata) //写数据
{
RDbf();
RS=1;
RW=0;
E=1;
LCMdata=wrdata;
E=0;
}
//---------------------------------------------------------
void Wr_Command(uchar wrcommand,busyc) //写指令
{
if(busyc)
RDbf();
RS=0;
RW=0;
E=1;
LCMdata=wrcommand;
E=0;
}
//----------------------------------------------------------
void Wr_Word(uchar *s)
{
while(*s!=)
{
Wr_Data(*s++);
} *s=0;
}
//----------------------------------------------------------
void Display_String(uchar line,uchar Y,uchar *string)//显示字符串
{
uchar addr,post;
if(line==1)
addr=0x80;
else if(line==2)
addr=0x90;
else if(line==3)
addr=0x88;
else if(line==4)
addr=0x98;
post=addr+Y;
Wr_Command(post,1);
while(*string!=)
{
Wr_Data(*string++);
}
//*string = 0;
}
//-----------------------------------------------------------
void Lcm_Init(void)
{
Delay_Ms(40);
Delay5Ms();
PSB=1;
Delay5Ms();
REST=1;
REST=0;
REST=1;
Wr_Command(0x30,0);
Delay5Ms();
Wr_Command(0x30,0); //2次显示模式设置,不用判忙
Delay5Ms();
Wr_Command(0x0c,1); //开显示及光标设置
Delay5Ms();
Wr_Command(0x01,1); //显示清屏
Delay5Ms();
Wr_Command(0x02,1);//光标归位
//Delay5Ms();
//Wr_Command(0x14,1);//光标向右移动
Delay5Ms();
Wr_Command(0x06,1); //显示光标移动设置
Delay5Ms();
}
//-----------------------------------------------------------
//-----------------------------------------------------------
void buz(void)
{
uint i;
for(i=200;i>0;i--)
{
Buz=1;
Delay_Us(120);
Buz=0;
}
Buz=0x00;
}
//----------------------------------------------------------
void Key_Scan()
{
P1=0x30;
if(Key_1==0)
{
Delay_Ms(20);
if(Key_1==0)
{
Key_Select++;
if (Key_Select==1)
{
Wr_Command(0x0f,1);
Wr_Command(0x88,1); //Hour
}
if(Key_Select==2)
{
Wr_Command(0x8a,1); //Min
}
if(Key_Select==3)
{
Wr_Command(0x8c,1); //Sec
}
if(Key_Select==4)
{
Wr_Command(0x91,1); //Yeah
}
if(Key_Select==5)
{
Wr_Command(0x93,1); //Mouth
}
if(Key_Select==6)
{
Wr_Command(0x95,1); //Date
}
if(Key_Select==7)
{
Wr_Command(0x9a,1); //Week;
}
if(Key_Select==8)
{
Wr_Command(0x0c,1);
Key_Select=0;
Key_Count=0;
}
buz();
while(!Key_1);
Key_Count=0;
}
}
if(Key_2==0)
{
Delay_Ms(20);
if(Key_2==0)
{
Key_Count++;
}
buz();
while(!Key_2);
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x80);
switch(Key_Select)
{
case 1://Hour
if(Key_Count!=0)
{
// Wr_Command(0x0f,1);
Wr_Command(0x88,1);
if(Key_Count==24)
Key_Count=0;
Hour=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[4],Hour);
}break;
case 2: //Min
if(Key_Count!=0)
{
Wr_Command(0x8a,1);
if(Key_Count==60)
Key_Count=0;
Min=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[5],Min);
}break;
case 3: //Sec
if(Key_Count!=0)
{
Wr_Command(0x8c,1);
if(Key_Count==60)
Key_Count=0;
Sec=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[6],Sec);
}break;
case 4: //Year
if(Key_Count!=0)
{
Wr_Command(0x91,1);
if(Key_Count==99)
Key_Count=0;
Year=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[0],Year);
}break;
case 5: //Mouth
if(Key_Count!=0)
{
Wr_Command(0x93,1);
if(Key_Count==12)
Key_Count=1;
Mouth=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[2],Mouth);
}break;
case 6: //Date
if(Key_Count!=0)
{
Wr_Command(0x95,1);
if(Key_Count==32)
Key_Count=1;
Date=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[3],Date);
}break;
case 7: //Week
if(Key_Count!=0)
{
Wr_Command(0x9a,1);
if(Key_Count==8)
Key_Count=1;
Week=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[1],Week);
}break;
default:
if(Key_Count==0)
{
Wr_Command(0x0c,1);
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x00);
Wr_1302(0x8e,0x80);
}Key_Select=0;
break;
}
}
}
//-----------------------------------------------------------
void main(void)
{
buz();
Lcm_Init();
Inint_ds18b20();
//Display_String(1,0,string_4);
Display_String(2,0,string_2);
Display_String(3,0,string_3);
//Display_String(4,0,string_4);
Delay_Ms(1000);
Wr_Command(0x01,1);
Delay_Ms(250);
//Display_String(1,0,string_4);
Display_String(2,0,string_2);
Display_String(3,0,string_3);
//Display_String(4,0,string_4);
Delay_Ms(1000);
Wr_Command(0x01,1);
Display_String(1,0,string_2);
Display_String(2,0,Display);
Display_String(3,0,Display_1);
Display_String(4,0,Display_2);
//Set_RTC();
//Wr_1302(0x80,0x00);
while(1)
{
Key_Scan();
Rd_RTC();
change();
Display_String(1,0,string_2);
Display_String(2,0,Display);
Display_String(3,0,Display_1);
Display_String(4,0,Display_2);
Read_Temp();
Display_String(4,4,Display_T);
Delay_Ms(100);
}
}
2,之前星期不可调,问题出在读DS1302后数值没转换成十进制数;
3,因为主函数始终要更新LCD的座标,所以光标会随之更新;这个对自已不做要求,有兴趣的可以试一下;
4,网站代码下载:http://www.51hei.com/f/124wnl.rar
#include
#define uchar unsigned char
#define uint unsigned int
#define LCMdata P0
#define Busy 0x80
//--------Lcd_part ----------------
sbit RS = P2^0;
sbit RW = P2^1;
sbit E = P2^2;
sbit REST = P2^5;
sbit PSB = P2^3;
//---------Key_part----------------
sbit Key_1 = P1^4;
sbit Key_2 = P1^5;
sbit Key_3 = P1^6;
sbit Key_4 = P1^7;
//----------Ds1302_part----------------
sbit Sclk = P1^0;
sbit IO = P1^1;
sbit Rst = P1^2;
sbit Buz = P3^7;
sbit DQ = P3^6;
uchar Key_Select,Key_Flag,Key_Count,Set1,Temp;
uchar Time_Flag,TimeCount,Week_Count=0;
uchar Sec=0;uchar Min=30;uchar Hour=7;
uchar Date=8;uchar Mouth=4;uchar Year=12;uchar Week=5;
uchar Display_number[14] = {"0123456789: -"};
uchar Rd_addr[] = {0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
uchar Wr_addr[] = {0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
uchar Display[] = {"2012年04月06日//"};
uchar Display_1[]={"19时36分00秒////"};
uchar Display_T[]={"室温25℃"};
uchar Display_2[]={"星期"};
uchar code string_2[] = {" ----时钟---- "};
uchar code string_3[] = {" ----日历---- "};
void Wr_Data(uchar wrdata);
void Wr_Word(uchar *s);
void Wr_Command(uchar wrcommand,busyc);
void Display_String(uchar line,uchar Y,uchar *string);
void Delay5Ms(void) //延时 5ms
{
unsigned int TempCyc=5552;
while(TempCyc--);
}
//-------------------------------------------------------
void Delay_Ms(uint Mtime)
{
uint i,j;
for(i=Mtime;i>0;i--)
for(j=122;j>0;j--)
{;}
}
//--------------------------------------------------------
void Delay_Us(uchar Utime)//*2us
{
while(--Utime);
}
void Delay(uint utime) //9Us
{
while(utime--);
}
/////////////////////////////////////////////////////////
void Inint_ds18b20(void)
{
uchar DQZT=0;
DQ=1;
Delay(8);
DQ=0;
Delay(50);
DQ=1;
Delay(5);
DQZT=DQ;
Delay(10);
}
uchar Read_ds18b(void)
{
uchar i,dat=0;
for(i=0;i<8;i++)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat=dat|0x80;
Delay(5);
}
return dat;
}
void Write_ds18b20(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DQ=0;
DQ=dat&0x01;
Delay(5);
DQ=1;
dat>>=1;
}
}
void Read_Temp(void)
{
uchar a,b;
Inint_ds18b20();
Write_ds18b20(0xcc);
Write_ds18b20(0x44);
Delay_Ms(100);
Inint_ds18b20();
Write_ds18b20(0xcc);
Write_ds18b20(0xbe);
Delay_Ms(50);
a=Read_ds18b();
b=Read_ds18b();
a&=0xf0;
a>>=4;
b<=4;
Temp=a|b;
Display_T[4]=Display_number[Temp/10];
Display_T[5]=Display_number[Temp%10];
Delay_Us(100);
}
/////////////////////////////////////////////////////////
void Wr_ds1302_byte(uchar data_13)
{
uchar i;
for(i=0;i<8;i++)
{
Sclk = 0;
IO = data_13 &0x01;
data_13=data_13>>1;
Sclk = 1;
}
}
///////////////////////////////////////////////////
uchar Rd_ds1302_byte()
{
uchar i,value;
for(i=0;i<8;i++)
{
value=value>>1;
Sclk = 1;
Sclk = 0;
if(IO)
value=value|0x80;
}
return value;
}
///////////////////////////////////////////////////////
void Wr_1302(uchar addr,uchar dat)
{
Rst = 0;
Sclk = 0;
Rst = 1;
Wr_ds1302_byte(addr);
Wr_ds1302_byte(dat);
Rst = 0;
Sclk = 1;
IO = 1;
}
////////////////////////////////////////////////////
Rd_1302(uchar addr)
{
uchar value;
Rst = 0;
Sclk = 0;
Rst = 1;
Wr_ds1302_byte(addr);
value=Rd_ds1302_byte();
Rst = 0;
IO = 1;
Sclk = 1;
return value;
}
////////////////////////////////////////////////////////////////////
void Set_RTC(void)
{
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x80);
Wr_1302(Wr_addr[6],(Sec/10)<4|Sec%10); //Sec
Wr_1302(Wr_addr[5],(Min/10)<4|Min%10); //Min
Wr_1302(Wr_addr[4],(Hour/10)<4|Hour%10); //Hour
Wr_1302(Wr_addr[3],(Date/10)<4|Date%10); //Date
Wr_1302(Wr_addr[2],(Mouth/10)<4|Mouth%10); //Mouth
Wr_1302(Wr_addr[1],(Week/10)<4|Week%10); //Weak
Wr_1302(Wr_addr[0],(Year/10)<4|Year%10); //Year
Wr_1302(0x8e,0x80);
}
/////////////////////////////////////////////////////////////////
void Rd_RTC(void)
{
Sec = Rd_1302(0x81); //Sec
Min = Rd_1302(0x83); //Min
Hour = Rd_1302(0x85); //Hour
Date = Rd_1302(0x87); //Date
Mouth = Rd_1302(0x89); //Mouth
Year = Rd_1302(0x8d); //Year
Week = Rd_1302(0x8b); //Week
}
////////////////////////////////////////////////////////////
void change(void)
{
//Year
Display[2] = Display_number[Year/16];
Display[3] = Display_number[Year%16];
//Mouth
Display[6] = Display_number[Mouth/16];
Display[7] = Display_number[Mouth%16];
//Date
Display[10] = Display_number[Date/16];
Display[11] = Display_number[Date%16];
//Hour
Display_1[0] = Display_number[Hour/16];
Display_1[1] = Display_number[Hour%16];
//Min
Display_1[4] = Display_number[Min/16];
Display_1[5] = Display_number[Min%16];
//Sec
Display_1[8] = Display_number[Sec/16];
Display_1[9] = Display_number[Sec%16];
Week = Week%16;
switch(Week)
{
case 1: Display_String(4,2,"一"); break;
case 2: Display_String(4,2,"二"); break;
//case 3: Display_String(4,2,"三"); break;
case 3 :Wr_Command(0x9a,1);Wr_Data(0xc8);Wr_Data(0xfd);break;
case 4: Display_String(4,2,"四");break;
case 5: Display_String(4,2,"五"); break;
case 6: Display_String(4,2,"六"); break;
case 7: Display_String(4,2,"日"); break;
default:
break;
}
}
//--------------------------------------------------------
void RDbf(void) //读忙状态
{
while(1)
{
RS=0;
RW=1;
E=0;
LCMdata=0xFF;
E=1;
if((LCMdata&Busy)==0)
break;
}
}
//--------------------------------------------------------
void Wr_Data(uchar wrdata) //写数据
{
RDbf();
RS=1;
RW=0;
E=1;
LCMdata=wrdata;
E=0;
}
//---------------------------------------------------------
void Wr_Command(uchar wrcommand,busyc) //写指令
{
if(busyc)
RDbf();
RS=0;
RW=0;
E=1;
LCMdata=wrcommand;
E=0;
}
//----------------------------------------------------------
void Wr_Word(uchar *s)
{
while(*s!=)
{
Wr_Data(*s++);
} *s=0;
}
//----------------------------------------------------------
void Display_String(uchar line,uchar Y,uchar *string)//显示字符串
{
uchar addr,post;
if(line==1)
addr=0x80;
else if(line==2)
addr=0x90;
else if(line==3)
addr=0x88;
else if(line==4)
addr=0x98;
post=addr+Y;
Wr_Command(post,1);
while(*string!=)
{
Wr_Data(*string++);
}
//*string = 0;
}
//-----------------------------------------------------------
void Lcm_Init(void)
{
Delay_Ms(40);
Delay5Ms();
PSB=1;
Delay5Ms();
REST=1;
REST=0;
REST=1;
Wr_Command(0x30,0);
Delay5Ms();
Wr_Command(0x30,0); //2次显示模式设置,不用判忙
Delay5Ms();
Wr_Command(0x0c,1); //开显示及光标设置
Delay5Ms();
Wr_Command(0x01,1); //显示清屏
Delay5Ms();
Wr_Command(0x02,1);//光标归位
//Delay5Ms();
//Wr_Command(0x14,1);//光标向右移动
Delay5Ms();
Wr_Command(0x06,1); //显示光标移动设置
Delay5Ms();
}
//-----------------------------------------------------------
//-----------------------------------------------------------
void buz(void)
{
uint i;
for(i=200;i>0;i--)
{
Buz=1;
Delay_Us(120);
Buz=0;
}
Buz=0x00;
}
//----------------------------------------------------------
void Key_Scan()
{
P1=0x30;
if(Key_1==0)
{
Delay_Ms(20);
if(Key_1==0)
{
Key_Select++;
if (Key_Select==1)
{
Wr_Command(0x0f,1);
Wr_Command(0x88,1); //Hour
}
if(Key_Select==2)
{
Wr_Command(0x8a,1); //Min
}
if(Key_Select==3)
{
Wr_Command(0x8c,1); //Sec
}
if(Key_Select==4)
{
Wr_Command(0x91,1); //Yeah
}
if(Key_Select==5)
{
Wr_Command(0x93,1); //Mouth
}
if(Key_Select==6)
{
Wr_Command(0x95,1); //Date
}
if(Key_Select==7)
{
Wr_Command(0x9a,1); //Week;
}
if(Key_Select==8)
{
Wr_Command(0x0c,1);
Key_Select=0;
Key_Count=0;
}
buz();
while(!Key_1);
Key_Count=0;
}
}
if(Key_2==0)
{
Delay_Ms(20);
if(Key_2==0)
{
Key_Count++;
}
buz();
while(!Key_2);
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x80);
switch(Key_Select)
{
case 1://Hour
if(Key_Count!=0)
{
// Wr_Command(0x0f,1);
Wr_Command(0x88,1);
if(Key_Count==24)
Key_Count=0;
Hour=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[4],Hour);
}break;
case 2: //Min
if(Key_Count!=0)
{
Wr_Command(0x8a,1);
if(Key_Count==60)
Key_Count=0;
Min=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[5],Min);
}break;
case 3: //Sec
if(Key_Count!=0)
{
Wr_Command(0x8c,1);
if(Key_Count==60)
Key_Count=0;
Sec=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[6],Sec);
}break;
case 4: //Year
if(Key_Count!=0)
{
Wr_Command(0x91,1);
if(Key_Count==99)
Key_Count=0;
Year=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[0],Year);
}break;
case 5: //Mouth
if(Key_Count!=0)
{
Wr_Command(0x93,1);
if(Key_Count==12)
Key_Count=1;
Mouth=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[2],Mouth);
}break;
case 6: //Date
if(Key_Count!=0)
{
Wr_Command(0x95,1);
if(Key_Count==32)
Key_Count=1;
Date=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[3],Date);
}break;
case 7: //Week
if(Key_Count!=0)
{
Wr_Command(0x9a,1);
if(Key_Count==8)
Key_Count=1;
Week=(Key_Count/10)<4|(Key_Count%10);
Wr_1302(Wr_addr[1],Week);
}break;
default:
if(Key_Count==0)
{
Wr_Command(0x0c,1);
Wr_1302(0x8e,0x00);
Wr_1302(0x80,0x00);
Wr_1302(0x8e,0x80);
}Key_Select=0;
break;
}
}
}
//-----------------------------------------------------------
void main(void)
{
buz();
Lcm_Init();
Inint_ds18b20();
//Display_String(1,0,string_4);
Display_String(2,0,string_2);
Display_String(3,0,string_3);
//Display_String(4,0,string_4);
Delay_Ms(1000);
Wr_Command(0x01,1);
Delay_Ms(250);
//Display_String(1,0,string_4);
Display_String(2,0,string_2);
Display_String(3,0,string_3);
//Display_String(4,0,string_4);
Delay_Ms(1000);
Wr_Command(0x01,1);
Display_String(1,0,string_2);
Display_String(2,0,Display);
Display_String(3,0,Display_1);
Display_String(4,0,Display_2);
//Set_RTC();
//Wr_1302(0x80,0x00);
while(1)
{
Key_Scan();
Rd_RTC();
change();
Display_String(1,0,string_2);
Display_String(2,0,Display);
Display_String(3,0,Display_1);
Display_String(4,0,Display_2);
Read_Temp();
Display_String(4,4,Display_T);
Delay_Ms(100);
}
}
51带键控带温度万年历LCD1286 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)