单片机源程序如下:
#include "LCD.h"
#include "LCD_LIST.h"
#define delay_ns(m) {u8 i;for(i=(m);i>0;i--);}
static u8 lcdImg[MAX_ADDR];
static u8 discnt;
//-----------硬件驱动部分---------------------------------------------------------------------------------------------
void LCD_en(void)//使能LCD读写许可
{
LCD_CS_H;
LCD_WRITE_H;
delay_ns(20);
LCD_CS_L;
delay_ns(20);
}
void LCD_dis(void)//禁止LCD读写
{
LCD_WRITE_H;
LCD_CS_H;
delay_ns(20);
}
void LCD_Write(u16 data,u8 len)//将data的低len位写入到LCD_DRIVER
{
for(;len>0;len--)
{
LCD_WRITE_L;
delay_ns(5);
if(data & (1<<(len-1))){LCD_DATA_H;}else{LCD_DATA_L;}
delay_ns(5);
LCD_WRITE_H;
delay_ns(10);
}
}
//------------硬件驱动结束-----------------------------------------------------------------------------------------------
//@@@@@@@@@@@@指令处理部分@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void LCD_command_1(u16 com)
{
LCD_en();
LCD_Write(com,12);
LCD_dis();
}
void LCD_commands_n(u16 * com,u8 len)
{
if(len)
{
LCD_en();
LCD_Write(4,3);
for(;len > 0;len--,com++)
{
LCD_Write(*com,9);
}
LCD_dis();
}
}
//@@@@@@@@@@@@指令处理结束@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//############数据发送部分################################################################################################
void LCD_Write_Data(u16 addr,u8 dt)
{
LCD_en();
LCD_Write(5,3);
LCD_Write(addr,6);
LCD_Write((u16)(dt),4);
LCD_dis();
}
void LCD_Write_Datas(u16 addr,u8 *dt,u8 len)
{
if(len)
{
LCD_en();
LCD_Write(5,3);
LCD_Write(addr,6);
for(;len > 0;len--,dt++)
{
LCD_Write((u16)(*dt),4);
}
LCD_dis();
}
}
void LCD_Flush(u8 init)
{
u8 copyImg[MAX_ADDR],cnt;
if(init && discnt == 0){LCD_init(1,0);}
if( discnt++ >= 10) discnt = 0;
if( discnt < 5 )
{
LCD_Write_Datas(0,lcdImg,MAX_ADDR);
}
else
{
for(cnt=0;cnt copyImg[cnt] = lcdImg[cnt] & (~(lcdImg[cnt]>>4)); } LCD_Write_Datas(0,copyImg,MAX_ADDR); } } //############数据发送结束################################################################################################ //------------LCD启动、关闭----------------------------------------------------------------------------------------------- void LCD_init(u8 fastinit,u8 whethclear) { #ifdef HT1621_LCD_DRIVER u16 coms[] = {LCD_RC_256K,LCD_SYS_EN,LCD_BIAS_3_4,LCD_TNORMAL,LCD_LCD_ON};// #endif #ifdef HT1622_LCD_DRIVER u16 coms[] = {LCD_RC_32K,LCD_SYS_EN,LCD_TNORMAL,LCD_LCD_ON};//LCD_RC_32K和LCD_TNORMAL是默认值 #endif if(fastinit) { LCD_commands_n(coms,sizeof(coms)/sizeof(coms[0])); } else { #ifdef HT1621_LCD_DRIVER LCD_command_1(LCD_RC_256K); LCD_command_1(LCD_SYS_EN); LCD_command_1(LCD_BIAS_3_4); LCD_command_1(LCD_TNORMAL); LCD_command_1(LCD_LCD_ON); #endif #ifdef HT1622_LCD_DRIVER LCD_command_1(LCD_RC_32K); LCD_command_1(LCD_SYS_EN); LCD_command_1(LCD_TNORMAL); LCD_command_1(LCD_LCD_ON); #endif } if(whethclear) LCD_clear_all(); } void LCD_off(void) { u16 coms[] = {LCD_SYS_DIS,LCD_SYS_DIS}; LCD_commands_n(coms,sizeof(coms)/sizeof(coms[0])); LCD_BKG_OFF(); } void LCD_clear_all(void) { u8 i; discnt = 0; for(i=0;i } void LCD_dis_all(void) { u8 i; discnt = 0; for(i=0;i } void LCD_flash_all(void) { u8 i; discnt = 0; for(i=0;i } //------------LCD启动关闭处理结束----------------------------------------------------------------------------------------- //$局部处理部分$ void mark_dis(u8 addr_v,u8 addr_h,enum MARK_DIS_OPTION type) { #ifdef HT1621_LCD_DRIVER addr_h &= 0x0F;addr_v &= 0x1F; #endif #ifdef HT1622_LCD_DRIVER addr_h &= 0x0F;addr_v &= 0x3F; #endif if (type == MARK_ON ) {lcdImg[addr_v] |= addr_h; lcdImg[addr_v] &= (((~addr_h) << 4) | 0x0F);} else if (type == MARK_OFF ) {lcdImg[addr_v] &= ~addr_h; lcdImg[addr_v] &= (((~addr_h) << 4) | 0x0F);} else {lcdImg[addr_v] |= addr_h; lcdImg[addr_v] |= ((addr_h << 4) & 0xF0);} } void seg_clear_bits(u8 addr_seg,u8 clear_bis) { #ifdef HT1621_LCD_DRIVER clear_bis &= 0x0F;addr_seg &= 0x1F; #endif #ifdef HT1622_LCD_DRIVER clear_bis &= 0x0F;addr_seg &= 0x3F; #endif lcdImg[addr_seg] &= ~clear_bis; lcdImg[addr_seg] &= (((~clear_bis) << 4) | 0x0F); } void seg_clear(u8 addr_seg) { #ifdef HT1621_LCD_DRIVER addr_seg &= 0x1F; #endif #ifdef HT1622_LCD_DRIVER addr_seg &= 0x3F; #endif lcdImg[addr_seg] = 0x00; } void dis_mark_out(u8 outX,enum MARK_DIS_OPTION type) { switch (outX) { #ifdef HT1621_LCD_DRIVER case 1 : mark_dis(2,1,type);break; case 2 : mark_dis(4,1,type);break; case 3 : mark_dis(4,8,type);break;
上一篇:基于AT89S52单片机的电子密码锁
下一篇:单片机模拟空调温度控制器,按键设定温度和控制风力
推荐阅读最新更新时间:2024-11-17 08:53