📄 mn_lcm.c
字号:
#include "reg51.h"
#include "MN_LCM.h"
sbit TT=P1^0;
void Serial_Init(void)
{
TMOD|=0X02;
TH0=0xa0;
TL0=TH0;
TR0=1;
TF0=0;
}
void WaitTF0(void)
{
while(!TF0);
TF0=0;
}
void WByte(uchar input)
{
//发送启始位
uchar i=8;
TR0=1;
WaitTF0();
TT=(bit)0;
WaitTF0();
//发送8位数据位
while(i--)
{
TT=(bit)(input&0x01); //先传低位
WaitTF0();
input=input>>1;
}
//发送校验位(无)
//发送结束位
TT=(bit)1;
WaitTF0();
}
//背光: 0开 1关
void lcd_light(uchar light)
{
WByte(0x1b);
WByte(0x25);
WByte(light);}
//清屏
void lcd_cls(void)
{
WByte(0x1b);
WByte(0x32);
}
//设置光标位置
void lcd_cursor(uchar x, uchar y)
{
WByte(0x1b);
WByte(0x33);
WByte(x);
WByte(y);
}
//光标闪烁还是关闭
void lcd_showcursor(uchar attr)
{
WByte(0x1b);
WByte(0x34);
WByte(attr);
}
//显示字符串
void lcd_string(uchar attr,uchar *pData)
{
WByte(0x1b);
WByte(0x37);
WByte(attr);
for(;*pData!=0;pData++) //遇到停止符0结束
{
WByte(*pData);
}
WByte(0x00);
}
//画圆
void lcd_circle(uchar attr,uchar ox,uchar oy,uchar rx)
{
WByte(0x1b);
WByte(0x41);
WByte(attr);
WByte(ox);
WByte(oy);
WByte(rx);
}
//画线
void lcd_line(uchar attr,uchar x0,uchar y0,uchar x1,uchar y1)
{
WByte(0x1b);
WByte(0x39);
WByte(attr);
WByte(x0);
WByte(y0);
WByte(x1);
WByte(y1);
}
//画点
void lcd_dot(uchar attr,uchar x,uchar y)
{
WByte(0x1b);
WByte(0x38);
WByte(attr);
WByte(x);
WByte(y);
}
/*-----------------------------------------
功能: 任意位置显示一个汉字
输入汉字内码,坐标为像素
-----------------------------------------*/
void DisplayHZ(uchar x,uchar y,uchar ch1,uchar ch2)
{
WByte(0x1b);
WByte(0x3a);
WByte(x);
WByte(y);
WByte(ch1);
WByte(ch2);
}
/*-----------------------------------------
功能: 在指定的位置显示字符串
入口: attr 0 正显 1 反显
x 0--17 y 0--5
*string 字符串指针
-----------------------------------------*/
void DisplayStr(uchar attr,uchar x, uchar y,uchar *string)
{
lcd_cursor(x, y);
lcd_string(attr,string);
}
/*-----------------------------------------
功能: 在指定的位置显示16进制数
显示范围 00--FF
-----------------------------------------*/
void DisplayHex(uchar x, uchar y,uchar num)
{
uchar str[3];
uchar tem;
str[2]='\0';
tem=num%16;
num/=16;
if(tem<10)
str[1] = tem+0x30;
else
str[1] = tem+0x30+7;
if(num<10)
str[0] = num+0x30;
else
str[0] = num+0x30+7;
DisplayStr(0,x,y,str);
}
/* 在指定位置显示10进制数 00-99 num为不大于99的数*/
void DisplayShi(uchar x,uchar y,uchar num)
{
uchar str[3];
uchar tem;
str[2]='\0';
tem=num%10;
num/=10;
str[1] = tem+0x30;
str[0] = num+0x30;
DisplayStr(0,x,y,str);
}
/*-----------------------------------------
功能: 在指定的位置显示浮点数
显示范围 00.00--99.99
-----------------------------------------*/
void DisplayFloat(uchar x, uchar y,float num)
{
uchar str[6];
uchar tem,tem2,tem3,tem4;
str[5]='\0';
tem=num/10;
num=num-tem*10;
tem2=num;
num=num-tem2;
tem3=num*10;
num=num-tem3*0.1;
tem4=num*100;
str[0] = tem+0x30;
str[1] = tem2+0x30;
str[2] = 0x2e;//.
str[3] = tem3+0x30;
str[4] = tem4+0x30;
DisplayStr(0,x,y,str);
}
/*--------------------------------------------------
显示一个3*5的字母或数字
---------------------------------------------*/
void Display35(uchar x,uchar y,uchar CH)
{
WByte(0x1b);
WByte(0x3b);
WByte(x);
WByte(y);
WByte(0x30+CH);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -