#include <REG51.H>//車?DS18B20?足2a???豕㏒?2⊿車?OCMJ2X8C∩?DD??那?3足D辰㏒?
#define uint unsigned int
#define uchar unsigned char
#define x 0x80
#define y 0x80
#define comm 0
#define dat 1
sbit cs = P3^6;
sbit std = P3^5;
sbit sclk = P3^2;
sbit psb = P3^3; //H=2⊿?迆; L=∩??迆;
sbit rst = P3^4; //Reset Signal 米赤米???車DD∫
sbit TMDAT= P2^6;
bit tsign;
bit flag;
void wr_lcd (uchar dat_comm,uchar content);
void delay (uint us);
uchar code tab1[]={
" ?D1迆那‘車赤∩車?∫ "};
uchar code tab2[]={
"3??t那赤 05?那10?? "
};
uchar code tab3[]={
" 米㊣?∼???豕?a "
};
uchar code tab4[]={
"??足足芍? 足足??o?豕豕"};
uchar code tab5[]={
"辰a℅⊿辰a﹞角那??米??∼?"};
uchar code tab6[]={
" ??足足???豕那那辰? "};
uchar code tab7[]={
"??3?豕ㄓ???‘辰???∼谷"};
uchar code tab8[]={
" ??足足足足??o?角? "};
uchar code tab9[]={
"D?D?谷赤足?㊣e?D?∼∼?"};
uchar code tab10[]={
/*-- 米‾豕?芍?辰?﹞迄赤???㏒oF:\芍o\?-赤?\HOCO12832.bmp --*/
/*-- ?赤?豕x???豕=128x32 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x18,0x0C,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x13,0x10,0x03,0xFE,0x00,
0x03,0xFF,0xC0,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x3F,0x30,0x1F,0xFF,0xC0,
0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x8C,0x03,0xF0,0x00,0x7F,0xE0,0x7C,0x01,0xE0,
0x03,0xFF,0xF0,0x00,0x00,0x00,0x01,0x36,0x06,0xC0,0x00,0x5F,0xC0,0xFF,0xFC,0x60,
0x01,0xFF,0xF0,0x00,0x00,0x00,0x02,0x1B,0x0F,0x80,0x00,0xFF,0x01,0xFE,0x0F,0x30,
0x00,0xEF,0xF0,0x00,0x00,0x00,0x02,0x6D,0x9F,0x00,0x00,0x3E,0x03,0xFF,0xF1,0x90,
0x00,0xFF,0xF8,0x00,0x00,0x00,0x04,0x36,0xFE,0x00,0x01,0xFF,0x07,0xFF,0xFC,0x90,
0x00,0xEF,0xFF,0xFF,0x80,0x00,0x04,0xDB,0x7E,0x00,0x03,0xFF,0x87,0xFF,0xFC,0xD0,
0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x04,0x6D,0xFC,0x00,0x07,0xFF,0x8F,0xFF,0xFE,0x50,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x36,0xFC,0x10,0x07,0xFF,0x8F,0xFF,0xFE,0x90,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x1B,0xF8,0x10,0x07,0xFF,0xCF,0xFF,0xFE,0x80,
0x00,0x0F,0xFF,0xFF,0xF0,0x00,0x04,0x0F,0xF8,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0x07,0xFF,0xFF,0xF0,0x00,0x04,0x07,0xF0,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x02,0x03,0xF0,0x20,0x07,0xFF,0xFF,0xFF,0xBA,0x00,
0x00,0xFD,0xFF,0xFF,0xFC,0x00,0x02,0x03,0xF0,0x20,0x03,0xFF,0xFF,0xDF,0xB8,0x00,
0x00,0xC1,0xC0,0x3F,0xFC,0x00,0x01,0x01,0xE0,0x40,0x00,0xFF,0xFF,0xDF,0xB0,0x00,
0x00,0x81,0xC0,0x3F,0xCE,0x00,0x00,0x81,0xE0,0x80,0x00,0x7F,0xFF,0xDF,0xA0,0x00,
0x00,0x81,0x80,0x1D,0xCF,0x00,0x00,0x41,0xE1,0x00,0x00,0x3F,0xFF,0x9B,0x00,0x00,
0x01,0x83,0x80,0x1F,0xC7,0x80,0x00,0x21,0xE2,0x00,0x00,0x1F,0xFD,0xB6,0x00,0x00,
0x01,0xC3,0x00,0x0E,0xE6,0x80,0x00,0x19,0xEC,0x00,0x00,0x07,0xFE,0x20,0x00,0x00,
0x00,0xC3,0x00,0x07,0x67,0x40,0x00,0x07,0xF0,0x00,0x00,0x03,0x3E,0x00,0x00,0x00,
0x00,0x02,0x00,0x03,0xE7,0xA0,0x00,0x00,0x00,0x00,0x00,0x02,0x8E,0x00,0x00,0x00,
0x00,0x06,0x00,0x03,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,
0x00,0x06,0x00,0x07,0x03,0x00,0x77,0x46,0x74,0x24,0x80,0x06,0x04,0x00,0x00,0x00,
0x00,0x1C,0x00,0x06,0x00,0x00,0x55,0x45,0x54,0x57,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x00,0x0E,0x00,0x00,0x45,0x45,0x74,0x57,0x80,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x00,0x00,0x55,0x45,0x44,0x74,0x80,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x77,0x76,0x47,0x54,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/*------------------3?那??‘-----------------*/
void init_lcd (void)
{
rst=1;
psb=0; //∩?DD
wr_lcd (comm,0x30); /*30---?迄㊣???芍??‘℅‾*/
wr_lcd (comm,0x01); /*???芍㏒?米??﹞???????辰00H*/
delay (80);
wr_lcd (comm,0x06); /*1a㊣那米?辰??‘﹞??辰*/
wr_lcd (comm,0x0c); /*?a??那?㏒?1?車?㊣那*/
}
/*---------------??那?oo℅??辰℅?﹞?----------------*/
void chn_disp1 (uchar code *chn)//?迆米迆辰?DDD∩℅?
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
j=0;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
void chn_disp2 (uchar code *chn)//?迆米迆?tDDD∩℅?
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x90);
j=0;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
/*----------------??那?赤?D?-----------------*/
void img_disp (uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd(comm,0x34);
wr_lcd(comm,y+j);
wr_lcd(comm,x+i);
wr_lcd(comm,0x30);
wr_lcd(dat,img[j*16+i*2]);
wr_lcd(dat,img[j*16+i*2+1]);
}
}
wr_lcd(comm,0x36);
}
/*---------------------------------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
uchar a,i,j;
delay (40);
a=content;
cs=1;
sclk=0;
std=1;
for(i=0;i<5;i++)
{
sclk=1;
sclk=0;
}
std=0;
sclk=1;
sclk=0;
if(dat_comm)
std=1; //data
else
std=0; //command
sclk=1;
sclk=0;
std=0;
sclk=1;
sclk=0;
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
a=a<<1;
std=CY;
sclk=1;
sclk=0;
}
std=0;
for(i=0;i<4;i++)
{
sclk=1;
sclk=0;
}
}
}
/*---------------------------------------*/
void delay (uint us) //delay time
{
while(us--);
}
void dmsec(unsigned int count)
{
unsigned int i;
while(count--){
for(i=0;i<125;i++){}
}
}
void tmreset(void)
{
unsigned int i;
TMDAT=0;
i=103;while(i>0) i--;
TMDAT=1;
i=4;while(i>0) i--;
}
void tmpre(void)
{
unsigned int i;
flag=0;
while(TMDAT);
i=32;
while(i--)
{
if(TMDAT) {flag=1;break;}
}
i=4;while(i>0) i--;
}
bit tmrbit(void) //read one bit
{
bit tdat;
unsigned int i;
TMDAT=1;
i++;
TMDAT=0;i++;
TMDAT=1;i++;i++;i++;
tdat=TMDAT;
i=8;
while(i>0) i--;
return(tdat);
}
unsigned char tmrbyte(void) //read one byte
{
unsigned char i,j;
unsigned char tdat=0;
for(i=1;i<=8;i++)
{
j=tmrbit();
tdat=(j<<7)|(tdat>>1);
}
return(tdat);
}
void tmwbyte(unsigned char tdat)
{
unsigned int i;
unsigned char j;
bit testb;
TMDAT=1;i++;i++;
for(j=1;j<=8;j++)
{
testb=tdat&0x01;
tdat=tdat>>1;
if(testb)
{
TMDAT=0; //write 1
i++;i++;
TMDAT=1;
i=8;while(i>0) i--;
}
else
{
TMDAT=0; //write 0
i=8;while(i>0) i--;
TMDAT=1;
i++;i++;
}
}
}
void tmstart(void) //ds18b20 start convert
{
do{ tmreset();
tmpre();
}while(~flag);
dmsec(1);
tmwbyte(0xcc); //skip rom
tmwbyte(0x44); //convert
}
unsigned int tmrtemp(void) //read temp
{
unsigned char a,b, y1,y2,y3;
unsigned int t1=0x0000;
float tt;
unsigned int t;
do{ tmreset();
tmpre();
}w