求助1602显示屏显示位置乱跑的问题

2019-07-16 08:20发布

本帖最后由 Smilence_L 于 2016-12-22 22:37 编辑

新人没有积分悬赏, 我就想问问为什么1602显示屏显示内容会乱跑??用的是ARM7的LPC2103.
以下是代码:
#include"iolpc2103.h"
#define uchar unsigned char
#define BUSY 1<<11
#define RS 1<<12
#define RW 1<<13
#define EN 1<<15
uchar hello[]="Hello!";
void Delay10ms(uchar c)   
{
    uchar a, b;
    for (;c>0;c--)
{
  for (b=38;b>0;b--)
  {
   for (a=130;a>0;a--);
  }         
}      
}
void checkbusy()
{
IODIR=0x0000b000;
while(1)
{
  IOCLR|=RS;
  IOSET|=RW;
  IOSET|=EN;
  if(!(IOPIN & BUSY))
  break;
  else
  {  Delay10ms(1);
                  IOCLR|=EN;
                }
}
IODIR=0x0000bff0;
}
void lcd_wcom(uchar com)
{
checkbusy();
IOCLR|=RS;
IOCLR|=RW;
IOCLR|=0x00000ff0;
        Delay10ms(1);
IOSET|=(com<<4);
Delay10ms(1);
IOSET|=EN;
        Delay10ms(1);
IOCLR|=EN;
}
void lcd_wdat(uchar dat)
{
checkbusy();
IOSET|=RS;
IOCLR|=RW;
IOCLR|=0x00000ff0;
        Delay10ms(1);
IOSET|=(dat<<4);
Delay10ms(1);
IOSET|=EN;
        Delay10ms(1);
IOCLR|=EN;
}
void lcd_init()
{
lcd_wcom(0x38);
lcd_wcom(0x0c);
lcd_wcom(0x06);
}
void main()
{
  uchar i=0;
  PINSEL0=0x00000000;
  PINSEL1=0x00000000;
  IODIR=0x0000bff0;
  Delay10ms(220);
  lcd_init();
  Delay10ms(220);
  lcd_wcom(0x80);
  for(;i<6;i++)
  {
    lcd_wdat(hello);
    Delay10ms(220);
  }
  while(1);
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。