在线时间0 小时
UID98929
注册时间2008-12-16
NXP金币0
该用户从未签到
新手上路

- 积分
- 20
- 最后登录
- 1970-1-1
|
想請教如下這段程序 在 8051上是可以正常顯示數值的,但轉換到 Freescale MC9s08SH4 完全就沒有顯示,是不是有哪個寄存器的初始給錯了,能否請前輩們幫忙看看,謝謝! I/O定義,PORTB 為 data , PORTA1~3 分別為 EN,RW,RS
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#define LCD_RS PTAD_PTAD3
#define LCD_RW PTAD_PTAD2
#define LCD_EN PTAD_PTAD1
#define LCD_Data PTBD
char Table1[] = "12345678901234567890"; //第一行列表字元
char Table2[] = "ABCDEFGHIJKLMNOPQRST"; //第二行列表字元
void HWinit(void);
void Reset_LCD(void);
void Delay(unsigned int dly);
void LCD_Cmd(unsigned char comm);
void Send_Data(char Data);
void main(void)
{
int i;
P1=0;
HWinit();
Reset_LCD(); //重置及清除LCD
Delay(200);
LCD_Cmd(0x80); //游標由第一行開始顯示
for(i=0 ; i< 20 ; i++)
Send_Data(Table1); //讀取列表20字送到LCD顯示
LCD_Cmd(0xC0); //游標由第二行開始顯示
for(i=0 ; i< 20 ; i++)
Send_Data(Table2); //讀取列表20字送到LCD顯示
loop:
LCD_Cmd(0x08); Delay(60000);
LCD_Cmd(0x0c); Delay(60000); //D=1開啟顯示器
goto loop;
}
void HWinit(void)
{
ICSC1= 0b00000100;
ICSC2= 0b11000000;
SOPT1 = 0b00000000; // BDM BIT1 OFF=0,ON=1
//SOPT1 = 0b00000011; // For Debug
//GPIO_initial
PTAD = 0b00000000;
PTADD = 0b00001110;
PTADS = 0b00000000;
PTAPE = 0b00110000;
PTASE = 0b00000000;
PTBD = 0b00000000;
PTBDD = 0b11111111;
PTBDS = 0b00000000;
PTBPE = 0b00000000;
PTBSE = 0b00000000;
}
void Reset_LCD(void) //LCD的啟始程式
{
LCD_Cmd(0x38); //DL=1:8bit傳輸,N=1:顯示2行,F=0:5*7字型
LCD_Cmd(0x0c); //D=1:顯示幕ON,C=0:不顯示游標,B=0:游標不閃爍
LCD_Cmd(0x06); //I/D=1:顯示完游標右移,S=0:游標移位禁能
LCD_Cmd(0x01); //清除顯示幕
LCD_Cmd(0x02); //游標回原位
}
void Send_Data(char Data) //傳送資料到LCD
{
LCD_Data=Data; //資料送到BUS
LCD_RS=1;
LCD_RW=0;
LCD_EN=1; //資料到LCD內
Delay(60); //延時片刻(可不要)
LCD_EN=0; //禁能LCD
}
void LCD_Cmd(byte comm) //傳送命令到LCD
{
LCD_Data=comm; //命令送到BUS
LCD_RS=0;
LCD_RW=0;
LCD_EN=1; //命令到LCD內
Delay(60); //延時片刻(可不要)
LCD_EN=0; //禁能LCD
}
void Delay(unsigned int dly) //延時函數
{
while(dly > 0)
dly --;
}
|
|