📄 lcd1602.c
字号:
/*************************************
功能:采用ARM7的GPIO口控制LCD1602显示
目的:彻底玩透ARM7的GPIO口
接线:P0.0~P0.7接D0~D7
P0.8~P0.10接RS,RW,E
作者:刘启明
更新:2007年1月20日
*************************************/
#include "IOLPC2132.h"
#include "string.h"
#define RS 0x00000100 //P0.8接RS
#define RW 0x00000200 //P0.9接RW
#define E 0x00000400 //P0.10接E
void Delayms(unsigned int count)
{
unsigned int i;
for(i=0;i<count;i++);
}
void WriteCommand(unsigned char Com)
{
IO0CLR=E;
IO0CLR=RS;IO0CLR=RW;IO0SET=E;
IO0CLR=0x000000ff;IO0SET=Com;
IO0CLR=E; IO0CLR=RS;IO0CLR=RW;
}
void WriteData(unsigned char Dat)
{
IO0CLR=E;
IO0SET=RS; IO0CLR=RW;IO0SET=E;
IO0CLR=0x000000ff;IO0SET=Dat;
IO0CLR=E; IO0CLR=RS;IO0CLR=RW;
}
void Init()
{
Delayms(1000);
WriteCommand(0x38);
Delayms(400);
WriteCommand(0x38);
Delayms(400);
WriteCommand(0x38);
Delayms(2800);
WriteCommand(0x38);
Delayms(2800);
WriteCommand(0x08);
Delayms(2800);
WriteCommand(0x01);
Delayms(2800);
WriteCommand(0x06);
Delayms(2800);
WriteCommand(0x0C);
}
void Show_Text(char *Text,char row)
{
unsigned char i;
if(row==0)
{
WriteCommand(0x80);
Delayms(2800);
for(i=0;i<strlen(Text);i++)
{
WriteData(Text[i]);
Delayms(2800);
}
}
else
{
WriteCommand(0xC0);
Delayms(2800);
for(i=0;i<strlen(Text);i++)
{
WriteData(Text[i]);
Delayms(2800);
}
}
}
void main()
{
PINSEL0=0x00000000;
IO0DIR =0xffffffff;
char Text1[16]="<NIOS II on DE2>";
char Text2[16]="Nice to See You!";
Init();
while(1)
{
Show_Text(Text1,0);
Show_Text(Text2,1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -