?? 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)
{
//發(fā)送啟始位
uchar i=8;
TR0=1;
WaitTF0();
TT=(bit)0;
WaitTF0();
//發(fā)送8位數(shù)據(jù)位
while(i--)
{
TT=(bit)(input&0x01); //先傳低位
WaitTF0();
input=input>>1;
}
//發(fā)送校驗位(無)
//發(fā)送結(jié)束位
TT=(bit)1;
WaitTF0();
}
//背光: 0開 1關(guān)
void lcd_light(uchar light)
{
WByte(0x1b);
WByte(0x25);
WByte(light);}
//清屏
void lcd_cls(void)
{
WByte(0x1b);
WByte(0x32);
}
//設(shè)置光標(biāo)位置
void lcd_cursor(uchar x, uchar y)
{
WByte(0x1b);
WByte(0x33);
WByte(x);
WByte(y);
}
//光標(biāo)閃爍還是關(guān)閉
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結(jié)束
{
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);
}
/*-----------------------------------------
功能: 任意位置顯示一個漢字
輸入漢字內(nèi)碼,坐標(biāo)為像素
-----------------------------------------*/
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進制數(shù)
顯示范圍 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進制數(shù) 00-99 num為不大于99的數(shù)*/
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);
}
/*-----------------------------------------
功能: 在指定的位置顯示浮點數(shù)
顯示范圍 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的字母或數(shù)字
---------------------------------------------*/
void Display35(uchar x,uchar y,uchar CH)
{
WByte(0x1b);
WByte(0x3b);
WByte(x);
WByte(y);
WByte(0x30+CH);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -