最近一直在调12864,但是始终无法显示任何东西。希望各位能帮帮忙,纠结很久了。控制芯片MC9S12XS128。 ps:程序并非原创 只是自己稍作修改。
#define LCD_RS PTT_PTT0 #define LCD_RW PTT_PTT1
#define LCD_E PTT_PTT2
uchar Tab1[]={"hello world!"};
uchar Tab2[]={"哈哈哈"};
void delay_10us(long m)
{
while(m--);
}
void delay_1ms(unsigned int t)
{
unsigned int i;
for(i=0;i<t;i++)
delay_10us(102);
}
void Write_Data(unsigned char dat)
{
DDRA = 0xff;
DDRT = 0xff;
DisableInterrupts;
delay_1ms(10);
LCD_RS = 1;
LCD_RW = 0;
delay_10us(5);
LCD_E = 0;
LCD_E = 1;
delay_10us(5);
PORTA = dat;
delay_10us(0);
LCD_E = 0;
LCD_RS = 0;
LCD_RW = 1;
EnableInterrupts;
}
void Write_Command(unsigned char dat)
{
DDRT = 0xff;
DDRA = 0xff;
DisableInterrupts;
delay_1ms(10);
LCD_RS = 0;
LCD_RW = 0;
delay_10us(5);
LCD_E = 0;
LCD_E = 1;
delay_10us(5);
PORTA = dat;
delay_10us(5);
LCD_E = 0;
LCD_RS = 1;
LCD_RW = 1;
EnableInterrupts;
}
void Write_String(unsigned char *p)
{
char cnt=0;
while(*(p+cnt)!='\0')
{
Write_Data(*(p+cnt));
delay_1ms(10);
cnt++;
}
}
void Set_Position(unsigned char x,unsigned char y)
{
unsigned char p;
switch(x%4)
{
case 0:p = 0x80; break;
case 1:p = 0x90; break;
case 2:p = 0x88; break;
case 3:p = 0x98; break;
}
p += y;
Write_Command(p);
}
void LCD_Init()
{
Write_Command(0x30);
delay_1ms(10);
Write_Command(0x0c);
delay_1ms(10);
Write_Command(0x14);
delay_1ms(10);
Write_Command(0x01);
delay_1ms(10);
}
void main(void)
{
PTT_PTT3 = 1;
EnableInterrupts;
delay_1ms(100);
LCD_Init();
Set_Position(0,0);
delay_1ms(10);
Write_String(Tab1);
Set_Position(2,0);
Write_String(Tab2);
for(;;) {}
}
|