2个回答
展开全部
我这有代码,但不知道与你的12864液晶是不是一个型号
#include "lcd_12864.h"
void LCD_Delayt(unsigned int dtime) {
unsigned int itemp;
for(itemp=0;itemp<dtime;itemp++);
}
void LCD_Init(void) {
SN74LVC_DIR_DIR |= SN74LVC_DIR;
SN74LVC_DIR_LO;
//SN74LVC_OE_DIR |= SN74LVC_OE;
//SN74LVC_OE_LO;
LCD_PSB_DIR |= LCD_PSB; //PSB -> 并行模式
LCD_PSB_HI;
LCD_RST_DIR |= LCD_RST; //RST -> 复位输出
LCD_RST_LO; //复位状态
LCD_Delayt(1000);
LCD_DI_DIR |= LCD_DI;
LCD_DI_LO;
LCD_RW_DIR |= LCD_RW;
LCD_RW_LO;
LCD_EN_DIR |= LCD_EN;
LCD_EN_LO;
LCD_Delayt(1000);
LCD_RST_HI; //正常状态
LCD_WriteComm(0x30);
LCD_WriteComm(0x0c);
LCD_WriteComm(0x01);
LCD_WriteComm(0x02);
LCD_WriteComm(0x06);
}
void LCD_CheckBusy(void) {
unsigned char Flag;
LCD_DI_LO;
LCD_RW_HI;
do {
LCD_EN_HI;
LCD_DATA_DIR = 0x00;
SN74LVC_DIR_HI;
_NOP();
Flag = LCD_DATA_IN;
_NOP();
SN74LVC_DIR_LO;
LCD_DATA_DIR = 0xFF;
LCD_EN_LO;
} while(Flag & 0x80);
}
void LCD_WriteComm(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_LO;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_WriteByte(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_HI;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_SetXY(unsigned char X, unsigned char Y) {
switch(Y) {
case 1:
LCD_WriteComm(0x7F + X);
break;
case 2:
LCD_WriteComm(0x8F + X);
break;
case 3:
LCD_WriteComm(0x87 + X);
break;
case 4:
LCD_WriteComm(0x97 + X);
}
}
void LCD_WriteDEC(unsigned char X, unsigned char Y, unsigned char wdata) {
LCD_SetXY(X,Y);
LCD_WriteByte(wdata);
}
void LCD_WriteString(unsigned char X, unsigned char Y, unsigned char *String) {
unsigned char temp;
LCD_SetXY(X,Y);
temp = *String;
while(temp!=0) {
LCD_WriteByte(temp);
temp = *(++String);
}
}
void Clr_Screen(void)
{
LCD_WriteComm(0x00);
}
#include "lcd_12864.h"
void LCD_Delayt(unsigned int dtime) {
unsigned int itemp;
for(itemp=0;itemp<dtime;itemp++);
}
void LCD_Init(void) {
SN74LVC_DIR_DIR |= SN74LVC_DIR;
SN74LVC_DIR_LO;
//SN74LVC_OE_DIR |= SN74LVC_OE;
//SN74LVC_OE_LO;
LCD_PSB_DIR |= LCD_PSB; //PSB -> 并行模式
LCD_PSB_HI;
LCD_RST_DIR |= LCD_RST; //RST -> 复位输出
LCD_RST_LO; //复位状态
LCD_Delayt(1000);
LCD_DI_DIR |= LCD_DI;
LCD_DI_LO;
LCD_RW_DIR |= LCD_RW;
LCD_RW_LO;
LCD_EN_DIR |= LCD_EN;
LCD_EN_LO;
LCD_Delayt(1000);
LCD_RST_HI; //正常状态
LCD_WriteComm(0x30);
LCD_WriteComm(0x0c);
LCD_WriteComm(0x01);
LCD_WriteComm(0x02);
LCD_WriteComm(0x06);
}
void LCD_CheckBusy(void) {
unsigned char Flag;
LCD_DI_LO;
LCD_RW_HI;
do {
LCD_EN_HI;
LCD_DATA_DIR = 0x00;
SN74LVC_DIR_HI;
_NOP();
Flag = LCD_DATA_IN;
_NOP();
SN74LVC_DIR_LO;
LCD_DATA_DIR = 0xFF;
LCD_EN_LO;
} while(Flag & 0x80);
}
void LCD_WriteComm(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_LO;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_WriteByte(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_HI;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_SetXY(unsigned char X, unsigned char Y) {
switch(Y) {
case 1:
LCD_WriteComm(0x7F + X);
break;
case 2:
LCD_WriteComm(0x8F + X);
break;
case 3:
LCD_WriteComm(0x87 + X);
break;
case 4:
LCD_WriteComm(0x97 + X);
}
}
void LCD_WriteDEC(unsigned char X, unsigned char Y, unsigned char wdata) {
LCD_SetXY(X,Y);
LCD_WriteByte(wdata);
}
void LCD_WriteString(unsigned char X, unsigned char Y, unsigned char *String) {
unsigned char temp;
LCD_SetXY(X,Y);
temp = *String;
while(temp!=0) {
LCD_WriteByte(temp);
temp = *(++String);
}
}
void Clr_Screen(void)
{
LCD_WriteComm(0x00);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询