📄 timer_thermometer_12864.c
字号:
//时钟和温度显示程序.制作:№→蓝海啸浪 404530302
//用T0中断定时,DS18B20测温,12864完成显示.原创
#include<reg52.h>
//#include<math.h>
#include<Write_12864.h>
#include<DB_12864.h>
#include<Read_DS18b20.h>
#define SETUP 0x0FE
#define LEFT 0x0FB
#define UP 0x0F7
#define DOWN 0x0EF
#define RIGHT 0x0DF
#define ENTER 0x07F
#define CANCEL 0x0BF
#define CLEAR 0x0FD
#define TCONST 49970
unsigned char *p; //显示程序查表指针
unsigned char *pdt; //时间日期显示区指针
unsigned char secf=0; //秒闪标志
unsigned char DTBUF[7]={07,1,15,1,12,30,30};//年/月/日/星期/时/分/秒;
unsigned char DTTMP[7];
unsigned char MSFLAG=20; //20MS倒计时标志
unsigned char dp; //显示允许,控制中断显示调用 dispermit
unsigned char TMPBUF_MSB,TMPBUF_LSB;
unsigned char TCOUNT=0;
//显示程序,
//sn控制显示数组的第几个元素serial number//年/月/日/星期/时/分/秒;
//,fl用来控制闪烁,当为0时显示" ",k为显示的开关参数,为0则显示程序段有效,开显示
void DateTime_Display(unsigned char *arrayp,unsigned char sn,unsigned char fl,unsigned char k)
{ unsigned char h,l,buf,xp,bs,cs,yp;
unsigned char *arraypointer,*pp;
//unsigned char yp;位置指针,即时间数据在Y轴的坐标
//unsigned char cs;时间数据在LCD上的左右边标志,0在左
//unsigned char bs;定义扫描的位数,当为0-9时,则扫描位数为8,倍率为16
//为一,二,时则扫描位数为16,倍率为32
arraypointer=arrayp;
if(k==0)
{
if(sn<3)
xp=0; //小于3则为日期,显示在第一行
else xp=2; //大于等于三则显示第二行,分别为时间和星期,
buf=*(arraypointer+sn);
switch(sn)
{ case 0: yp=16; cs=0; break; // 年,显示在第一行左边,坐标从16开始
case 1: yp=48; cs=0; break; // 月,显示在第一行左边,坐标从48开始
case 2: yp=16; cs=1; break; // 日,显示在第一行右边,坐标从16开始
case 3: yp=32; cs=0; break; // 星期,显示在第三行左边,坐标从48开始
case 4: yp=0; cs=1; break; // 时,显示在第三行左边,坐标从0开始
case 5: yp=24; cs=1; break; // 分,显示在第三行左边,坐标从24开始
case 6: yp=48; cs=1; break; // 秒,显示在第三行左边,坐标从48开始
default: break;
}
//****************
if(fl==1) //闪烁标志,当FL为0时显示" ",为1时正常显示
{if(sn==3)
{ pp=tabb; //星期,调用B数组显示
bs=16;
h=buf; //当显示星期时,16*16的编码只要送高位;
}
else
{ pp=taba; //日期与时间为数字,调用A数组,
bs=8;
h=buf/10;
l=buf%10;
}
}
else if(fl==0) //为0则显示" "
{ pp=tabe;
h=0;
l=0;
if(sn==3) bs=16;
else bs=8;
}
//****************
p=pp;
if(cs==0)
{ p=p+h*bs*2; Left_Bytes_DaSend(xp, yp, p,bs);
p=p+bs; Left_Bytes_DaSend(xp+1, yp, p,bs);
if(bs==8) //为8位的数字,则需要显示低位;
{p=pp; p=p+l*bs*2;
yp=yp+bs; Left_Bytes_DaSend(xp, yp, p,bs);
p=p+bs; Left_Bytes_DaSend(xp+1, yp, p,bs);
}
}
else if(cs==1)
{
p=p+h*bs*2; Right_Bytes_DaSend(xp, yp, p,bs);
p=p+bs; Right_Bytes_DaSend(xp+1, yp, p,bs);
if(bs==8) //为8位的数字,则需要显示低位;
{p=pp; p=p+l*bs*2;
yp=yp+bs; Right_Bytes_DaSend(xp, yp, p,bs);
p=p+bs; Right_Bytes_DaSend(xp+1, yp, p,bs);
}
}
}
//else{;}
}
//秒闪显示
void Second_Flash(unsigned char f)
{
if(f==1)
{p=tabc;
p=p+64;}
else p=tabe;
Right_Bytes_DaSend( 2, 40, p,8);
p=p+8;
Right_Bytes_DaSend( 3, 40, p,8);
}
//清屏子程序
void Clean_Lcd(void)
{
unsigned char i;
p=tabe;
for(i=0;i<8;i++)
{
Left_Bytes_DaSend( i, 0, p,32);
Left_Bytes_DaSend( i, 32, p,32);
Right_Bytes_DaSend( i, 0, p,32);
Right_Bytes_DaSend( i, 32, p,32);
}
}
//显示"水位 .米"在第四行
void Display_LCD_1(void)
{
p=tabd; Left_Bytes_DaSend( 6, 16, p,16);
p=p+16; Left_Bytes_DaSend( 7, 16, p,16);
p=p+16; Left_Bytes_DaSend( 6, 32, p,16);
p=p+16; Left_Bytes_DaSend( 7, 32, p,16);
p=p+16; Right_Bytes_DaSend( 6, 16, p,8);
Right_Bytes_DaSend( 4, 32, p,8);
p=p+8; Right_Bytes_DaSend( 7, 16, p,8); Right_Bytes_DaSend( 5, 24, p,8);
Right_Bytes_DaSend( 5, 32, p,8);
p=p+8; Right_Bytes_DaSend( 6, 40, p,16);
p=p+16; Right_Bytes_DaSend( 7, 40, p,16);
}
//显示"年月日"在第二行
void Display_LCD_2(void)
{
p=tabc; Left_Bytes_DaSend( 0, 32, p,16);
p=p+16; Left_Bytes_DaSend( 1, 32, p,16);
p=p+16; Right_Bytes_DaSend( 0, 0, p,16);
p=p+16; Right_Bytes_DaSend( 1, 0, p,16);
p=tabb;
p=p+192; Right_Bytes_DaSend( 0, 32, p,16);
p=p+16; Right_Bytes_DaSend( 1, 32, p,16);
}
//显示"20"在第一行,年
void Display_LCD_3(void)
{
p=taba; Left_Bytes_DaSend( 0, 8, p,8);
p=p+8; Left_Bytes_DaSend( 1, 8, p,8);
p=p+24; Left_Bytes_DaSend( 0, 0, p,8);
p=p+8; Left_Bytes_DaSend( 1, 0, p,8);
}
//显示":"在第二三行
void Display_LCD_4(void)
{
p=tabc; p=p+64;
Right_Bytes_DaSend( 2, 16, p,8);
Left_Bytes_DaSend( 4, 48, p,8);
Left_Bytes_DaSend( 6, 48, p,8);
p=p+8;
Right_Bytes_DaSend( 3, 16, p,8);
Left_Bytes_DaSend( 5, 48, p,8);
Left_Bytes_DaSend( 7, 48, p,8);
}
//显示"星期"在第三行
void Display_LCD_5(void)
{
p=tabc;
p=p+80; Left_Bytes_DaSend( 2, 0, p,16);
p=p+16; Left_Bytes_DaSend( 3, 0, p,16);
p=p+16; Left_Bytes_DaSend( 2, 16, p,16);
p=p+16; Left_Bytes_DaSend( 3, 16, p,16);
}
//显示"温度C"
void Display_LCD_6(void)
{
p=tabd;
p=p+112; Left_Bytes_DaSend( 4, 16, p,16);
p=p+16; Left_Bytes_DaSend( 5, 16, p,16);
p=p+16; Left_Bytes_DaSend( 4, 32, p,16);
p=p+16; Left_Bytes_DaSend( 5, 32, p,16);
p=p+16; Right_Bytes_DaSend( 4, 48, p,16);
p=p+16; Right_Bytes_DaSend( 5, 48, p,16);
}
//显示负号
void Display_LCD_7(void)
{
p=tabf; Right_Bytes_DaSend( 4, 0, p,8);
p=p+8; Right_Bytes_DaSend( 5, 0, p,8);
}
//清除负号
void Display_LCD_8(void)
{
p=tabe; Right_Bytes_DaSend( 4, 0, p,8);
p=p+8; Right_Bytes_DaSend( 5, 0, p,8);
}
//void DS18B20_Start (void)
//unsigned long DS18B20_Tmp_Read()
//温度转换程序
unsigned char Tmp_Convert(void)
{
unsigned int TMP_BUF; //温度缓冲单元
unsigned char TMP_SIGN; //温度符号
TMP_BUF=DS18B20_Tmp_Read();
TMP_SIGN=(unsigned char)(TMP_BUF>>12);
if(TMP_SIGN)TMP_BUF=(~TMP_BUF)+1;
TMPBUF_MSB=(unsigned char)(TMP_BUF>>4); //取中间八位的值
TMPBUF_LSB=(unsigned char)(TMP_BUF&0x0f);//取低四位的值
TMPBUF_LSB=(TMPBUF_LSB*10)/16; //乘10除16相当于乘以0.625
if(TMP_SIGN)return 1; //返回符号标志位
else return 0;
}
//温度显示程序
void Tmp_Display(void)
{ unsigned char tmpf,k,h,l;
tmpf=Tmp_Convert(); //调用温度转换程序
if(TMPBUF_MSB>125){TMPBUF_MSB=0;Display_LCD_7();}
else Display_LCD_8(); //负号消隐;
k=TMPBUF_MSB/100;
h=(TMPBUF_MSB%100)/10;
l=(TMPBUF_MSB%100)%10;
if(tmpf) {Display_LCD_7();tmpf=0;}
else Display_LCD_8();
if(k==0) p=tabe;
else p=taba; //高位为零则消隐
p=p+(k*16); Right_Bytes_DaSend(4, 8, p,8);
p=p+8; Right_Bytes_DaSend(5, 8, p,8);
if(k==0&&h==0) p=tabe;
else p=taba;
p=p+(h*16); Right_Bytes_DaSend(4, 16, p,8);
p=p+8; Right_Bytes_DaSend(5, 16, p,8);
p=taba;
p=p+(l*16); Right_Bytes_DaSend(4, 24, p,8);
p=p+8; Right_Bytes_DaSend(5, 24, p,8);
p=taba;
p=p+(TMPBUF_LSB*16);Right_Bytes_DaSend(4, 40, p,8);
p=p+8; Right_Bytes_DaSend(5, 40, p,8);
}
//LCD初始化程序
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -