📄 lcd.c
字号:
/*
数码管扫描显示驱动程序
*/
#include "config.h"
uchar buf1[8];
/*
函数:DispChar()
功能:在数码管上显示字符
参数:
x:数码管的坐标位置(0~7)
mydata:要显示的字符(仅限十进制数字和减号)
*/
void DispChar(unsigned char x, unsigned char mydata)
{
//0123456789的数码管字型数据
code unsigned char SegTab[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00};
//0 1 2 3 4 5 6 7 8 9 no
code unsigned char ComTab[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
// seg--- P0
//com ---P1
// if (x==4)
//{
// P0=(SegTab[mydata]|0x80);//dot on
// }
//else
//{
P0=~SegTab[mydata];
P1=~ComTab[x];
// }
// if ( c == '-' )
// {
// DispBuf[x] = 0x40;
// }
// else if ( ( c >= 0) && ( c <= 10 ) )
// {
// DispBuf[x] = Tab[c];
// }
}
/*
函数:DispStr()
功能:在数码管上显示字符串
参数:
*s:要显示的字符串(字符仅限十进制数字和减号)
*/
void DispStr( unsigned char *s)
{
//uchar s[8]={1,2,3,4,5,6,7,8} ;
unsigned char i;
uchar x=0;
for (i=0;i<8;i++)
{
DispChar(x,*s);
s++;
x++;
}
}
/*
函数:DispDotOn()
功能:显示指定位的小数点
参数:x为数码管坐标
*/
//void DispDotOn(unsigned char mydata)
//{
// mydata|= 0x80;
//}
/*
函数:ByteToStr()
功能:字节型变量c转换为十进制字符串
*/
void ByteToStr(unsigned char *s, int c )
{
uchar aa,bb,cc;
s[0]=c/100;//百位
s[1]=c%100/10;//十位
s[2]=c%100%10;//个位
aa=c/100;
// bb==c%100/10;//十位 //c/10-s[0]*10;//十位
// cc=c%100%10;//个位 //c-s[0]*10-s[1];//个位
// printf("c=%ud\n",c);
// printf("s[0]=%ud\n",s[0]);
// printf("s[1]=%ud\n",s[1]);
// printf("s[2]=%ud\n",s[2]);
}
/*
函数:DispTemp()
功能:在数码管上显示出温度值
参数:
t:补码,除以8以后才是真正温度值
*/
unsigned char* DispTemp(int t)
{
extern Temperature_Set;//设定温度
unsigned char buf[3];
unsigned char buf1[8];
bit s; //符号位
int i; //整数部分
int d; //小数部分
// unsigned char x; //临时变量
//分离出符号
s = 0;
if ( t < 0 )
{
s = 1;
t = -t;
}
//分离出整数和小数部分
// printf("t=%d\n",t);
i = t / 8;
d = t % 8;
d=d*125;
// printf("i=%ud\n",i);
// printf("d=%ud\n",d);
//整数部分转换成字符串
ByteToStr(buf,i);
buf1[5]=buf[0];
buf1[4]=buf[1];
buf1[3]=buf[2];
if(0==buf1[5])
{
buf1[5]=10;
}
else if((10==buf1[5])&&(0==buf1[4]))
{
buf1[4]=10;
}
ByteToStr(buf,d);
buf1[2]=buf[0];
buf1[1]=buf[1];
buf1[0]=buf[2];
//buf1[2]=0;
//buf1[1]=1;
//buf1[0]=3;
ByteToStr(buf,Temperature_Set);
buf1[7]=buf[1];
buf1[6]=buf[2];
return buf1;
// DispStr(8,buf1);
//显示小数点
// DispDotOn(4);
//x = 4 - strlen(buf);
//清除所有显示
//DispClear();
//显示符号
//if ( s ) DispChar(x,'-');
//x++;
//显示整数部分
//DispStr(x,buf);
//显示小数部分
// DispStr(5,Tab[d]);
}
void disp(int t)
{
// const uchar Dispbuf[8]={0};
//com = 0xFF; //暂停显示
unsigned char *Dispbuf=0;
Dispbuf = DispTemp(t);
// DispStr( Dispbuf) ;
//DispTemp(buf1, t);
// Dispbuf[8]
// DispStr(Dispbuf);
//DispStr(buf1);
//DispDotOn(5);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -