weisuhong2006 发表于 2010-3-31 15:52:33

液晶显示问题二

本人写的一个测试程序,烧进去后运行不了,不知何因,还希望高手指点
ATmega128并行控制带字库的12864程序
// 液晶硬件连接:   
//                                1.PIN1 --- GND        ---->GND
//                                2.PIN2 --- VCC        ---->5v
//                                3.PIN3 --- V0        ---->3.2v
//                                4.PIN4 --- RS        ---->PORTE.3
//                                5.PIN5 --- R/W        ---->PORTE.4
//                                6.PIN6 --- E        ---->PORTE.5
//                                7.PIN7 --- DB0---->PORTB.0
//                                8.PIN8 --- DB1---->PORTB.1
//                                9.PIN9 --- DB2---->PORTB.2
//                                10.PIN10 --- DB3---->PORTB.3
//                                11.PIN11 --- DB4---->PORTB.4
//                                12.PIN12 --- DB5---->PORTB.5
//                                13.PIN13 --- DB6---->PORTB.6
//                                14.PIN14 --- DB7---->PORTB.7
//                                15.PIN15 --- PSB---->1,并行
//                                16.PIN16 --- NC
//                                17.PIN17 --- RST---->5v,no reset
//                                18PIN18 --- NC
//                                19PIN19 --- VCC   ---->5v
//                                20.PIN20 --- GND---->GND
#include <iom128v.h>
#include<macros.h>
//==============================================================================================
#define BIT(x)                   (1 << (x))
#define SETBIT(x, y)              (x |= y)
#define CLEARBIT(x, y)            (x &= ~y)
#define CHECKBIT(x, y)            (x & y)
#define BIT5 0x20
#define BIT4 0x10
#define BIT3 0x08
#define LCD_RS      BIT3
#define LCD_RW      BIT4
#define LCD_EN      BIT5
/*****LCD接口定义*****/
#define LCD_RSH SETBIT(PORTE, LCD_RS) // 1:输入数据   
#define LCD_RSL CLEARBIT(PORTE, LCD_RS) //0:输入命令
#define LCD_RWH SETBIT(PORTE,LCD_RW ) //1:读数据   
#define LCD_RWL CLEARBIT(PORTE,LCD_RW ) //0:写数据   
#define LCD_ENHSETBIT(PORTE,LCD_EN )   
#define LCD_ENLCLEARBIT(PORTE,LCD_EN )   
/*****汉字地址表*****/
unsigned char addr_tab[]={   //便于根据汉字坐标求出地址
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行汉字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行汉字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行汉字位置
};
/*****n(ms)延时子程序*****/
void delayms(unsigned int t)    //约延时n(ms)
{
unsigned int i;
while(t--)
    {
       for(i=0;i<125;i++);
    }
}
/*****等待LCD忙*****/
void WaitBusy(void)      //延时一小段时间,等待LCD空闲
{
unsigned char i=5;
    while(i--);
}

/*****写指令代码*****/
void Lcd_WriteCmd(unsigned char cmdcode)
{
    LCD_RSL;
    LCD_RWL;
    LCD_ENH;
    WaitBusy();
    PORTB=cmdcode;
    LCD_ENL;
}
/*****写数据*****/
void Lcd_WriteData(unsigned char dispdata)
{
    LCD_RSH;
    LCD_RWL;
    LCD_ENH;
    WaitBusy();
    PORTB=dispdata;
    LCD_ENH;
}
/*****初始化LCD*****/
void Lcd_Init()
{
delayms(50);
    Lcd_WriteCmd(0x01);          //清除显示,并且设定地址指针为00H
delayms(1);
    Lcd_WriteCmd(0x30);      //选择基本指令集
delayms(1);
    Lcd_WriteCmd(0x30);          //选择8bit数据流
delayms(1);
    Lcd_WriteCmd(0x0c);          //开显示(无游标、不反白)
delayms(20);
}
/*****显示汉字*****/
void hanzi_Disp(unsigned char x,unsigned char y,unsigned char *s)
{          //x、y为汉字坐标
Lcd_WriteCmd(addr_tab);//写地址
while(*s>0)
    {
Lcd_WriteData(*s);    //写数据
s++;   
    }
}
/*****主函数*****/
void main(void)
{
Lcd_Init();
DDRB=0xFF;
PORTC=0x00;
while(1)
{
Lcd_Init();
hanzi_Disp(0,0,"ST7920型液晶模块");
hanzi_Disp(1,1,"并行测试程序");
hanzi_Disp(3,3,"");
delayms(2000);
}
}
页: [1]
查看完整版本: 液晶显示问题二