📄 0809+1602.c
字号:
#include <REG51.H>
#include "LCD1602.h"
unsigned char TempBuffer[10];
#define uchar unsigned char
#define uchar unsigned char
#define uint unsigned int
sbit START=P2^4;
sbit OE=P2^5;
sbit EOC=P2^6;
uint data tvdata;
void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
{
/* unsigned char a[5]; char i, j;
a[0]=(t/10000)%10; //取得整数值到数组
a[1]=(t/1000)%10;
a[2]=(t/100)%10;
a[3]=(t/10)%10;
a[4]=(t/1)%10;*/
unsigned char a[5]; char i, j;
a[0]=(t/1000)%10; //取得整数值到数组
a[1]=(t/100)%10;
a[2]=(t/10)%10;
a[3]='q'; //&v,%u,$t,#s ,#p, 字母Q,显示“。”
a[4]=(t/1)%10;
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++);
}
void sentdata(uint data i)
{
SBUF=i;
while(TI==0);
TI=0;
}
void main(void)
{
LCD_Initial();
GotoXY(0,0);
Print("DC vol BG1TRK");
GotoXY(0,1);
Print(" V");
while(1)
{ START=1;
START=0; //启动转换
while(EOC==0);
OE=1;
tvdata=P1;
tvdata= tvdata*2;
OE=0;
sentdata(tvdata);
IntToStr(tvdata,&TempBuffer[0],5);
GotoXY(0,1);
Print(&TempBuffer[0]);
Delay1ms(20);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -