|
我要用Atmega16驱动一块240128的LCD,精心设计了一个月,用Protues模拟实现了所有要求的内用,今天开的板子下来了,正是等待丰收的时候。
我把程序下进去以后,却什么都显示不出来,线路我检查了,也没发现问题,搞得我快辞职了。今天,我来这里做最后一搏。我把程序浓缩了一下,显示结果就是在屏幕第一行第一列输出一个8,刚用protues模拟完,可以显示,可下到单片机里就不行,大家帮我看看哪里有错误?
#include <iom16v.h>
#include <macros.h>
#define cchar const unsigned char
//8X16字库
const unsigned char fons[16]={
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
};
#define LCD_RW PC2
#define LCD_RD PC3
#define LCD_CE PC0
#define LCD_CD PC1
#define LCD_RES PC4
#define LCD_CODE_P PORTC
#define LCD_RW_H LCD_CODE_P |= BIT(LCD_RW)
#define LCD_RW_L LCD_CODE_P &= ~BIT(LCD_RW)
#define LCD_RD_H LCD_CODE_P |= BIT(LCD_RD)
#define LCD_RD_L LCD_CODE_P &= ~BIT(LCD_RD)
#define LCD_CE_H LCD_CODE_P |= BIT(LCD_CE)
#define LCD_CE_L LCD_CODE_P &= ~BIT(LCD_CE)
#define LCD_CD_H LCD_CODE_P |= BIT(LCD_CD)
#define LCD_CD_L LCD_CODE_P &= ~BIT(LCD_CD)
#define LCD_RES_H LCD_CODE_P |= BIT(LCD_RES)
#define LCD_RES_L LCD_CODE_P &= ~BIT(LCD_RES)
#define LCD_DATA PINB
#define LCD_DDR DDRB
#define LCD_PORT PORTB
#define LCD_LEFT 0
#define LCD_TOP 0
#define LCD_RIGHT 239
#define LCD_BOTTOM 127
#define LCD_DELAY 0
#define uchar unsigned char
#define uint unsigned int
uint lcd_line=0;//全局变量,用于显示光标定位
//#define movepoint(n) lcd_line=n //细化地指定位置,n=0~30*128-1
/***********************************************************************************/
void lcd_delay(uint time)
{
uint i;
while(time--){
i=1000;
while(--i);
}
}
/***********************************************************************************/
void lcd_wd(uchar lcd_data)/*写数据*/
{
LCD_DDR = 0X00;
LCD_CODE_P &= ~(BIT(LCD_RD) | BIT(LCD_CE));
/*LCD_CODE_P = 0XF9;*/
while((LCD_DATA & 0X03) != 0X03);
LCD_RD_H;
LCD_CD_L;
LCD_RW_L;
/*LCD_CODE_P = 0XF2;*/
LCD_DDR = 0XFF;
LCD_PORT = lcd_data;
LCD_CODE_P |= (BIT(LCD_RW) | BIT(LCD_RD) | BIT(LCD_CD) | BIT(LCD_CE));
}
/***********************************************************************************/
void lcd_wc(uchar lcd_code)/*写命令*/
{
LCD_DDR = 0X00;
LCD_CODE_P &= ~(BIT(LCD_RD) | BIT(LCD_CE));
/*LCD_CODE_P = 0XF9;*/
while((LCD_DATA & 0X03) != 0X03);
LCD_RD_H;
LCD_RW_L;
/*LCD_CODE_P = 0XFA;*/
LCD_DDR = 0XFF;
LCD_PORT = lcd_code;
LCD_CODE_P |= (BIT(LCD_RW) | BIT(LCD_RD) | BIT(LCD_CD) | BIT(LCD_CE));
}
/***********************************************************************************/
void lcd_wc3(uchar lcd_code,uchar lcd_data1,uchar lcd_data2)
{
lcd_wd(lcd_data1);
lcd_wd(lcd_data2);
lcd_wc(lcd_code);
}
void port_init(void)
{
PORTD = 0xFF;
DDRD = 0xFF;
PORTB = 0x00;
DDRB = 0x00;
PORTA = 0x00;
DDRA = 0x00;
PORTC = 0xFF;
DDRC = 0xFF;
}
void lcd_init(void)
{
port_init();
LCD_RES_H;
LCD_RES_L;
lcd_delay(15);
LCD_RES_H;
lcd_wc(0x80); //设置显示模式为逻辑“或”模式
lcd_wc(0x98); //开显示
lcd_wc3(0x40,0,0); //设置文本显示区首地址
lcd_wc3(0x41,30,0); //设置文本显示区宽度
lcd_wc3(0x42,0,0); //设置图形显示区首地址
lcd_wc3(0x43,30,0); //设置图形显示区宽度
lcd_wc(0x98); //设置为图形显示
}
void lcd_print(uint x,uchar lcd_data)
{
//lcd_wc(0x98);
lcd_wc3(0x24,(uchar)x,(uchar)(x>>8));
lcd_wc(0xb0);
lcd_wd(lcd_data);
lcd_wc(0xb2);
}
/**********************************************************************************/
void put8x16(const uchar *s){//输出一个8x16点阵的数
uint temp;
uchar i;
temp=lcd_line;
for(i=0;i<16;i++,temp+=30)
lcd_print(temp,s);
}
void main(void)
{
lcd_init();
put8x16(fons);
}
我还伴随一个问题,就是插上LCD无法下载程序,拔了就可以下载
我听说LCD里要有驱动程序,有这么一回事吗?如果要加驱动怎么往LCD里下,另外到哪去弄LCD的驱动程序? |
|