#include<reg52.h>
#include<stdio.h>
#include<intrins.h>
#include"lcd1602.H"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar code tab[9]={0xff,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; //ÃüÁîÖ¸Áî
uchar date[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/************************************
ÑÓʱ×Ó³ÌÐò
ÑÓʱʱ¼ä(xms*1)ms
*************************************/
void delayms(uint xms)// ÑÓ³Ùº¯Êý
{
uint x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
}
void send(uchar dat) //·¢ËÍÒ»×Ö½Ú
{
SBUF=dat;
while(!TI);
TI=0;
}
void main(void)
{
uint tmp;
uchar i;
TMOD=0x20; // T1¶¨Ê±·½Ê½2
SCON=0x40;//´®Ðй¤×÷ ·½Ê½1
PCON=0x00; //²»¼Ó±¶
TH1=TL1=0xfd; //¶¨Ê±Æ÷1¸³³õÖµ ±£Ö¤²¨ÌØÂÊ9600
TR1=1; //¿ª¶¨Ê±Æ÷1
REN=1; //ÔÊÐí´®¿Ú½ÓÊÕ
init_1602(); //Òº¾§³õʼ»¯
delayms(10);
ES=1; //´ò¿ª´®¿ÚÖжÏ
EA=1; //¿ª×ÜÖжÏ
while(1)
{
for(i=0;i<9;i++) //Ïòco2´«¸ÐÆ÷·¢ËÍÊý¾Ý
{
send(tab[i]);
}
delayms(1000); //ÑÓʱһÃë ˢвâµÃÊý¾Ý
tmp=date[2]*256+date[3]; //¼ÆËã³öco2Ũ¶ÈÖµ
if(tmp>9999)
tmp=0;
WRITE_LCD1602_COM(0x80+8);
if((tmp/1000)>0)
WRITE_LCD1602_DAT(LCD1602_Table[tmp/1000]);
else WRITE_LCD1602_DAT('0');
WRITE_LCD1602_DAT(LCD1602_Table[tmp%1000/100]);
WRITE_LCD1602_DAT(LCD1602_Table[tmp%100/10]);
WRITE_LCD1602_DAT(LCD1602_Table[tmp%10]);
}
}
void serial()interrupt 4 //´®¿ÚÖжϷþÎñº¯Êý
{
static uchar j;
ES=0; //½ûÖ¹ÖжÏ
if(!RI);
RI=0; //Çå³þ½ÓÊÕÍê±Ï±êÖ¾
date[j]=SBUF;
if(date[0]==0xff) //ÅжϽÓÊÕµ½µÄµÚһλΪ´«¸ÐÆ÷Ëù·¢Êý¾Ý
j++;
else
j=0;
if(j==9) //½ÓÊÕ´«¸ÐÆ÷Ëù·¢Êý¾Ý9×Ö½Ú
j=0;
ES=1; //ÔÊÐí´®¿ÚÖжÏ
} |