




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
王健带你征服王健带你征服 AVR 单片机仿真第一课单片机仿真第一课 用法 用法 LCD init LCD write string 列列 行行 字符串字符串 LCD write char 列列 行行 字符字符 下面是下面是 AVR 与与 LCD 连接信息连接信息 PA2 RS PA3 EN 地地 RW PA4 D4 PA5 D5 PA6 D6 PA7 D7 要使用本驱动 改变下面配置信息即可要使用本驱动 改变下面配置信息即可 define LCD EN PORT PORTA 以下以下 2 个要设为同一个口个要设为同一个口 define LCD EN DDR DDRA define LCD RS PORT PORTA 以下以下 2 个要设为同一个口个要设为同一个口 define LCD RS DDR DDRA define LCD DATA PORT PORTA 以下以下 3 个要设为同一个口个要设为同一个口 define LCD DATA DDR DDRA 一定要用高一定要用高 4 位位 define LCD DATA PIN PINA define LCD RS 1 PA2 0 x04 portA2 out define LCD EN 1 PA3 0 x08 portA3 out define LCD DATA 1 PA4 1 PA5 1 PA6 1 PA7 0 xf0 portA4 5 6 7 out 函数说明函数说明 void LCD init void void LCD en write void void LCD write command unsigned char command void LCD write data unsigned char data void LCD set xy unsigned char x unsigned char y void LCD write string unsigned char X unsigned char Y unsigned char s void LCD write char unsigned char X unsigned char Y unsigned char data ifndef 1602 h define 1602 h include delay h void LCD init void 液晶初始化液晶初始化 LCD DATA DDR LCD DATA 数据口方向为输出数据口方向为输出 LCD EN DDR LCD EN 设置设置 EN 方向为输出方向为输出 LCD RS DDR LCD RS 设置设置 RS 方向为输出方向为输出 LCD write command 0 x28 LCD en write delay nus 40 LCD write command 0 x28 4 位显示位显示 LCD write command 0 x0c 显示开显示开 LCD write command 0 x01 清屏清屏 delay nms 2 void LCD en write void 液晶使能液晶使能 LCD EN PORT LCD EN delay nus 1 LCD EN PORT void LCD write command unsigned char command 写指令写指令 delay nus 16 LCD RS PORT RS 0 LCD DATA PORT 清高四位清高四位 LCD DATA PORT command 写高四位写高四位 LCD en write command command 4 低四位移到高四位低四位移到高四位 LCD DATA PORT 清高四位清高四位 LCD DATA PORT command 写低四位写低四位 LCD en write void LCD write data unsigned char data 写数据写数据 delay nus 16 LCD RS PORT LCD RS RS 1 LCD DATA PORT 清高四位清高四位 LCD DATA PORT data 写高四位写高四位 LCD en write data data 4 低四位移到高四位低四位移到高四位 LCD DATA PORT 清高四位清高四位 LCD DATA PORT data 写低四位写低四位 LCD en write void LCD set xy unsigned char x unsigned char y 写地址函数写地址函数 unsigned char address if y 0 address 0 x80 x else address 0 xc0 x LCD write command address void LCD write string unsigned char X unsigned char Y unsigned char s 列列 x 0 15 行行 y 0 1 LCD set xy X Y 写地址写地址 while s 写显示字符写显示字符 LCD write data s s void LCD write char unsigned char X unsigned char Y unsigned char data 列列 x 0 15 行行 y 0 1 LCD set xy X Y 写地址写地址 LCD write data data endif 延时函数 编译器 ICC AVR v6 31A 目标芯片 M16 时钟 8 0000Mhz void delay nus unsigned int n void delay nms unsigned int n void delay 1us void void delay 1ms void ifndef delay h define delay h void delay 1us void 1us 延时函数 asm nop void delay nus unsigned int n N us 延时函数 unsigned int i 0 for i 0 i n i delay 1us void delay 1ms void 1ms 延时函数 unsigned int i for i 0 i 1140 i void delay nms unsigned int n N ms 延时函数 unsigned int i 0 for i 0 i n i delay 1ms endif 函数说明 unsigned char get key void ifndef key h define key h unsigned char key read void unsigned char i 获取列地址 DDRB 0 xf0 高 4 位输出 低 4 位输入 PORTB 0 x0f 高 4 位输出 0 低 4 位带上拉输入 delay nms 1 i PINB 获取行地址 DDRB 0 x0f 高 4 位输入 低 4 位输出 PORTB 0 xf0 低 4 位输出 0 高 4 位带上拉输入 delay nms 1 i PINB switch i case 0 xff return 0 x00 case 0 xee return 0 case 0 xde return 1 case 0 xbe return 2 case 0 x7e return 3 case 0 xed return 4 case 0 xdd return 5 case 0 xbd return 6 case 0 x7d return 7 case 0 xeb return 8 case 0 xdb return 9 case 0 xbb return A case 0 x7b return B case 0 xe7 return C case 0 xd7 return D case 0 xb7 return E case 0 x77 return F default return 0 x00 unsigned char get key void unsigned char i static unsigned char j 按键记录 i key read if i 0 x00 无有效按键按下 j 0 x00 清除按键记录 return 0 x00 程序退出 if j 0 x00 为新按键 j i 保存本次结果 delay nms 10 延时去抖动 i key read if i j return i return 0 x00 endif include include include 1602 h include key h include uart h 主函数 void main void LCD init init USART ShowMenu 欢迎界面显示 while 1 Menu Change get key define Null 0 函数声明 void ShowMenu void void Menu Change unsigned char KeyNum 按键功能键宏定义 define UP 3 define Down 7 define Esc B define Enter F define Reset 0 目录结构体定义 struct MenuItem unsigned char MenuCount 当前层节点数 unsigned char DisplayString 菜单标题 void Subs 节点函数 struct MenuItem ChildrenMenus 子节点 struct MenuItem ParentMenus 父节点 调用子函数区 void NullSubs void 以下为例子 请根据实际情况修改 void TimeSet void put s TimeSet void DateSet void put s DateSet void AlertSet void put s AlertSet 结构体区 以下为例子 请根据实际情况修改 struct MenuItem TimeMenu 4 struct MenuItem FlashMenu 5 struct MenuItem VoiceMenu 5 struct MenuItem RobotMenu 5 struct MenuItem MainMenu 5 struct MenuItem TimeMenu 4 MenuCount DisplayString SubsChildrenMenus ParentMenus 4 1 Time Set TimeSet Null MainMenu 4 2 Date Set DateSet Null MainMenu 4 3 AlertSet AlertSet Null MainMenu 4 4 Back NullSubs MainMenu MainMenu struct MenuItem FlashMenu 5 MenuCount DisplayString SubsChildrenMenus ParentMenus 5 1 Flash Record NullSubs Null MainMenu 5 2 Play NullSubs Null MainMenu 5 3 Pause NullSubs Null MainMenu 5 4 Flash Delete NullSubs Null MainMenu 5 5 Back NullSubs MainMenu MainMenu struct MenuItem VoiceMenu 5 MenuCount DisplayString SubsChildrenMenus ParentMenus 5 1 Voice Record NullSubs Null MainMenu 5 2 Play NullSubs Null MainMenu 5 3 Pause NullSubs Null MainMenu 5 4 Voice Delete NullSubs Null MainMenu 5 5 Back NullSubs MainMenu MainMenu struct MenuItem RobotMenu 5 MenuCount DisplayString SubsChildrenMenus ParentMenus 5 1 Turn Left NullSubs Null MainMenu 5 2 Turn Right NullSubs Null MainMenu 5 3 Go Ahead NullSubs Null MainMenu 5 4 Go Back NullSubs Null MainMenu 5 5 Back NullSubs MainMenu MainMenu struct MenuItem MainMenu 5 MenuCount DisplayString SubsChildrenMenus ParentMenus 5 1 Time Set NullSubs TimeMenu Null 5 2 Voice Center NullSubs VoiceMenu Null 5 3 Robot Control NullSubs RobotMenu Null 5 4 Flash Option NullSubs FlashMenu Null 5 5 Back NullSubs MainMenu MainMenu 全局变量声明区 struct MenuItem MenuPoint MainMenu 结构体指针 指向结构体后由内部函 数指针指向功能函数 unsigned char DisplayStart 0 显示时的第一个菜单项 unsigned char UserChoose 0 用户所选菜单项 unsigned char DisplayPoint 0 显示指针 unsigned MaxItems 同级最大菜单数 unsigned char ShowCount 2 同屏显示菜单数 显示函数区 void ShowMenu void unsigned char n MaxItems MenuPoint 0 MenuCount 定义最大同级菜单 DisplayPoint DisplayStart for n 0 DisplayPoint MaxItems LCD write string 2 n MenuPoint DisplayPoint DisplayString void Menu Change unsigned char KeyNum if KeyNum switch KeyNum case UP UserChoose if UserChoose 255 UserChoose 0 上翻截至 如果要回滚赋值 MaxItems 1 break case Esc if MenuPoint UserChoose ParentMenus Null MenuPoint MenuPoint UserChoose ParentMenus UserChoose 0 DisplayStart 0 break case Down UserChoose if UserChoose MaxItems UserChoose MaxItems 1 下翻截至 如要回滚 赋值为 0 break case Enter if MenuPoint UserChoose Subs NullSubs MenuPoint UserChoose Subs else if MenuPoint UserChoose ChildrenMenus Null MenuPoint MenuPoint UserChoose ChildrenMenus UserChoose 0 DisplayStart 0 break case Reset MenuPoint MainMenu UserChoose 0 DisplayStart 0 break default break if UserChoose ShowCount 0 一
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 考点解析湖北省麻城市7年级上册期末测试卷章节练习试题(含答案解析)
- 大数据、“互联网+”和媒体融合试题(卷)答案解析
- 2025年基因治疗药物研发中的临床试验数据监管与合规性分析报告
- 2025年工业互联网在制造业中的应用前景与市场潜力分析报告
- 2025年沉浸式戏剧行业市场潜力与投资价值分析报告
- 2025年土壤污染监测物联网技术应用与治理策略报告
- 2025年快时尚在时尚零售行业变革中的产品包装设计趋势报告
- 2025年广播影视行业媒体融合技术发展趋势报告
- 2025至2030年中国人力资源数字化行业发展趋势预测及投资战略咨询报告
- 推拿治疗学试题附参考答案详解【考试直接用】
- 施工管理办法总则
- 【MOOC答案】《模拟电子电路实验》(东南大学)章节作业慕课答案
- 样品封存管理办法
- 海外仓合同范本
- 麻黄现行管理办法
- 北师大版(2024)七年级下册数学第四章 三角形 单元测试卷(含答案解析)
- 《研学旅行指导师实务》课件-第6章 基(营)地研学课程操作
- 膀胱炎护理课件
- 搅拌站建设可行性研究报告
- 插秧劳动指导课件
- 幕墙施工培训课件
评论
0/150
提交评论