本帖最后由 ys46501 于 2013-12-29 19:34 编辑
调试时修改显示控制位,LCD屏幕显示空白和显示所有字段都是正常的(说明写指令是正常的了)。但是字符却怎么也显示不出来,请大家帮忙看看什么地方搞错了?单片机16F1396配置位都是OK的,
#include <htc.h>
#define uint unsigned int
#define uchar unsigned char
__CONFIG(0x09c4); //FCMEN=0;IESO=0;CLKOUTEN=1;BOREN1=0;BOREN0=0;CPD=1;CP=1
//MCLRE=1; PWRTE=0;WDTE1=0;WDTE0=0;FOSC2=1;FOSC1=0;FOSC0=0
__CONFIG(0x1033); //禁止DEBUG;禁止4×PLL;禁止闪存保护,VCAP引脚无电容。
#define LCD_RST RB0 //定义复位端。
#define LCD_CE RB1 //定义片选端,低电平有效。
#define LCD_DC RB2 //数据/指令端,高电平写数据,低电平写指令。
#define LCD_DIN RB3 //串行数据线
#define LCD_CLK RB4 //串行时钟线
void MCU_init();
void LCD5110_init();
void LCD5110_RAM_clr();
void LCD5110_write_byte(uchar wbyte, uchar comd);
void MCU_init() //单片机IO初始化
{
OSCTUNE=0X00; //配置内部振荡器以厂家校准后的频率运行
OSCCON=0X68; //配置内部时钟为4M,禁止4×PLL
TRISB=0b00000000;
PORTB=0b00000000;
}
void LCD5110_write_byte(uchar wbyte, uchar comd) //LCD写入1字节。
{
uchar i;
LCD_CE = 0; //片选使能
LCD_DC = comd; //1=数据 //0=指令
for(i = 0; i<8; i++) //8位数据, 先高后低
{
LCD_CLK = 0;
if(wbyte & 0x80) LCD_DIN = 1; //写入1
else LCD_DIN = 0; //写入1
wbyte=wbyte<<1; //移位(延时)
NOP();NOP();
LCD_CLK = 1; //上升沿写入
NOP();NOP();
}
LCD_CE = 1; //片选禁止
}
void LCD5110_init() //LCD初始化
{
uchar i;
LCD_RST=0;
for(i=100;i;i--) LCD_RST=1;
LCD_CE = 1; //LCD复位。
LCD5110_write_byte(0x21,0); //掉电模式、水平寻址、扩展指令
LCD5110_write_byte(0x98,0); //设置VOP
LCD5110_write_byte(0x20,0); //显示模式, 水平寻址, 常规指令
LCD5110_write_byte(0x0C,0); //显示模式为普通
LCD5110_write_byte(0x40,0); //Y起始页地址0
LCD5110_write_byte(0x80,0); //X起始列地址0
LCD5110_RAM_clr(); //清楚显示RAM。
}
void main()
{
MCU_init(); //IO初始化。
LCD5110_init(); //初始化5110
while(1)
{
LCD5110_write_byte(0xFF, 1);
LCD5110_write_byte(0x00, 1);
LCD5110_write_byte(0xFF, 1);
LCD5110_write_byte(0x00, 1);
LCD5110_write_byte(0xFF, 1);
LCD5110_write_byte(0x00, 1);
LCD5110_write_byte(0xFF, 1);
LCD5110_write_byte(0x00, 1);
}
}
void LCD5110_RAM_clr() //清空LCD显示内存
{
uint t;
LCD5110_write_byte(0x40,0); //Y起始页地址0
LCD5110_write_byte(0x80,0); //X起始列地址0
for(t = 504; t; t--)
LCD5110_write_byte(0x00,1);
LCD5110_write_byte(0x40,0); //Y起始页地址0
LCD5110_write_byte(0x80,0); //X起始列地址0
} |