?? 19264液晶屏演示程序2.c
字號:
//連線表: CPU=89C52 *
//RS=P3.0 R/W=P3.1 E=P3.2 CS1=P3.3 CS2=P3.4 *
//SysClock=12MHz DB0-DB7=P0.0-P0.7 /Reset=InBoard *
//***************************************************************************
#pragma debug code small
#pragma REGPARMS
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
#include "D:\Program Files\KEIL\C51\INC\reg52.h"
#include <math.h>
#include <absacc.h>
#include <ctype.h>
#include "YDJ.H"
/********************引腳定義********************/
sbit RS =P2^2; //數據指令
sbit RW =P2^3; //讀寫
sbit E =P2^6; //使能
sbit A12 =P2^4; //1片選
sbit A13 =P2^5; //2片選
sbit A15 =P2^7; //3片
unsigned char Page; //頁 地址
unsigned char Col; //列 地址
unsigned char code BMP1[];
unsigned char code BMP2[];
void Delay(unsigned int MS);
void wtcom(void);
/***************************/
/*檢查Busy */
/***************************/
void BusyL(void)
{
A12= 0;
A13= 0;
A15= 1;
wtcom();
}
void BusyM(void)
{
A12= 0;
A13= 1;
A15= 1;
wtcom();
}
void BusyR(void)
{
A12= 1;
A13= 0;
A15= 1;
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P0 = 0xFF; //輸出0xff以便讀取正確
E = 1;
_nop_();
//while(P0 & 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; //寫
P0 = y; //設置頁面地址
E = 1;
_nop_();
E = 0;
_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P0 = x; //設置列地址
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*寫指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
BusyL();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandM( unsigned char CommandByte )
{
BusyM();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandR( unsigned char CommandByte )
{
BusyR();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*讀數據 */
/***************************/
unsigned char ReadData( void )
{
unsigned char DataByte;
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
RS = 1; /*數據輸出*/
RW = 1; /*讀入 */
P0 = 0xFF; //輸出0xff以便讀取正確
E = 1; /*讀入到LCM*/
_nop_();
DataByte = P0; /*數據讀出到數據口P0 */
E = 0;
_nop_();
return DataByte;
}
/***************************/
/*寫數據 */
/***************************/
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
RS = 1; /*數據輸出*/
RW = 0; /*寫輸出 */
P0 = 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 + -