《基于STC89C52RC的LCD12864模塊調(diào)試源碼》由會員分享,可在線閱讀,更多相關《基于STC89C52RC的LCD12864模塊調(diào)試源碼(6頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、///////////////////////////////////////////////////////
CONFIG.H引腳配置文件:
///////////////////////////////////////////////////////
#ifndef _CONFIG_H
#define _CONFIG_H
/* 通用頭文件 */
#include
#include
/* 數(shù)據(jù)類型定義 */
/*typedef signed char int8; // 8位有符號整型數(shù)
typedef
2、 signed int int16; //16位有符號整型數(shù)
typedef signed long int32; //32位有符號整型數(shù) */
typedef unsigned char u8; // 8位無符號整型數(shù)
typedef unsigned int u16; //16位無符號整型數(shù)
typedef unsigned long u32; //32位無符號整型數(shù)
/* 全局運行參數(shù)定義 */
#define SYS_MCLK (11059200/12) //系統(tǒng)主時鐘頻率,即振蕩器頻率
3、÷12
/* IO引腳分配定義 */
sbit KEY_IN_1 = P2^4; //矩陣按鍵的掃描輸入引腳1
sbit KEY_IN_2 = P2^5; //矩陣按鍵的掃描輸入引腳2
sbit KEY_IN_3 = P2^6; //矩陣按鍵的掃描輸入引腳3
sbit KEY_IN_4 = P2^7; //矩陣按鍵的掃描輸入引腳4
sbit KEY_OUT_1 = P2^3; //矩陣按鍵的掃描輸出引腳1
sbit KEY_OUT_2 = P2^2; //矩陣按鍵的掃描輸出引腳2
sbit KEY_OUT_3 = P2^1; //矩陣按鍵的掃描輸出引腳3
4、
sbit KEY_OUT_4 = P2^0; //矩陣按鍵的掃描輸出引腳4
sbit ADDR0 = P1^0; //LED位選譯碼地址引腳0
sbit ADDR1 = P1^1; //LED位選譯碼地址引腳1
sbit ADDR2 = P1^2; //LED位選譯碼地址引腳2
sbit ADDR3 = P1^3; //LED位選譯碼地址引腳3
sbit ENLED = P1^4; //LED顯示部件的總使能引腳
#define LCD12864_DB P0 //1602液晶數(shù)據(jù)端口
sbit LCD12864_RES = P1^0; //1602液
5、晶指令/數(shù)據(jù)選擇引腳
sbit LCD12864_RW = P1^1; //1602液晶讀寫引腳
sbit LCD12864_EN = P1^5; //1602液晶使能引腳
sbit DS1302_CE = P1^7; //DS1302片選引腳
sbit DS1302_CK = P3^5; //DS1302通信時鐘引腳
sbit DS1302_IO = P3^4; //DS1302通信數(shù)據(jù)引腳
sbit I2C_SCL = P3^7; //I2C總線時鐘引腳
sbit I2C_SDA = P3^6; //I2C總線數(shù)據(jù)引腳
sbit BUZZER =
6、 P1^6; //蜂鳴器控制引腳
sbit IO_18B20 = P3^2; //DS18B20通信引腳
sbit IR_INPUT = P3^3; //紅外接收引腳
#include "LCD12864.H"
#include "TIME.H"
#include "DHT21.h"
#endif
//////////////////////////////////////////////////////////////
LCD12864.C源碼
//////////////////////////////////////////////////////
7、///////
#include "config.h"
u8 zhbuf[]={"預覽"}; //中文數(shù)組
u8 ehbuf[]={"yulan"}; //英文字符數(shù)組
u8 code imbuf[]={ //圖片碼128*64 寬16,高32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/*寫等待*/
void Write_Ready()
{
u8 sta=0;
LCD12864_RES = 0;
LCD12864_RW =
8、1;
do{
LCD12864_EN = 1;
sta = P0;
LCD12864_EN = 0;
}while(sta&0x80);
}
/*讀RAM中數(shù)據(jù)*/
u8 Read_12864_RAM()
{
u8 ram=0;
LCD12864_RES = 1;
LCD12864_RW = 1;
LCD12864_EN = 1;
ram = P0;
LCD12864_EN = 0;
return ram;
}
/*寫指令*/
void Write_12864_Cmd(u8 cmd)
{
Write_Ready();
9、 LCD12864_RES = 0;
LCD12864_RW = 0;
P0 = cmd;
LCD12864_EN = 1;
LCD12864_EN = 0;
}
/*寫數(shù)據(jù)*/
void Write_12864_Dat(u8 dat)
{
Write_Ready();
LCD12864_RES = 1;
LCD12864_RW = 0;
P0 = dat;
LCD12864_EN = 1;
LCD12864_EN = 0;
}
/*設置起始坐標*/
void Set_DDRAM_XY(u8 x,u8 y)
{
if(x>=7)
10、 x=7;
if(y>=3)
y=3;
switch(y)
{
case 0:Write_12864_Cmd(0x80+x);break;
case 1:Write_12864_Cmd(0x90+x);break;
case 2:Write_12864_Cmd(0x88+x);break;
case 3:Write_12864_Cmd(0x98+x);break;
default : break;
}
}
/*顯示連續(xù)的2個字符*/
void Show_Double_12864_Char(u8 x,u8 y,u8 *c)
{
Se
11、t_DDRAM_XY(x,y);
Write_12864_Dat(*c);
Write_12864_Dat(*(c+1));
}
/*顯示單個字符*/
void Show_Single_12864_Char(u8 x,u8 y,u8 *c)
{
Set_DDRAM_XY(x,y);
Write_12864_Dat(*c);
}
/*顯示中文字符串*/
void Show_12864_ZH(u8 x,u8 y,u8 *zh)
{
u8* p=zh;
Set_DDRAM_XY(x,y);
while((*p)!='\0')
{
Writ
12、e_12864_Dat(*p++);
}
}
/*顯示一串數(shù)值*/
/*u8 dec 小數(shù)位 為0不顯示小數(shù)*/
void Show_12864_NUM(u8 x,u8 y,u8 dec,u16 num)
{
u8 i;
u8 numbuf[6];
for(i=0;num;i++)
{
numbuf[i]=num%10+'0';
num/=10;
}
Set_DDRAM_XY(x,y);
for(;i;i--)
{
if(i==dec)
{
Write_12864_Dat(0X2E); //顯示小數(shù)點
13、 }
Write_12864_Dat(*(numbuf+(i-1))); //顯示數(shù)值
}
}
/*顯示英文字符串*/
void Show_12864_EH(u8 x,u8 y,u8 *eh)
{
u8* p=eh;
Set_DDRAM_XY(x,y);
while((*p)!='\0')
{
Write_12864_Dat(*p++);
}
}
/*顯示圖案*/
void Show_12864_IM(u8 code *im)
{
unsigned char x,y,i;
unsigned int tmp=0;
for(i=
14、0;i<9;)
{ //分兩屏,上半屏和下半屏,因為起始地址不同,需要分開
for(x=0;x<32;x++)
{ //32行
Write_12864_Cmd(0x34);
Write_12864_Cmd(0x80+x);//列地址
Write_12864_Cmd(0x80+i); //行地址,下半屏,即第三行地址0X88
Write_12864_Cmd(0x30);
for(y=0;y<16;y++)
Write_12864_Dat(im[tmp+y]);
15、//讀取數(shù)據(jù)寫入LCD
tmp+=16;
}
i+=8;
}
Write_12864_Cmd(0x36); //擴充功能設定
Write_12864_Cmd(0x30);
}
/*初始化12864*/
void Init_Lcd12864()
{
Read_12864_RAM();
Show_Single_12864_Char(0,0,'A');
Show_Double_12864_Char(0,0,"AB");
Show_12864_NUM(0,0,1,123);
Show_12864_ZH(0,0,"預覽");
Sh
16、ow_12864_EH(0,0,"yulan");
Show_12864_IM(imbuf);
Write_12864_Cmd(0X30); //8位數(shù)據(jù),基本指令
Write_12864_Cmd(0X0C); //開顯示,關游標
Write_12864_Cmd(0X01); //清屏
Write_12864_Cmd(0X02); //地址歸位
Write_12864_Cmd(0X80); //設置DDRAM地址
}
/////////////////////////////////////////////////////////////////
17、/////////////////////
MAIN.C文件
/////////////////////////////////////////////////////////////////////////////////////////////
/*主測試函數(shù)*/
void main()
{
Init_Lcd12864();
Read_12864_RAM();
Show_12864_IM(imbuf);
Show_12864_EH(0,0,ehbuf);
Show_12864_ZH(1,1,zhbuf);
while(1);
}
///////////////////////////////////////////////////////////////