再次把程序贴出来,请高手帮忙分析分析。谢谢!
void SetDBDirection (unsigned char direction)
{
if (direction == 0xff) //input
{
TRISA0 = 1;//RA0 is configed as output,MCU_LCD_DB3
PCFG0 = 1;
TRISA1 = 1;//RA1 is configed as output,MCU_LCD_DB4
PCFG1 = 1;
TRISA2 = 1;//RA2 is configed as output,MCU_LCD_DB5
PCFG2 = 1;
TRISA3 = 1;//RA3 is is configed as output,MCU_LCD_DB6
PCFG3 = 1;
//TRISA5 = 1;//RA5 is is configed as output,MCU_LCD_DB7
//PCFG4 = 1;
//LATB = 0xff;
//TRISB0 = 1;//RB0 is configed as output,MCU_LCD_DB2
//PCFG12 = 1;
//TRISB1 = 1;//RB1 is configed as output,MCU_LCD_DB1
//PCFG10 = 1;
//TRISB2 = 1;//RB2 is configed as output,MCU_LCD_DB0
//PCFG8 = 1;
}
else if (direction == 0x00) //output
{
TRISA0 = 0;//RA0 is configed as output,MCU_LCD_DB3
PCFG0 = 1;
TRISA1 = 0;//RA1 is configed as output,MCU_LCD_DB4
PCFG1 = 1;
TRISA2 = 0;//RA2 is configed as output,MCU_LCD_DB5
PCFG2 = 1;
TRISA3 = 0;//RA3 is is configed as output,MCU_LCD_DB6
PCFG3 = 1;
//TRISA5 = 0;//RA5 is is configed as output,MCU_LCD_DB7
//PCFG4 = 1;
//LATB = 0xff;
//TRISB0 = 0;//RB0 is configed as output,MCU_LCD_DB2
//PCFG12 = 1;
//TRISB1 = 0;//RB1 is configed as output,MCU_LCD_DB1
//PCFG10 = 1;
//TRISB2 = 0;//RB2 is configed as output,MCU_LCD_DB0
//PCFG8 = 1;
}
}
//-------------------------------------------------------------------------------
//lcdwc(unsigned char c).
//function:write instruction
//-------------------------------------------------------------------------------
void lcdwc (unsigned char c)
{
//lcdwaitidle();
SetDBDirection (0x00);
LCD_RS = 0;//RS=0
LCD_RW = 0;//RW=0
LCD_EN = 0;//E=0
DBHighByte = c/16;
DBLowByte = c%16;
PORTA &= 0xf0;//
PORTA |= DBHighByte;
LCD_EN = 1;//E=1
NOP();
NOP();
LCD_EN = 0;//E=0
PORTA &= 0xf0;//
PORTA |= DBLowByte;
LCD_EN = 1;//E=1
NOP();
NOP();
LCD_EN = 0;
delay5ms();
}
//-------------------------------------------------------------------------------
//lcdwc8(unsigned char c).
//function:write instruction
//-------------------------------------------------------------------------------
void lcdwc8 (unsigned char c)
{
//lcdwaitidle();
SetDBDirection (0x00);
LCD_RS = 0;//RS=0
LCD_RW = 0;//RW=0
LCD_EN = 0;//E=0
DBHighByte = c/16;
DBLowByte = c%16;
PORTA &= 0xf0;//
PORTA = DBHighByte;
//NOP();
//NOP();
//PORTA |= DBLowByte;
NOP();
NOP();
LCD_EN = 1;//E=1
NOP();
NOP();
LCD_EN = 0;
delay5ms();
}
//-------------------------------------------------------------------------------
//void lcdreset(void)
//function:LCD controller init
//-------------------------------------------------------------------------------
void lcdreset (void) //LCD controller init
{
delay300ms();
delay300ms();
delay300ms();
newline();
puts ("initializing LCD controller...", 0);
//lcdwc (0x30);//function set:8 bit interface,basic instruction
lcdwc8 (0x30);//function set: 8 bit interface,basic instruction
lcdwc8 (0x30);//function set: 8 bit interface,basic instruction
lcdwc (0x20);//function set: 4 bit interface,basic instruction
delay5ms();
//lcdwc (0x30);//function set:8 bit interface,basic instruction
lcdwc (0x20);//function set:4 bit interface,basic instruction
delay5ms();
lcdwc (0x06);//I/D=1,cursor move right,AC increase by 1;S=0,no toggle
delay5ms();
lcdwc (0x0f);//D=1,display on;C=1,cursor on;B=0,blink off
//lcdon();//D=1,display on;C=1,cursor on;B=0,blink off
delay5ms();
//lcdon();//D=1,display on;C=0,cursor off;B=0,blink off
lcdwc (0x01);//clear
delay5ms();
delay5ms();
lcdwc (0x02);//set cursor to home
delay5ms();
lcdwc (0x80);//set DDRAM address as 0x00
//delay5ms();
//lcdwd ('a');
//lcdwd ('a');
//delay5ms();
puts ("done!", 0);
} |