📄 lcd drive.c
字号:
//proteus仿真论坛:http://proteus.5d6d.com/
#include <reg51.h>
#include "LCD1602.h"
#define uchar unsigned char
#define uint unsigned int
#define High 1
#define Low 0
int t;
sbit cs=P1^7;
sbit sclk=P1^6;
sbit dout=P1^5;
sbit P30=P3^0;
sbit P31=P3^1;
sbit P32=P3^2;
sbit P33=P3^3;
sbit P34=P3^4;
sbit P35=P3^5;
sbit P36=P3^6;
sbit P37=P3^7;
unsigned char a[5];
unsigned char b[5];
unsigned char TempBuffer[10];
/***************************************
max1241读转换结果
****************************************/
uint read_max1241()
{
uint voltage_temp=0;
uchar ucloop=12;
cs=High;
//dout=low;
sclk=Low;
cs=Low;
while(dout==0);//EOC信号为高表示转换结束
sclk=High;
sclk=Low;
while(ucloop--)
{
sclk=High;//上升沿数据稳定并读出
voltage_temp<<=1;
if(dout==1)
voltage_temp+=1;
sclk=Low;
};
//sclk=low;
cs=High;
return voltage_temp;
}
void IntToStr(unsigned char *str, unsigned char n)
{
char i, j;
t=read_max1241();
b[0]=(t/10000)%10; //取得整数值到数组
b[1]=(t/1000)%10;
b[2]=(t/100)%10;
b[3]=(t/10)%10;
b[4]=(t/1)%10;
for(i=0; i<5; i++)
a[i]=b[i];
for(i=0; i<5; i++) //转成ASCII码
a[i]=a[i]+'0';
for(i=0; a[i]=='0' && i<=3; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; }
for(; i<5; i++)
{ *str=a[i]; str++; } //加入有效的数字
*str='\0';
}
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
main()
{
LCD_Initial();
GotoXY(0,0);
Print("The 1602LCD Test");
GotoXY(0,1);
Print("Input NO.: ");
while(1)
{
IntToStr(&TempBuffer[0],5);
GotoXY(11,1);
Print(&TempBuffer[0]);
Delay1ms(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -