📄 lcd.c
字号:
{LCD_PutData(x,(Declenth-i)/2+y,character+dat[i-1]);Delay1ms(1);
}
cc=0;
}
//*****************************************************************
//显示浮点型的十进制数值
//入口参数:坐标,坐标,数值
//整数和小数部分的长度在lcd.h文件中定义 ,由于定义的数据的限制,小数和整数的长度最长为9位
//N=(unsigned long)floatdata;floatdata赋予小数部分的值再将小数点移至右边;Dp=(unsigned long)floatdata;
//******************************************
void LCD_PutFloat(unsigned char x,unsigned char y, float floatdata)
{unsigned char datN[FloatNlenth];
unsigned char datDp[FloatDplenth];
unsigned char datNDp[FloatLenth];
unsigned char i,j;
unsigned long N;
unsigned long Dp;
N=(unsigned long)floatdata;
floatdata=floatdata-N; //取出小数部分
for(i=0;i<FloatNlenth;i++) //取出整数部分按由高到低的顺序存入datN[0]到datN[FloatNlenth-1]
{datN[FloatNlenth-i-1]=N%10;N=N/10;}
for(i=0;i<FloatDplenth;i++) //将小数数部分按由高到低的顺序存入datDp[0]到datDp[FloatDplenth-1]
{floatdata=10*floatdata;}
Dp=(unsigned long)floatdata; //Dp最多为9位
for(i=0;i<FloatDplenth;i++){datDp[FloatDplenth-i-1]=Dp%10;Dp=Dp/10;}
for(i=0;i<FloatNlenth;i++){datNDp[i]=datN[i];}//按整数 小数点 小数 的连接顺序存入datNDp数组中
datNDp[i]=10; i=i+1;
for(;i<FloatNlenth+FloatDplenth+1;i++)
{j=i-FloatNlenth-1;
datNDp[i]=datDp[j];
}
//在指定位置依次显示数字
j=0;
for(i=0;i<FloatNlenth-1;i++){if(datNDp[i]>0){j=i;break;}}
if(j>0)
{for(i=0;i<j;i++){datNDp[i]=11;}}
for(i=1;i<FloatLenth+1;i++){LCD_PutData(x,(i-1)/2+y,character+datNDp[i-1]);Delay1ms(1);}
cc=0;//cc=0初始化函数 LCD_PutData;
}
/**************************************************************************
------图形文本方式变换子程序-----------------------------------------------
***************************************************************************
说明:入口参数:液晶显示方式0:文本;1:图形
出口参数:无
***************************************************************************/
void LCD_ChangMode(unsigned char mode)
{
switch(mode)
{
case 0:
{
FUNCTION_BASIC();
LCD_DISP_ON();
break;
}
case 1:
{
LCD_CURSOR_OFF();
FUNCTION_EXTEND();
LCD_GRAPH_CLEAR();
LCD_GRAPH_ON();
break;
}
default:
break;
}
}
/************************************************************************
-------图形方式下坐标变换子程序------------------------------------------
*************************************************************************
说明:入口参数:坐标,坐标
出口参数:是否成功
************************************************************************/
unsigned char LCD_CoorShift(unsigned char x,unsigned char y)
{
x=x-1;y=y-1;
x=x>>4;
if(x<0||x>8) return ERR;
if(y>=0&&y<32)
{
LCD_WriteCommand(0x80+y);
LCD_WriteCommand(0x80+x);
}
else
{
LCD_WriteCommand(0x80+y-32);
LCD_WriteCommand(0x80+x+8);
}
}
code unsigned short Position[]={0x8000,0x4000,0x2000,0x1000,
0x0800,0x0400,0x0200,0x0100,
0x0080,0x0040,0x0020,0x0010,
0x0008,0x0004,0x0002,0x0001
};
/************************************************************************
-------图形方式下画点子程序------------------------------------------
*************************************************************************
说明:入口参数:坐标,坐标
出口参数:无
************************************************************************/
void LCD_PutPiex(unsigned char x,unsigned char y)
{unsigned short temp;
unsigned char temp_H,temp_L;
LCD_CoorShift(x,y);
x=x-1;
x=x%16;
temp=Position[x];
temp_L=temp&0x00ff;
temp_H=(temp>>8)&0x00ff;
// temp_H|=LCD_ReadData();
// temp_L|=LCD_ReadData();
LCD_WriteData(temp_H);
LCD_WriteData(temp_L);
}
/************************************************************************
-------图形方式下打印BMP图画子程序------------------------------------------
*************************************************************************
说明:入口参数:图画的点数组指针
出口参数:无
************************************************************************/
void LCD_PutBMP(unsigned char *ptr)
{unsigned char i,j;
for(i=0;i<0x20;i++)
{for(j=0;j<8;j++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(0x80+j);
LCD_WriteData(*ptr);
ptr++;
LCD_WriteData(*ptr);
ptr++;
}
}
for(i=0;i<0x20;i++)
{for(j=0;j<8;j++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(0x80+j+8);
LCD_WriteData(*ptr++);
LCD_WriteData(*ptr++);
}
}
}
/************************************************************************
-------图形方式下WINDOWS窗口子程序---------------------------------------
*************************************************************************
说明:入口参数:TITLE OF THE WINDOWS
出口参数:无
************************************************************************/
void WindowsFront(unsigned char *ptr)
{
LCD_CLEAR();
Delay1ms(100);
LCD_ChangMode(1);
LCD_PutBMP(WindowsFronts);
Delay1ms(100);
LCD_ChangMode(0);
LCD_CURSOR_OFF();
LCD_Printf(1,1,ptr);
}
/***********************************************************************
------变量值显示函数-------------------------
说明:将变量的值显示到指定的位置
入口参数:显示起始位置,要显示的变量
出口参数:无
***********************************************************************/
void LCD_Put_Varib(unsigned char x,unsigned char y, float variable)
{
unsigned char i;
unsigned char dispbuf[7]={0};
LCD_Goto ( (x-1), y );
if(variable<0)
{
variable=-variable;// print "-"
LCD_WriteData(45);
}
LCD_Goto(x,y);
dispbuf[0]=variable/10000; // divide the data into bit;
dispbuf[1]=(variable-dispbuf[0]*10000)/1000;
dispbuf[2]=(variable-dispbuf[0]*10000-dispbuf[1]*1000)/100;
dispbuf[3]=(variable-dispbuf[0]*10000-dispbuf[1]*1000-dispbuf[2]*100)/10;
dispbuf[4]=variable-dispbuf[0]*10000-dispbuf[1]*1000-dispbuf[2]*100-dispbuf[3]*10;
dispbuf[5]=(variable-dispbuf[0]*10000-dispbuf[1]*1000-dispbuf[2]*100-dispbuf[3]*10-dispbuf[4])/0.1;
dispbuf[6]=(variable-dispbuf[0]*10000-dispbuf[1]*1000-dispbuf[2]*100-dispbuf[3]*10-dispbuf[4]-dispbuf[5]*0.1)/0.01;
for(i=0;i<6;i++) // 找出第一个不是0的位数;
{
if(dispbuf[i]==0)
continue;
else
break;
}
for(;i<7;i++)
{
if(dispbuf[i]!=0)
{
dispbuf[i]=tbl[ dispbuf[i] ];
LCD_Goto(x, (y+i ));
LCD_WriteData(dispbuf[i]);
}
}
}
/***************************************************/
//---------------清屏子函数--------------------------
//入口参数:无
//出口参数:无
/***************************************************/
void LCD_Clear (void)
{
LCD_CLEAR();
Delay1ms(100);
}
/***************************************************/
//---------------关闭光标函数--------------------------
//入口参数:无
//出口参数:无
/***************************************************/
void LCD_CursorOff(void)
{
LCD_CURSOR_OFF();
}
/*
main()
{
unsigned char i;
// unsigned char hz[]="十八组”;
config();
LCD_Init();
LCD_ChangMode(1);
LCD_PutPiex(6,7);
// LCD_ChangMode(0);
// LCD_Printf(1,1,"lcd init");
// LCD_CURSOR_OFF();
// for(i=0;i<10;i++)
// Delay1ms(200);
// LCD_ChangMode(1);
// LCD_PutPiex(6,7);
// for(i=0;i<10;i++)
// Delay1ms(200);
LCD_ChangMode(0);
LCD_CURSOR_OFF();
LCD_PutHZ(1,1,"十" );
LCD_PutHZ(1,2,"八");
LCD_PutHZ(1,3,"组");
while(1);
while(1);
/*
unsigned char i;
unsigned char num[4];
num[2]='%';num[3]=0;
config();
LCD_Init();
LCD_ChangMode(1);
LCD_PutBMP(screen0);
Delay1ms(1);
LCD_ChangMode(0);
LCD_CURSOR_OFF();
LCD_Printf(4,1,"Copyright Team18");
for(i=0;i<5;i++)
Delay1ms(200);
LCD_CLEAR();
for(i=0;i<10;i++)
{LCD_Printf(1,1,"System Star...");
Delay1ms(100);
}
for(i=0;i<64;i++)
{LCD_Printf(2,1,"Hardware Init.");
switch(i%4)
{
case 0: {LCD_PutChar(2,8,'-');Delay1ms(80);break;}
case 1: {LCD_PutChar(2,8,92);Delay1ms(80);break;}
case 2: {LCD_PutChar(2,8,'|');Delay1ms(80);break;}
case 3: {LCD_PutChar(2,8,'/');Delay1ms(80);break;}
}
}
LCD_Printf(3,1,"C8051F020 CPU!");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_Printf(3,1,"OK!!! ");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_Printf(4,1,"SYSTEM CLOCK!!");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_Printf(4,1,"OK!!!8M ");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_CLEAR();
for(i=0;i<=100;i++)
{
LCD_Printf(1,1,"MEMORY TEST.");
Delay1ms(40);
num[0]=i/10+0x30;
num[1]=i%10+0x30;
LCD_Printf(1,7,num);
Delay1ms(10);
}
LCD_Printf(2,1,"Basic Mem 256B");
Delay1ms(100);
LCD_Printf(3,1,"Exten Mem 4096B");
Delay1ms(100);
LCD_Printf(4,1,"Flash Mem 64KB");
for(i=0;i<10;i++)
Delay1ms(150);
LCD_CLEAR();
for(i=0;i<5;i++)
{
Delay1ms(100);
LCD_Printf(1,1,"128*64 LCD..");
}
LCD_Printf(1,7,"OK");
for(i=0;i<10;i++)
Delay1ms(100);
LCD_Printf(2,1,"KEYBOARD TEST!");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_Printf(2,1,"ERR!!!!! ");
for(i=0;i<5;i++)
Delay1ms(100);
LCD_Printf(3,1,"SYSTEM TEST END");
LCD_Printf(4,1," WELCOME!!! ");
for(i=0;i<10;i++)
Delay1ms(200);
LCD_CLEAR();
Delay1ms(20);
LCD_ChangMode(1);
LCD_PutBMP(screen2);
Delay1ms(20);
LCD_ChangMode(0);
LCD_WriteCommand(0x0f);
LCD_Goto(4,2);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
WindowsFront(" 超声测距系统 ");
while(1)
{_nop_();}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -