lcd1602.c

来自「16*2液晶显示1602驱动程序」· C语言 代码 · 共 54 行

C
54
字号
#include <REG52.H>
#include "LCD1602.h"

unsigned char TempBuffer[10];
void IntToStr(unsigned long t, unsigned char *str) 
{
unsigned char a[10]; char i,length;                                 	
while(t/10) 			//将计数值转换为数码管段码值
       	{ 
            a[i]=t%10; 
            t=t/10; 
            i++; 
           } 
        a[i]=t; 
length=i+1;                                                     
	for(i=0; i<length; i++)         //转成ASCII码              	
		a[i]=a[i]+'0';                                    	
//for(i=0; a[i]=='0' && i<=6; i++);                     	
//for(j=8-n; j<i; j++)       //填充空格                 	
//		{ *str=' ';  str++; }                             	
	for(i=length-1; i>=0; 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 long Count = 12345678;
	LCD_Initial();
	GotoXY(0,0);
	Print("The 1602LCD Test");
	GotoXY(0,1);
	//Print("GO:       by JJJ");

//	while(1)
//	{
//			IntToStr(Count,&TempBuffer[0],8);

//		IntToStr(Count++,&TempBuffer[0],5);
IntToStr(Count,&TempBuffer[0]);

		GotoXY(3,1);
Print(&TempBuffer[0]);
//		Delay1ms(100);
//	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?