#include "SM5964.h" //芯片设备
#include "TypeDef.h"
#include "Delay.h"
#include "Lcd.h"
#include "ResSrc.h" //资源文件
#define LCD_CMD 0
#define LCD_DATA 1
//sbit LCS_CS =P1^0; //;片选,低有效,默认有效
sbit LCD_RS =P1^0; //;数据指令选择,0->写命令 ;1->写数据
//sbit LCD_LED =P1^1; //;背光控制
sbit LCD_RES =P1^2; //;复位控制,低复位
sbit LCD_SCL =P1^6; //;时钟位
sbit LCD_SDA =P1^7; //;数据位
//数据指令选择,0->写命令 ;1->写数据
void LCDWriteByte(u1 u1method,u1 u1byte)
{
u1 data u1i;
if (u1method){
LCD_RS = 1; //LCD_RS=1
}else{
LCD_RS = 0; //LCD_RS=0
}
for (u1i=0;u1i<8;u1i++)
{
if(u1byte&0x80)
{
LCD_SDA=1; //LCD_SDA=1;
}else{
LCD_SDA=0; //LCD_SDA=0;
}
LCD_SCL=0;
LCD_SCL=1;
u1byte<<=1;
}
LCD_SDA=1;
LCD_SCL=1;
}
//液晶初始化
const u1 code LCDINITCODE[18] = {
0xE2, //;Internal Soft Reset
0xE3, //;NOP Command for non-operation
//
0xA0, //;ADC select ,select SEG output direction
//;0xa0-> normal direction
//;0xa1-> reverse direction
0xC8, //;SHL select,select COM output direction
//;0xc0-> normal direction;
//;0xc8-> reverse direction
0xA2, //;LCD bias select,
//;0xa2->1/9 bias
//;0xa3->1/7bias
//;Power control
0x2C, //;VC=1
0x2E, //;VR=1
0x2F, //;VF=1
// 0x29, //;VC=0,VR=0,VF=1,接外部电源到V0
//
0x25, //;Regulator resistor select
//;V0=9V
//;R2~R0=101 ——> (1+Ra/Rb)=5.5
0x81, //;set reference voltage
0x19, //;SV5~SV0=10 0011
0x40, //;Initial display line 0
0xB0, //;set page address 0000
0x10, //;set column address MSB 0000
0x00, //;set column address LSB 0000
0xA6, //;set lcd display normal A6/ reverse A7
0xA4, //;display all points
0xAF //;0xAE-> DISPLAY OFF
//;0xAF-> DISPLAY ON
};
#if 0
//清屏处理
void LCDClrScreen(bit bBlack)
//void LCDClearScreen(void)
{
u1 data u1i,u1j;
for(u1i=0;u1i<4;u1i++)
{
LCDWriteByte(LCD_CMD, (unsigned char)(0xB0+u1i)); //set page address
LCDWriteByte(LCD_CMD, 0x10); //set seg address
LCDWriteByte(LCD_CMD, 0x00);
for(u1j=0;u1j<128;u1j++){
if (bBlack){
LCDWriteByte(LCD_DATA, 0xFF);
}else{
LCDWriteByte(LCD_DATA, 0x00);
}
}
}
}
#else
//清屏处理
void LCDClrScreen(bit bBlack)
//void LCDClearScreen(void)
{
u1 data u1i,u1j;
u1 data u1Data;
if (bBlack) {
u1Data = 0xFF;
} else {
u1Data = 0x00;
}
for(u1i=0;u1i<4;u1i++)
{
LCDWriteByte(LCD_CMD, (unsigned char)(0xB0+u1i)); //set page address
LCDWriteByte(LCD_CMD, 0x10); //set seg address
LCDWriteByte(LCD_CMD, 0x00);
for(u1j=0;u1j<128;u1j++){
LCDWriteByte(LCD_DATA, u1Data);
//if (bBlack){
// LCDWriteByte(LCD_DATA, 0xFF);
//}else{
// LCDWriteByte(LCD_DATA, 0x00);
//}
}
}
}
#endif /*hsf:100202*/
//液晶初始化
void LCDInit(void)
{
u1 u1i;
//复位
LCD_RES=0; //REST=0,CS=0;
LCD_SDA=1;
LCD_SCL=1; //SDA=1,SCL=1
Delay10mS();
LCD_RES=1;
LCD_RS=1;
Delay10mS();
//初始化指令
for (u1i=0;u1i<sizeof(LCDINITCODE);u1i++)
LCDWriteByte(LCD_CMD,LCDINITCODE[u1i]);
}
//行清除
void LCDClearLine(u1 u1Line)
{
u1 data u1i;
if (u1Line > 3)
return;
LCDWriteByte(LCD_CMD, (unsigned char)(0xB0+u1Line)); //set page address
LCDWriteByte(LCD_CMD, 0x10); //set seg address
LCDWriteByte(LCD_CMD, 0x00);
for(u1i=0;u1i<128;u1i++)
LCDWriteByte(LCD_DATA, 0x00);
}
//设置对比度 0 ~ 63
void SetLCDContrast(u1 u1Value)
{
//-----------------
u1Value &= 0x3F;
LCDWriteByte(LCD_CMD, 0x81); //set page address
LCDWriteByte(LCD_CMD, u1Value);
}
//写
void LCDWrite(u1 u1x,u1 u1y, u1 u1Size, u1 * pu1Buf)
{
u1 u1Ins;
//设置地址
u1Ins = (u1)(u1y>>3);
LCDWriteByte(LCD_CMD, 0xB0+u1Ins); //set page address
u1Ins = (u1x >> 4) & 0x0F;
LCDWriteByte(LCD_CMD, 0x10+u1Ins); //set seg address MSB
u1Ins = u1x & 0x0F ;
LCDWriteByte(LCD_CMD, 0x00+u1Ins); // LSB
//显示数据
for(u1Ins=0;u1Ins<u1Size;u1Ins++)
LCDWriteByte(LCD_DATA, pu1Buf[u1Ins]);
}
评论0