標(biāo)題: 12864液晶顯示加ds18b20溫度顯示 [打印本頁(yè)]

作者: 橘生淮南則為橘    時(shí)間: 2019-4-23 23:02
標(biāo)題: 12864液晶顯示加ds18b20溫度顯示
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit DQ=P3^7;//溫度傳感器DQ端接單片機(jī)P2.0口
sbit beep=P1^5;
// 12864液晶位定義
sbit key1=P3^2;
sbit key2=P3^1;
sbit key3=P3^4;

sbit lcdrs=P2^6;//液晶的RS端接P3.4口
sbit lcdrw=P2^5;//液晶的RW端接P3.6口
sbit lcden=P2^7;// 液晶的EN使能端接P3.7口
uchar shi,fen,miao;
uint wendu=0;
uchar AN;
/********************延時(shí)函數(shù),延時(shí)一毫秒************************/

void delay1ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}

/**************************12864顯示****************************/

void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay1ms(1);
lcden=1;
delay1ms(1);
lcden=0;

}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
delay1ms(1);
lcden=1;
delay1ms(1);
lcden=0;
}

void write_str(uchar *str)
{
while(*str!='\0')  //表示字符串的結(jié)束
{
write_date(*str++);
delay1ms(5);
}
}

void write_pos(uchar x,uchar y)//從第X行的第Y位置開始顯示? ?
{
uchar pos;
if(x==1)//第一行? ?
{ x=0x80;}
else if(x==2)//第二行? ?
{ x=0x90;}
else if(x==3)//第三行? ?
{ x=0x88;}
else if(x==4)
{ x=0x98;}
pos=x+y-1;
write_com(pos);
}

/***************************12864液晶初始化******************************/

void init_12864()
{
lcdrw=0;
lcden=0;
write_com(0x01);//清屏命令
delay1ms(5);
write_com(0x30);//設(shè)置基本指令集動(dòng)作? ? ? ??
write_com(0x06); //進(jìn)入顯示模式
write_com(0x0c); // 開顯示
write_com(0x88);
write_pos(1,1);
write_str("溫度測(cè)量實(shí)驗(yàn)");
write_pos(2,1);
write_str("實(shí)時(shí)溫度:");
write_pos(2,8);
write_str("度");
write_pos(3,1);
write_str("單片機(jī)時(shí)鐘");
// write_pos(4,1);
// write_str("00時(shí)00分00秒");



}
void write_shu(uchar add,uchar date)
{
        uchar ge,shi;
        shi=date/10;
        ge=date%10;
        write_com(0x98+add);
        write_date(0x30+shi);
        write_date(0x30+ge);
}
void init(void)
{       
        write_com(0x98+3);
        write_date(':');
        delay1ms(10);
        write_com(0x98+0x01);
        write_date(':');
        delay1ms(10);

        write_shu(4,miao);
        write_shu(2,fen);
        write_shu(0,shi);

        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;
        ET0=1;
        TR0=1;

}
void di()
{
beep=1;
delay1ms(10);
beep=0;
}
void key_scan()
{
        if(key1==0)
        delay1ms(100);
        if(key1==0)
        {
                TR0=0;
                AN++;
                while(!key1);
        }
                        if(AN==1)
                {
                        write_com(0x98+5);         //光標(biāo)顯示位
                        write_com(0x0f);
                }
                if(AN==2)
                {
                        write_com(0x98+3);         //光標(biāo)顯示位
                        write_com(0x0f);
                }
                if(AN==3)
                {
                        write_com(0x98+1);         //光標(biāo)顯示位
                        write_com(0x0f);
                }
                 if(AN==4)
                 {
                         TR0=1;
                         AN=0;
                         write_com(0x0c);         //開整體顯示,開游標(biāo)
                 }
                        if(AN==1)
                        {
                            if(key2==0)
                            delay1ms(100);
                            if(key2==0)
                            {
                                   while(!key2);
                                    miao++;
                                    if(fen==60)
                                    {    fen=0;
                                             shi++;
                                                        if(shi==24)
                                                                shi=0;
                                    }
                            }
                        }
                                if(AN==2)
                                {
                                        write_com(0x98+2);         //光標(biāo)顯示位
                                        write_com(0x0f);
                            if(key2==0)
                            delay1ms(100);
                            if(key2==0)
                            {
                                   while(!key2);
                                           shi--;
                                                if(shi==24)
                                     shi=0;
                                    write_shu(0,shi);
                            }
                                }
                                if(AN==3)
                                {
//                                        write_com(0x98+0);         //光標(biāo)顯示位
//                                        write_com(0x0f);
                            if(key3==0)
                            delay1ms(100);
                            if(key3==0)
                            {
                                   while(!key2);
                                           miao--;
                                                if(miao==00)
                                     shi=0;
                                    write_shu(1,shi);
                            }
                                }
                } }
剩下的程序可以在壓縮包里看



5.jpg (100.42 KB, 下載次數(shù): 44)

5.jpg

液晶1602顯示.zip

172.66 KB, 下載次數(shù): 40, 下載積分: 黑幣 -5


作者: 1367067553    時(shí)間: 2019-4-27 19:12
溫度可以顯示嘛  我看了好幾個(gè)都不行




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1