📄 lcd.c
字号:
#include <reg51.h>
#include "LCD1602.h"
#include<stdio.h>
sbit P10=0x90;
sbit P11=0x91;
sbit P12=0x92;
sbit P13=0x93;
sbit P14=0x94;
sbit P15=0x95;
sbit P16=0x96;
sbit P17=0x97;
unsigned char disp_data[]={"0""1""2""3""4""5""6""7""8""9""10""11""12""13""14""15"};
void IntToStr(unsigned int Count, unsigned char *str, unsigned char n)
{
unsigned char a[5]; char i, j;
a[0]=(Count/10000)%10; //取得整数值到数组
a[1]=(Count/1000)%10;
a[2]=(Count/100)%10;
a[3]=(Count/10)%10;
a[4]=(Count/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++);
}
main()
{
unsigned int Count;
SCON=0x52;
TMOD=0x20;
TCON=0x69;
TH1=0xf3;
LCD_Initial();
GotoXY(0,0);
Print("The 1602LCD Test");
GotoXY(0,1);
Print("GO: by JJJ");
while(1)
{
{
if(P14==0 && P13==0) Count=0;
if(P14==0 && P12==0) Count=1;
if(P14==0 && P11==0) Count=2;
if(P14==0 && P10==0) Count=3;
if(P15==0 && P13==0) Count=4;
if(P15==0 && P12==0) Count=5;
if(P15==0 && P11==0) Count=6;
if(P15==0 && P10==0) Count=7;
if(P16==0 && P13==0) Count=8;
if(P16==0 && P12==0) Count=9;
if(P16==0 && P11==0) Count=10;
if(P16==0 && P10==0) Count=11;
if(P17==0 && P13==0) Count=12;
if(P17==0 && P12==0) Count=13;
if(P17==0 && P11==0) Count=14;
if(P17==0 && P10==0) Count=15;
}
IntToStr(Count,&disp_data[16],5);
GotoXY(3,1);
Print(&disp_data[16]);
Delay1ms(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -