网站首页
IC库存
IC展台
电子资讯
技术资料
PDF文档
我的博客
IC72论坛
ic72 logo
资料首页最新产品 技术参数 电路图 设计应用 解决方案 代理商查询 IC替换 IC厂商 电子辞典
关键字: 技术文章 PDF资料 IC价格 电路图 代理商查询 IC替换 IC厂商 电子辞典

12864液晶(AVR_Mega128)的头文件

根据你们液晶电路更改下面的端口宏定义即可

//CPU:ATmega128; 时钟频率为16MHz

//编译环境为ICCAVR

//头文件

#include

#include

#include

//数据端口定义

#define Dat_Port_Write PORTA

#define Dat_Port_Read PINA

//控制端口及相应的位

#define RS_RW_EN_Control PORTG

#define LCM_RS 0

#define LCM_RW 1

#define LCM_EN 2

#define uchar unsigned char

#define uint unsigned int

//延时函数

void Delay_Ms(unsigned int ms)

{

for(;ms>1;ms--);

}

//写数据

void Write_Data_LCM(unsigned char WDLCM)

{

Read_Status_LCM(); //检测忙

Delay_Ms(100);

RS_RW_EN_Control|=BIT(LCM_RS); //RS=1

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_RW); //RW=0

Delay_Ms(100);

RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

Delay_Ms(100);

Dat_Port_Write=WDLCM; //输出数据

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

Delay_Ms(100);

}

//写指令

void Write_Command_LCM(unsigned char WCLCM)

{

Read_Status_LCM(); //根据需要检测忙

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_RS); //RS=0

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_RW); //RW=0

Delay_Ms(100);

RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

Delay_Ms(100);

Dat_Port_Write=WCLCM; //输出指令

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

Delay_Ms(100);

}

//读状态:检测忙

void Read_Status_LCM(void)

{

uchar temp;

uchar flag = 1;

while(flag==1)

{

DDRA=0x00; //端口A改为输入

Dat_Port_Write = 0xff;

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_RS); //RS=0

Delay_Ms(100);

RS_RW_EN_Control|=BIT(LCM_RW); //RW=1

Delay_Ms(100);

RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

Delay_Ms(100);

temp = Dat_Port_Read; //读端口A

Delay_Ms(100);

DDRA=0xff; //端口A改为

Delay_Ms(100);

RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

Delay_Ms(100);

if(temp>>7==0)

flag = 0;

}

}

//LCM初始化

void LCM_Init(void)

{

Write_Command_LCM(0x38); //三次显示模式设置,不检测忙信号

Delay_Ms(1000);

Write_Command_LCM(0x38);

Delay_Ms(1000);

Write_Command_LCM(0x38);

Delay_Ms(1000);

Write_Command_LCM(0x38); //显示模式设置,开始要求每次检测忙信号

Write_Command_LCM(0x08); //关闭显示

Write_Command_LCM(0x01); //显示清屏

Write_Command_LCM(0x06); //显示光标移动设置

Write_Command_LCM(0x0C); //显示开及光标设置

}

/

热门搜索:2858043 N060-002 2920120 2762265 CC2544RHBR 2866569 SS7415-15 TLM812SA 2839376 SS240806 TLM825GF RS1215-RA 2856032 B40-8000-PCB LCR2400 SBB830 SS361220 02B1001JF TLM626NS BTS410F2E6327 UL24CB-15 SS7619-15 6NX-6 2839224 2838319
COPYRIGHT:(1998-2010) IC72 达普IC芯片交易网
客户服务:service@IC72.com 库存上载:IC72@IC72.com
(北京)联系方式: 在线QQ咨询:点击这里给我发消息 联系电话:010-82614113 传真:010-82614123
京ICP备06008810号-21 京公网安备 11010802032910 号 企业资质