12864c语言接温度计,单片机万年历+温度计+12864LCD液晶显示 仿真+程序

#include

#include

#include

#include

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();          //初始化LCD12864

for(i=0;i<9;i++)

{

ShowNumber(6,i*8+32,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)

{

//send_char_com(0x31);

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);

}

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/*-----------------------------------------------------------*/ #define LCD_OFF 0x3E #define LCD_ON 0x3F #define Add_X 0xB8 //the start address of the page 0 ;(0~7) #define Add_Y 0x40 //the start address of the Y counter ; (0~64) #define Add_Z 0xC0 //the start address of the DDRAM ; (0~64) #define UPLINE 0x01 #define UNDERLINE 0x80 /*-----------------------------------------------------------*/ #define LCD12864_DATA_PORT P0 sbit LCD12864_EN =P1^4; sbit LCD12864_RW =P1^3; //0:write ; 1:read sbit LCD12864_RS =P1^2; //0:the command .1:the data sbit LCD12864_CS_L =P1^1; //select the left of the lcd when 1 sbit LCD12864_CS_R =P1^0; sbit LCD12864_RST =P1^5; /*------------------------------------------------------------*/ void delayus(unsigned int us) { while(us--); } void delayms(unsigned ms) { unsigned int i,j; for (i=0;i<ms;i++) { for (j=0;j<1000;j++) ; } } /*--------------------------select the LCD--------------------*/ void LCDSel(unsigned char sel) { switch(sel) { case 0: LCD12864_CS_L=0;LCD12864_CS_R=0;break; case 1: LCD12864_CS_L=1;LCD12864_CS_R=0;break; //left case 2: LCD12864_CS_L=0;LCD12864_CS_R=1;break; //right default:; }; } /*------------------------------------------------------------*/ void WaitLCD() { unsigned char flag; LCD12864_DATA_PORT=0xFF; LCD12864_RW=1; LCD12864_RS=0; LCD12864_EN=1; LCD12864_EN=1; LCD12864_EN=0; LCD12864_DATA_PORT=0xFF; //读有效数据 LCD12864_RW=1; LCD12864_RS=0; ; LCD12864_EN=1; do { flag=LCD12864_DATA_PORT; LCD12864_DATA_PORT=0xFF; }while(!((flag&0x80)==0x80)); LCD12864_EN=0; } //*/ /*-------------------------------------------------------------*/ void WriteDatToLCD12864(unsigned char dat) { WaitLCD(); LCD12864_RS=1; //the data LCD12864_RW=0; //write LCD12864_DATA_PORT=dat; LCD12864_EN=1; ; LCD12864_EN=0;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值