本帖最后由 liuxiaolinsara 于 2012-7-20 16:27 编辑
我用的是ST7565P驱动的LCD12864,现在用程序控制显示信息,但是屏幕上什么都不显示,求帮助!
程序代码如下:
#include"reg52.h"
#include "intrins.h"
#define NOP _nop_()
#define uchar unsigned char
#define uint unsigned int
sfr P1M0 = 0x92;
sfr P1M1 = 0x91;
sfr P2M0 = 0x96;
sfr P2M1 = 0x95;
uchar code dig[]={"0123456789"};
uchar code dig2[]={0,1,2,3,':'};
sbit LCD_SI = P1^5;
sbit LCD_SCL = P1^7;
sbit LCD_A0 = P2^4;
sbit LCD_CS = P1^4;
/**************** 你(0) 好(1) ************************************/
unsigned char code dat[]={
0x90,0x00,0x90,0x01,0x88,0x20,0xC8,0x7F,0x44,0x20,0x2C,0x12,0x16,0x02,0x45,0x0A,
0xC4,0x12,0x44,0x12,0x24,0x22,0x24,0x62,0x14,0x22,0x84,0x02,0x04,0x01,0x00,0x00,/*"你",0*/
0x08,0x00,0x88,0x3F,0x08,0x10,0x08,0x08,0x3F,0x04,0x24,0x04,0x24,0x04,0xE4,0x7F,
0x22,0x04,0x26,0x04,0x18,0x04,0x10,0x04,0x28,0x04,0x64,0x04,0x22,0x05,0x01,0x02/*"好",1*/
};
/*******************************延时子程序**********************************/
void Delay(int n)
{
unsigned char i;
while(n--)
for(i=0;i<250;i++);
}
/*************************************************************
** 函数名称:Data_Send()
** 入口参数:需要发送的数据mydata
** 函数说明:串行模式发送数据
**********************************************************/
void Data_Send(unsigned char mydata)
{
unsigned int i;
unsigned char s,temp;
LCD_SCL=0;
LCD_CS=0;
s=mydata;
for(i=8;i>0;i--)
{
LCD_SCL=0;
NOP;
NOP;
temp=s&0x80;
if(temp) LCD_SI=1;
else LCD_SI=0;
LCD_SCL=1;
s=s<<1;
}
// LCD_CS=1;
}
//========================================================================
// 描述: 写一个字节的数据至LCD中的控制寄存器当中
// 参数: Command 写入的数据,低八位有效(byte)
//========================================================================
void Write_Cmd(unsigned char cmd)
{
LCD_A0 = 0;
LCD_CS = 0;
Data_Send(cmd);
}
//========================================================================
// 描述: 写一个字节的显示数据至LCD中的显示缓冲RAM当中
// 参数: dat 写入的数据
//========================================================================
void Write_Data(unsigned char dat)
{
LCD_A0 = 1;
LCD_CS = 0;
Data_Send(dat);
}
//========================================================
//页设置子函数
//========================================================
void Set_page(unsigned char a)
{
a|=0xb0;
Write_Cmd(a);
}
//========================================================
//列设置子函数
//========================================================
void Set_addr(unsigned char addr)
{
unsigned char a,b;
a=addr;
a&=0x0f;
b=addr>>4;
b|=0x10;
Write_Cmd(a);
Write_Cmd(b);
}
/**********************************************************
**显示
**参数入口Display(汉字数组)
*************************************************************/
void Display(uchar *p)
{
unsigned char column;
unsigned char page;
for(page=0xB0;page<0xB9;page++) //写地址共8页
{
Write_Cmd(page);
Write_Cmd(0x10); //列地址,高低字节两次写入
Write_Cmd(0x00);
for(column=0;column<128;column++) //写128列
{
Write_Data(*p++);
}
}
}
//========================================================
//初始化LCD
//========================================================
void Init_LCD(void)
{
LCD_SI =0x00; //端口初始化
Delay(10000);
Write_Cmd(0xaf); //LCD_ON /*显示开关指令 Display ON*/
// Write_Cmd(0x60);
Write_Cmd(0xa0); //Segment方向选择(0xa1反向)
Write_Cmd(0xa6); //正常显示控制指令,RAM中数据不变(0xa7)
Write_Cmd(0xa4); //所有的点正常显示
Write_Cmd(0xa2); //偏压设置 1/9偏压
Write_Cmd(0xc8); //Com 扫描方式设置(0xc8反向)
Write_Cmd(0x2f); //上电模式
Write_Cmd(0x24); //内部电阻模式的设置
Write_Cmd(0x81); //电量设置模式(屏幕亮度)
Write_Cmd(0x24); //指令数据,电量值
Write_Cmd(0xf8); // 进入倍压比的设置模式
Write_Cmd(0x00); // 倍压比设置为4倍
}
void InitUART(void)
{
TMOD = 0x20;
TH1 = 0xFA; //晶振22.1184MHZ,波特率9600
TL1 = 0xFA;
SCON = 0x50;
PCON = 0x00;
EA = 0;
ES = 0;
TR1 = 1;
}
void main()
{
P1M0 = 0xFF;
P1M1 = 0x00;
P2M0 = 0xFF;
P2M1 = 0x00;
InitUART();
Delay(10000);
Init_LCD();
while(1)
{
Display(dat);// 在第二行第一列显示"你好"
}
} |