12864液晶(AVR_Mega128)的头文件
出处:维库电子市场网 发布于:2015-10-27 10:03:50
根据你们液晶电路更改下面的端口宏定义即可
//CPU:ATmega128; 时钟频率为16MHz
//编译环境为ICCAVR
//头文件
#include <iom128v.h>
#include <string.h>
#include<avrdef.h>
//数据端口定义
#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); //显示开及光标设置
}
/
版权与免责声明
凡本网注明“出处:维库电子市场网”的所有作品,版权均属于维库电子市场网,转载请必须注明维库电子市场网,https://www.dzsc.com,违反者本网将追究相关法律责任。
本网转载并注明自其它出处的作品,目的在于传递更多信息,并不代表本网赞同其观点或证实其内容的真实性,不承担此类作品侵权行为的直接责任及连带责任。其他媒体、网站或个人从本网转载时,必须保留本网注明的作品出处,并自负版权等法律责任。
如涉及作品内容、版权等问题,请在作品发表之日起一周内与本网联系,否则视为放弃相关权利。
- Microchip 发布PIC16F13145系列MCU,促进可定制逻辑的新发展2024/4/23 15:34:17
- 什么是MCU2024/3/25 17:05:40
- 了解GD32单片机和STM32单片机2024/3/13 14:17:13
- STM32F103单片机概述2024/3/13 14:13:33
- 什么是DSP?DSP的分类2024/1/22 16:38:45
- 英特尔数据存储如何操作和实现
- 什么是微动开关_微动开关有什么用_微动开关使用方法
- VCC,VDD,VEE,VSS在电源原理图中有什么区别?
- 低压配电系统设计规范_低压配电系统设计注意事项
- xEV 主逆变器电源模块中第四代 SiC MOSFET 的短路测试
- 光耦详细应用教程
- 定义绝缘耐久性评估的电压脉冲测试要求
- 采用沟槽MOS结构,使存在权衡关系的VF和IR相比以往产品得到显著改善 ROHM推出实现业界超快trr的100V耐压SBD“YQ系列”
- NOVOSENSE - 纳芯微推出车规级温湿度传感器NSHT30-Q1,助力汽车智能化发展
- Keysight - EV 电池设计创新:扩大续航里程、延长电池寿命