lcd1602.c

来自「LCD 1602 显示程序 包含初始化及相关应用函数 功能较为完备」· C语言 代码 · 共 61 行

C
61
字号
#include <REGX52.H>
#include "LCD1602.h"

unsigned char TempBuffer[10];
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;                                        	
                                                      
	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 delay()
   {
    unsigned int i,j;
	for(i=0;i<1000;i++)
	for(j=0;j<100;j++);
   }
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 = 0;
	LCD_Initial();              //lcd 初始化
	GotoXY(0,0);				// Y
	Print("     welcome!");		// 0
    GotoXY(0,1);                // 1
	Print(" COPYRIGHT: TQ");    //	 0  1          X
	delay();
	P3=0xff;	
    while(1) 
	
	{
		IntToStr(Count++,&TempBuffer[0],5);
		GotoXY(0,0);
		Print("COUNTING...");
		Print(&TempBuffer[0]);
		GotoXY(0,1);
		Print("                     ");
	    P3=~P3;
		Delay1ms(100);
		Count++;
	}  	
}

⌨️ 快捷键说明

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