|
学ARM两个周,想吧以前51的程序移植过来,发现1602虽然能驱动显示,但是无法显示小写字母,送入的字符串明明是小写,显示的却是大写,并且符号类的字符包括空格都显示乱码先献上代码,希望有人帮我:
#include "config.h"
#define LCD_RS (1<<8)
#define LCD_RW (1<<9)
#define LCD_E (1<<10)
#define LCD_BUSY (1<<7)
void delay(uint32 n)
{
uint32 i;
for(i=0; i<n; i++);
}
void LCD_ChkBusy(void)
{
IO0DIR=0x000007ff;
IO0CLR=LCD_RS;
IO0SET=LCD_RW;
IO0SET=LCD_E;
while((IO0PIN&LCD_BUSY)!=0);
delay(400);
IO0CLR=LCD_E;
IO0DIR=0x000007ff;
}
void LCD_write_command(uint8 dat, uint8 busy)
{
if(busy) LCD_ChkBusy();
IO0CLR=LCD_E;
IO0CLR=LCD_RS;
IO0CLR=LCD_RW;
IO0CLR=0x000000ff;
IO0SET=dat;
IO0SET=LCD_E;
delay(400);
IO0CLR=LCD_E;
}
void LCD_write_data(uint8 dat)
{
// LCD_ChkBusy();
delay(400);
IO0CLR=LCD_E;
IO0SET=LCD_RS;
IO0CLR=LCD_RW;
IO0CLR=0x000000ff;
IO0SET=dat;
IO0SET=LCD_E;
delay(400);
IO0CLR=LCD_E;
}
void LCD_disp_string(uint8 x, uint8 y, uint8 *dat)
{
uint8 addr;
if(y==1)
addr=0x80+x;
else
addr=0xc0+x;
LCD_write_command(addr,0);
while(*dat)
{
LCD_write_data(*dat);
dat++;
}
}
void LCD_init()
{
delay(1000);
LCD_write_command(0x38,0);
delay(400);
LCD_write_command(0x38,0);
delay(400);
LCD_write_command(0x38,0);
delay(2800);
LCD_write_command(0x38,0);
delay(2800);
LCD_write_command(0x08,0);
delay(2800);
LCD_write_command(0x0c,0);//整体显示,关光标,不闪烁
delay(2800);
LCD_write_command(0x06,0);//设定输入方式,增量不移位
delay(2800);
LCD_write_command(0x01,0);//清除屏幕显示
delay(2800);
}
int main (void)
{
uint8 str[]="Hello World!";
PINSEL0=0x00000000;
IO0DIR=0x000007ff;
LCD_init();
while(1)
{
LCD_disp_string(0,1,str);
}
return 0;
}
补充一点,程序在proteus上仿真是通过了的,如下图:
(原文件名:ARM_LCD.png)
实际效果如下:
(原文件名:IMG0253A.jpg)
再补充一点:程序中如果加入了检测忙就无法显示 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|