您现在的位置: 主页 > 嵌入式开发入门到精通 > 单片机技术进阶 > 液晶显示器LCD12864驱动程序 -
本文所属标签:
为本文创立个标签吧:

液晶显示器LCD12864驱动程序 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-08 

[导读]#include#include "lcd12864.h"#include "typedef.h"#define cyCSBIT0//P2.0,片选信号#define cySIDBIT1//P2.1,串行数据#define cyCLKBIT2//P2.2,同步时钟#define cyPORTP2OUT#define cyDDRP2DIRvoid Write_8bits

#include
#include "lcd12864.h"
#include "typedef.h"

#define cyCSBIT0//P2.0,片选信号
#define cySIDBIT1//P2.1,串行数据
#define cyCLKBIT2//P2.2,同步时钟
#define cyPORTP2OUT
#define cyDDRP2DIR

本文引用地址: http://www.21ic.com/app/mcu/201807/778428.htm


void Write_8bits(u8 W_bits)
{
u8 i;
cyDDR |= cyCLK + cySID;//设置输出方向
for(i = 0; i < 8; i++)
{
if(( W_bits << i )&0x80)
{
cyPORT |= cySID;

}
else
{
cyPORT &= ~cySID;
}
delay_ms(1);
cyPORT |= cyCLK;
delay_ms(1);
delay_ms(1);
cyPORT &= ~cyCLK;
}
}


void w_1byte(u8 RS, u8 w_data)
{
u8 H_Data,L_Data;
u8 tmp_Data = 0xf8;

cyDDR |= cyCS;//设置CS口为输出
if(RS == 0) tmp_Data &= ~0x02;
elsetmp_Data |= 0x02;

H_Data = w_data;//高位数据
H_Data &= 0xf0;
L_Data = w_data;//低位数据
L_Data &= 0x0f;
L_Data <<= 4;

cyPORT |= cyCS;
Write_8bits(tmp_Data);
Write_8bits(H_Data);
Write_8bits(L_Data);
cyPORT &= ~cyCS;
}


void init_Lcd(void)
{
cyDDR |= cyCLK + cySID + cyCS;//相应的位端口设置为输出
delay_ms(10);//延时等待液晶完成复位
w_1byte(0,0x30);
delay_ms(1);
w_1byte(0,0x02);
delay_ms(5);
w_1byte(0,0x0c);
delay_ms(1);
w_1byte(0,0x01);
delay_ms(5);
w_1byte(0,0x06);
delay_ms(1);
}

//清屏
void clear_lcd(void)
{
delay_ms(1);
w_1byte(0,0x01);
delay_ms(5);
}

void lcd_pos(u8 x,u8 y)//定位
{
u8 pos;
switch(x)
{
case 1:pos=0x80;break;
case 2:pos=0x90;break;
case 3:pos=0x88;break;
case 4:pos=0x98;break;
default:pos=0x80;
}
pos += y;
w_1byte(0,pos);
}

//显示汉字
void Disp_HZ(const u8 * pt,u8 num)
{
u8 i;
for(i = 0;i < num*2;i++)
{
w_1byte(1,*(pt++));
}
}

//显示字符
void Disp_Ch(const u8 ch)
{
w_1byte(1, ch);
}

//汉字和字符混合显示
void disp_lcd_str(u8 x, u8 y, const u8 *str, u8 len)
{
u8 i;
lcd_pos(x, y);
for(i = 0;i < len && *str; )
{
if(*(str) >= 0x80)
{
w_1byte(1,*(str++));
w_1byte(1,*(str++));
i++;
i++;
}
else
{
w_1byte(1,*(str++));
i++;
}
}
}




              查看评论 回复



 

"液晶显示器LCD12864驱动程序 -"的相关文章

网站地图

围观()