?? 19264lcd.c
字號:
// CA19264A Demo Program
//***************************************************************************
//* Create by :liujun 2005.02.28 *
//***************************************************************************
//連線表: CPU=89C52 *
//RS=P2.0 R/W=P2.1 E=P2.2 CS1=P2.3 CS2=P2.4 *
//SysClock=12MHz DB0-DB7=P2.0-P2.7 /Reset=InBoard *
//因為這款液晶是兩個片選,00 01 10表示三個芯片,三個片選各自代表一個道理是一樣的。
//***************************************************************************
#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
/********************引腳定義********************/
sbit CS1 =P1^3; //1片選
sbit CS2 =P1^5; //2片選
sbit CS3 =P1^6; //3片選
sbit RS =P1^0; //數據指令
sbit RW =P1^1; //讀寫
sbit E =P1^2; //使能
sbit RST =P1^5;//復位
//sbit Sbreak=P
unsigned char Page; //頁 地址
unsigned char Col; //列 地址
unsigned char code BMP1[];
unsigned char code BMP2[];
char code Hanzi[];
void Delay(unsigned int MS);
void wtcom(void);
/***************************/
/*檢查Busy */
/***************************/
void BusyL(void)
{
CS1= 0;
CS2= 1;
CS3= 1;
wtcom();
}
void BusyM(void)
{
CS1= 1;
CS2= 0;
CS3= 1;
wtcom();
}
void BusyR(void)
{
CS1= 1;
CS2= 1;
CS3= 0;
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P2 = 0xFF; //輸出0xff以便讀取正確
E = 1;
_nop_();
while(P2 & 0x80); //Status Read Bit7 = BUSY
E = 0;
_nop_();
}
/********************************************************/
/*根據設定的坐標數據,定位LCM上的下一個操作單元位置 */
/********************************************************/
void Locatexy(void)
{
unsigned char x,y;
switch (Col&0xc0) /* col.and.0xC0 */
{ /*條件分支執行 */
case 0: {BusyL();break;}/*左區 */
case 0x40: {BusyM();break;}/*中區 */
case 0x80: {BusyR();break;}/*右區 */
}
x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/
y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */
wtcom(); /* waitting for enable */
RS = 0; //指令
RW = 0; //寫
P2 = y; //設置頁面地址
E = 1;
_nop_();
E = 0;
_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P2 = x; //設置列地址
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*寫指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
BusyL();
P2 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandM( unsigned char CommandByte )
{
BusyM();
P2 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandR( unsigned char CommandByte )
{
BusyR();
P2 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*讀數據 */
/***************************/
unsigned char ReadData( void )
{
unsigned char DataByte;
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
RS = 1; /*數據輸出*/
RW = 1; /*讀入 */
P2 = 0xFF; //輸出0xff以便讀取正確
E = 1; /*讀入到LCM*/
_nop_();
DataByte = P2; /*數據讀出到數據口P2 */
E = 0;
_nop_();
return DataByte;
}
/***************************/
/*寫數據 */
/***************************/
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
RS = 1; /*數據輸出*/
RW = 0; /*寫輸出 */
P2 = DataByte; /*數據輸出到數據口 */
E = 1; /*寫入到LCM*/
_nop_();
E = 0;
_nop_();
}
void LcmClear( void )
{
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
for(Col=0;Col<192;Col++)
WriteData(0);
}
void LcmInit( void )
{
WriteCommandL(0x3f); //開顯示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
WriteCommandL(0xc0); //設置起始地址=0
WriteCommandM(0xc0);
WriteCommandR(0xc0);
WriteCommandL(0x3f); //開顯示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
LcmClear();
Col = 0;
Page= 0;
Locatexy();
}
/*
void LcmPutDots( unsigned char DotByte )
{
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<192;Col++)
{
WriteData( DotByte );
DotByte = ~DotByte;
}
}
} */
void LcmPutBMP( unsigned char *puts )
{
unsigned int X=0;
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<192;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
void LcmReverseBMP( void )
{
unsigned char temp;
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<192;Col++)
{
temp = ReadData(); //空讀一次
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -