S6B0724芯片的LCD128*64的AVR128驱动程序

标签:S6B0724AVR128
分享到:

以下是用S6B0724做驱动芯片的128*64的AVR128驱动程序,已经测试通过。请大家放心使用,呵呵!
/*************************************************************/

#i nclude <avr/io.h>
/*************************************************************/
/* 宏定义替换 */
/*************************************************************/
#define uchar unsigned char //宏定义替换
#define uint unsigned int //宏定义替换
#define ulong unsigned long //宏定义替换
/*************************************************************/
/* 接口定义替换 */
/*************************************************************/
//#define LCM_DB P0 //数据总线定义
//sbit LCM_nRST = P1^0; //低电平复位
//sbit LCM_nCS = P2^7; //片选A15
//sbit LCM_DnI = P2^0; //数据与指令的接口A8
//sbit LCM_nWR = P3^6; //写选通线
//sbit LCM_nRD = P3^7; //读选通线
#define LCM_DB PORTA //数据总线定义
#define LCM_nRST PC7 //低电平复位
#define LCM_nCS PC6 //片选A15
#define LCM_DnI PC5 //数据与指令的接口A8
#define LCM_nWR PC4 //写选通线
#define LCM_nRD PC3 //读选通线
#define SETBIT(x,y) (x |= (1<<y)) // Set bit y in byte x
#define CLRBIT(x,y) (x &= (~(1<<y)))// Clear bit y in byte x
#define CHKBIT(x,y) (x & (1<<y)) // Check bit y in byte x
/*************************************************************/
/* 字模数组 */
/*************************************************************/
/*-- 调入了一幅图像:D:\LCD\商行.bmp --*/
/*-- 宽度x高度=128x64 纵向倒序 --*/
uchar zimo[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x40,0x40,0x40,
0x40,0x40,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x80,0x80,0x80,0xC0,0x80,0x80,
0x80,0x80,0x00,0x00,0x40,0x80,0x00,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,
0x00,0x40,0x80,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x97,0x5D,0x35,0x95,
0x75,0x15,0x17,0xF0,0x00,0x00,0x22,0x12,0xFF,0x0A,0x00,0xAA,0x2A,0xFF,0xAA,0xAA,
0xBE,0x08,0x00,0x04,0x04,0xFC,0x80,0x48,0x08,0xFE,0x08,0x08,0xFF,0x00,0x80,0x00,
0x04,0x04,0xFD,0x00,0x82,0x42,0x32,0x0F,0x12,0x22,0xC2,0x02,0x00,0x00,0x7F,0x49,
0x49,0x49,0xFF,0x49,0x49,0x49,0x7F,0x00,0x80,0x00,0x08,0x08,0x08,0x08,0x08,0x08,
0xFE,0x0A,0x09,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0xC0,0x21,0x20,0x22,0xC1,0x00,
0x00,0xC2,0x22,0x21,0x20,0xC0,0x00,0x02,0x03,0x02,0x81,0x00,0x01,0x03,0x02,0x82,
0x42,0x22,0x20,0x60,0x00,0x01,0x00,0x80,0x40,0xE3,0x00,0x00,0x00,0x61,0x23,0xE0,
0x22,0x61,0x00,0x01,0x02,0x82,0x62,0x82,0x02,0x02,0x22,0xE2,0x20,0x20,0x20,0xC0,
0x00,0x40,0x89,0x12,0x02,0x12,0xD2,0x12,0x9B,0xD0,0x90,0x90,0x10,0x00,0x00,0x02,
0x03,0xF8,0xA8,0xA8,0xA8,0xA8,0xA8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x00,
0x00,0x1C,0x23,0x22,0x23,0x1C,0x00,0x00,0x09,0x06,0x1F,0x06,0x09,0x00,0x00,0x1F,
0x22,0x21,0x21,0x1E,0x00,0x04,0x0B,0x08,0x28,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,
0x20,0x00,0x00,0x20,0x38,0x27,0x04,0x27,0x38,0x20,0x20,0x3F,0x21,0x21,0x21,0x1E,
0x00,0x08,0x7C,0x02,0x04,0x7F,0x40,0x22,0x15,0x0A,0x14,0x23,0x40,0x00,0x00,0x7E,
0x2A,0x2A,0x2A,0x7E,0x00,0x7E,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x29,0xAB,
0x65,0xA5,0x2F,0x30,0xAB,0x65,0xA5,0x2F,0x00,0x00,0x90,0xDC,0xB3,0x88,0x50,0x95,
0x15,0xF5,0x95,0x9F,0x50,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x5F,0x51,0x55,0x55,0xFF,0x55,0x55,0x51,0x5F,0x00,
0x00,0x00,0x00,0xFC,0x44,0x44,0x46,0x45,0x44,0x44,0x44,0xFC,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x72,0x02,0x7F,0x42,
0x22,0x1A,0x17,0x32,0x52,0x12,0x02,0x00,0x10,0x08,0xF4,0x93,0x92,0x92,0xFA,0x96,
0x92,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x80,0x82,0x03,0x42,
0x82,0x02,0xE2,0x0F,0x82,0x42,0x02,0x02,0x02,0x80,0x64,0x44,0x42,0xE2,0x44,0x42,
0x49,0x4F,0x40,0x01,0x02,0x24,0x40,0x00,0x41,0x42,0x46,0x60,0x40,0x40,0x40,0x40,
0x00,0x00,0x00,0x00,0xE0,0xA9,0xA5,0xA1,0xAD,0xA1,0xE1,0x0D,0x01,0x01,0x05,0x09,
0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x24,0x24,0x24,0xA4,0xAF,0x60,0x20,0x00,0x01,
0x02,0x06,0x80,0x80,0xE0,0x80,0x40,0xC0,0x40,0x60,0x40,0xC8,0x48,0x0F,0x09,0x8F,
0x89,0x89,0x8F,0x29,0x2F,0x28,0xA8,0x60,0x20,0x20,0x27,0x08,0x08,0x08,0xC8,0x48,
0x48,0x48,0x48,0x4E,0x40,0xE0,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x12,0xFE,0x92,0x00,0xFE,
0x2A,0x2A,0x2B,0x2A,0xFE,0x00,0x00,0x02,0x01,0x1F,0xD5,0x55,0x55,0x5F,0x55,0x55,
0xD5,0x15,0x10,0x00,0x21,0xF2,0x08,0x10,0xFC,0x03,0x88,0x56,0x2B,0x52,0x8E,0x00,
0x00,0x00,0xF8,0xA8,0xAB,0xAA,0xFA,0x02,0xFA,0xAA,0xAB,0xA8,0xF8,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x82,0x62,0x1E,0x20,0x2A,0xFF,0x2A,0x20,0x0F,0x34,0x42,
0x80,0x00,0x10,0x08,0xFF,0x04,0x12,0x12,0xB3,0x5A,0x53,0xB2,0x92,0x12,0x00,0x20,
0x60,0x3F,0x10,0x10,0x3F,0x81,0x41,0x3D,0x41,0xBF,0x00,0x00,0x00,0x00,0xFF,0x92,
0x92,0x92,0x92,0x92,0x92,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,
0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

/*************************************************************/
/* 延时程序 */
/*************************************************************/
//--------------------------------------------------------------------------
void nop(void)
{
int i;
for(i=0;i<10;i++)
{
;
}
}
//--------------------------------------------------------------------------
//12.0000MHz
void DelayMS(uint number)
{
uchar k;
for(;number!=0;number--)
for(k=198;k!=0;k--)
{
nop();
nop();
nop();
}
}


/*************************************************************/
/* 检查液晶忙标志 */
/*************************************************************/
/*void CheckLCMBusy(void)
{
uchar data BusyFlag;
do {
LCM_DnI = 0;
LCM_nRD = 0;
_nop_();
BusyFlag = P0;
_nop_();
LCM_nRD = 1;
BusyFlag = BusyFlag & 0x80;
}
while(BusyFlag==0x80);
}*/
/*************************************************************/
/* 写液晶指令 */
/*************************************************************/
void WriteCommandLCM(uchar CommandCode)
{
CLRBIT(PORTC,LCM_DnI);//LCM_DnI = 0;
CLRBIT(PORTC,LCM_nWR);//LCM_nWR = 0;
nop();
PORTA = CommandCode;
nop();
SETBIT(PORTC,LCM_nWR);//LCM_nWR = 1;
nop();
}
/*************************************************************/
/* 写液晶数据 */
/*************************************************************/
void WriteDataLCM(uchar Data)
{
SETBIT(PORTC,LCM_DnI);//LCM_DnI = 1;
CLRBIT(PORTC,LCM_nWR);//LCM_nWR = 0;
nop();
PORTA = Data;
nop();
SETBIT(PORTC,LCM_nWR);//LCM_nWR = 1;
nop();
}
/*************************************************************/
/* 读液晶数据 */
/*************************************************************/
/*uchar ReadDataLCM(void)
{
uchar data RData;
LCM_DnI = 1;
LCM_nRD = 0;
_nop_();
RData = P0;
_nop_();
LCM_nRD = 1;
_nop_();
return(RData);
}*/
/*************************************************************/
/* 清液晶显示 */
/*************************************************************/
void ClearLCM(uchar ddd)
{
uchar ii,jj;

WriteCommandLCM(0x40); //START LINE ADDRESS SET
WriteCommandLCM(0xAF); //SET PAGE0 ADDRESS
for(ii=0;ii<8;ii++)
{
WriteCommandLCM(0xB0+ii); //SET PAGE0 ADDRESS ++
WriteCommandLCM(0x10); //SET THE COLUMN ADDRESS MSB
WriteCommandLCM(0x02); //SET THE COLUMN ADDRESS LSB
for(jj=128;jj!=0;jj--)
WriteDataLCM(ddd);
}
}
/*************************************************************/
/* 液晶初始化 */
/*************************************************************/
void LCMInit(void)
{
SETBIT(DDRB,4);
SETBIT(PORTB,4);
SETBIT(DDRB,6);
SETBIT(PORTB,6);
DDRC=0XFF;
DDRA=0XFF;
CLRBIT(PORTC,LCM_nCS);//LCM_nCS = 0;
SETBIT(PORTC,LCM_nWR);//LCM_nWR = 1;
SETBIT(PORTC,LCM_nRD);//LCM_nRD = 1;

CLRBIT(PORTC,LCM_nRST);//LCM_nRST = 0;
nop();
nop();
nop();
nop();
nop();

SETBIT(PORTC,LCM_nRST);//LCM_nRST = 1; //至少1us复位液晶

WriteCommandLCM(0xA1);
WriteCommandLCM(0xC8);
WriteCommandLCM(0xA2);
WriteCommandLCM(0x2F);
WriteCommandLCM(0x21);
//REGULATOR RESISTOR SELECT:(1+(Rb/Ra)=5.29)X1.76=V0=11.07V
WriteCommandLCM(0x81);
WriteCommandLCM(0x03);
//REFERENCE VOLTAGE REGISTER SET:Vref=2V Vev=1.76=(1-(63-27)/300)*Vref
}
/*************************************************************/
/* 显示128*64的图形函数:纵向倒序 */
/*************************************************************/
#define Normal 0 //左右反转显示
#define Reverse 1 //对于该液晶的显示为正常从左到右显示
void Display128x64(uchar ADCSelectBit, uchar *TableArray)
{
uchar ii,jj;

if(ADCSelectBit == Reverse) WriteCommandLCM(0xA0);
else WriteCommandLCM(0xA1);
WriteCommandLCM(0x40); //START LINE ADDRESS SET
WriteCommandLCM(0xAF); //SET DISPLAY ON
for(ii=0;ii<8;ii++)
{
WriteCommandLCM(0xB0+ii); //SET PAGE0 ADDRESS ++
WriteCommandLCM(0x10); //SET THE COLUMN ADDRESS MSB
WriteCommandLCM(0x02); //SET THE COLUMN ADDRESS LSB
for(jj=128;jj!=0;jj--)
{
WriteDataLCM(*TableArray);
TableArray++;
}
}
WriteCommandLCM(0xA1);
}
/*************************************************************/
/* 主函数 */
/*************************************************************/
void main(void)
{
LCMInit();

for(;;)
{
ClearLCM(0xf0);
DelayMS(200);
ClearLCM(0x0f);
DelayMS(200);
ClearLCM(0xff);
DelayMS(200);
ClearLCM(0x00);
DelayMS(200);

Display128x64(Normal,zimo);
DelayMS(1000);
Display128x64(Reverse,zimo);
DelayMS(300);
}
}
/*************************************************************/
/* 结束 */
/*************************************************************/
 

©2018 Microchip Corporation
facebook google plus twitter linkedin youku weibo rss