S6B0724芯片的LCD128*64的AVR128驅(qū)動(dòng)程序
以下是用S6B0724做驅(qū)動(dòng)芯片的128*64的AVR128驅(qū)動(dòng)程序,已經(jīng)測(cè)試通過(guò)。請(qǐng)大家放心使用,呵呵!
/*************************************************************/
#i nclude avr/io.h>
/*************************************************************/
/* 宏定義替換 */
/*************************************************************/
#define uchar unsigned char //宏定義替換
#define uint unsigned int //宏定義替換
#define ulong unsigned long //宏定義替換
/*************************************************************/
/* 接口定義替換 */
/*************************************************************/
//#define LCM_DB P0 //數(shù)據(jù)總線(xiàn)定義
//sbit LCM_nRST = P1^0; //低電平復(fù)位
//sbit LCM_nCS = P2^7; //片選A15
//sbit LCM_DnI = P2^0; //數(shù)據(jù)與指令的接口A8
//sbit LCM_nWR = P3^6; //寫(xiě)選通線(xiàn)
//sbit LCM_nRD = P3^7; //讀選通線(xiàn)
#define LCM_DB PORTA //數(shù)據(jù)總線(xiàn)定義
#define LCM_nRST PC7 //低電平復(fù)位
#define LCM_nCS PC6 //片選A15
#define LCM_DnI PC5 //數(shù)據(jù)與指令的接口A8
#define LCM_nWR PC4 //寫(xiě)選通線(xiàn)
#define LCM_nRD PC3 //讀選通線(xiàn)
#define SETBIT(x,y) (x |= (1y)) // Set bit y in byte x
#define CLRBIT(x,y) (x = (~(1y)))// Clear bit y in byte x
#define CHKBIT(x,y) (x (1y)) // Check bit y in byte x
/*************************************************************/
/* 字模數(shù)組 */
/*************************************************************/
/*-- 調(diào)入了一幅圖像: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};
/*************************************************************/
/* 延時(shí)程序 */
/*************************************************************/
//--------------------------------------------------------------------------
void nop(void)
{
int i;
for(i=0;i10;i++)
{
;
}
}
//--------------------------------------------------------------------------
//12.0000MHz
void DelayMS(uint number)
{
uchar k;
for(;number!=0;number--)
for(k=198;k!=0;k--)
{
nop();
nop();
nop();
}
}
/*************************************************************/
/* 檢查液晶忙標(biāo)志 */
/*************************************************************/
/*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);
}*/
/*************************************************************/
/* 寫(xiě)液晶指令 */
/*************************************************************/
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();
}
/*************************************************************/
/* 寫(xiě)液晶數(shù)據(jù) */
/*************************************************************/
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();
}
/*************************************************************/
/* 讀液晶數(shù)據(jù) */
/*************************************************************/
/*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;ii8;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復(fù)位液晶
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的圖形函數(shù):縱向倒序 */
/*************************************************************/
#define Normal 0 //左右反轉(zhuǎn)顯示
#define Reverse 1 //對(duì)于該液晶的顯示為正常從左到右顯示
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;ii8;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);
}
/*************************************************************/
/* 主函數(shù) */
/*************************************************************/
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);
}
}
/*************************************************************/
/* 結(jié)束 */
/*************************************************************/
評(píng)論