本帖最后由 jianghuoo00 于 2011-11-5 10:18 编辑
使用icd2调试的,为什么LCD1602不显示?是程序的问题吗?单片机上没有晶振,开始调试时出现icd2x083的错误,后来请教他人加上了红字配置晶振,没有错误了,可是lcd为什么不显示呢?请教高手。感谢回答参考
LCD1602液晶中文资料[1].pdf
(299.6 KB)
#include<p33FJ64MC506.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_RS LATDbits.LATD5
#define LCD_RW LATDbits.LATD6
#define LCD_E LATDbits.LATD7
const uchar table1[]="LCD1602 CHECK OK";
const uchar table2[]="1602 OK";
void init();
void LCD_init();
void delay(uint x);
void LCD_wcom(uint com);
void LCD_wdat(uint data);
int main(void) //主函数
{
//Configure Oscillator to operate the device at 80Mhz
PLLFBD=41; // M=20
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
// Clock switching to incorporate PLL
__builtin_write_OSCCONH(0x01); //Initiate Clock Switch to Primary
//FRC with PLL (NOSC=0b001)
__builtin_write_OSCCONL(0x01); //Start clock switching
while (OSCCONbits.COSC != 0b001); // Wait for Clock switch to occur
uchar m,n;
init();
LCD_init();
LCD_wcom(0x80); //第一行显示
for(m=0;m<16;m++)
{
LCD_wdat(table1[m]);
delay(200);
}
LCD_wcom(0x80+0x40); //第二行显示
for(n=0;n<7;n++)
{
LCD_wdat(table2[n]);
delay(200);
}
while(1);
}
void init() //初始化
{
TRISD=0;
//LATD=0;
TRISE=0;
//LATE=0;
}
void LCD_init() //LCD初始化
{
delay(15);
LCD_wcom(0x38);
delay(5);
LCD_wcom(0x38);
delay(5);
LCD_wcom(0x38);
LCD_wcom(0x38);
LCD_wcom(0x08);
LCD_wcom(0x01);
LCD_wcom(0x06);
LCD_wcom(0x0c);
}
void delay(uint x) //延时
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void LCD_wcom(uint com) //1602写指令
{
LCD_RS=0;
LCD_RW=0;
LATE=com;
delay(5);
LCD_E=0;
delay(5);
LCD_E=1;
delay(5);
}
void LCD_wdat(uint dat) //写数据
{
LCD_RS=1;
LCD_RW=0;
LATE=dat;
delay(5);
LCD_E=0;
delay(5);
LCD_E=1;
delay(5);
} |