




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
最小系统板测试程序 二极管闪烁 串口接收 中断方式 发送 查询方式 外部 RAM 的读写 include include include define low XBYTE 0 xe000 define high XBYTE 0 xfff0 sbit LED P1 3 发光二极管连接于 P1 3 24C64 接口引脚定义 sbit WP P1 0 sbit I2C SCK P1 1 sbit I2C SDA P1 2 void Delay 10 uS void bit I2C Start void void I2C Stop void void I2C Ack void void I2C Nack void bit I2C Send Byte unsigned char d unsigned char I2C Receive Byte void void AT24C64 W unsigned char mcu address unsigned int AT24C64 address unsigned int count void AT24C64 R unsigned char mcu address unsigned int AT24C64 address unsigned int count unsigned char DataBuf 8 0 bit flag 0 void init all void SCON 0 x50 SCON serail mode 1 8 bit UART enable ucvr TMOD 0 x20 TMOD timer 1 mode 2 8 bit reload PCON 0 x00 SMOD 0 TH1 0 xFD Baud 9600 fosc 11 0592MHz IE 0 x90 Enable Serial Interrupt TR1 1 timer 1 run 向串口发送一个字符 void send char com unsigned char ch SBUF ch while TI 0 TI 0 串口接收中断函数 void serial interrupt 4 using 3 if RI unsigned char ch RI 0 ch SBUF if ch 0 xAA flag 1 else flag 0 外部 RAM 读写测试 void exram wr void unsigned char i j unsigned char xdata low 0 xD020 指针指向 2000H 单元 unsigned char xdata high 0 xF000 指针指向 2000H 单元 写 0 xE000 0 xE00F 单元 for i 0 i 16 i low 0 xf0 i low 将 0 xE000 0 xE00F 单元的数据读出 并存入 0 xF000 0 xF00F 单元 low 0 xD020 for i 0 i 16 i j low low high j high I2C 测试程序 void I2C WR void unsigned char i WP 0 DataBuf 0 2 DataBuf 1 3 AT24C64 W DataBuf 0 2 Delay 10 uS DataBuf 0 34 DataBuf 1 56 AT24C64 R DataBuf 0 2 for i 0 i 2 i SBUF DataBuf i while TI 0 TI 0 main LED 0 init all I2C WR exram wr while 1 LED 1 发光二极管点亮 if flag 1 send char com 0 xbb flag 0 LED 0 发光二极管熄灭 24C64 子程序 void Delay 10 uS void char i 10 while i bit I2C Start void Delay 10 uS I2C SDA 1 Delay 10 uS I2C SCK 1 Delay 10 uS if I2C SDA 0 return 0 if I2C SCK 0 return 0 I2C SDA 0 Delay 10 uS I2C SCK 0 Delay 10 uS return 1 void I2C Stop void Delay 10 uS I2C SDA 0 Delay 10 uS I2C SCK 1 Delay 10 uS I2C SDA 1 Delay 10 uS void I2C Ack void Delay 10 uS I2C SDA 0 Delay 10 uS I2C SCK 1 Delay 10 uS I2C SCK 0 Delay 10 uS void I2C Nack void Delay 10 uS I2C SDA 1 Delay 10 uS I2C SCK 1 Delay 10 uS I2C SCK 0 Delay 10 uS bit I2C Send Byte unsigned char d unsigned char i 8 bit bit ack while i Delay 10 uS if d else I2C SDA 0 Delay 10 uS I2C SCK 1 Delay 10 uS I2C SCK 0 d d 1 Delay 10 uS I2C SDA 1 Delay 10 uS I2C SCK 1 Delay 10 uS bit ack I2C SDA I2C SCK 0 Delay 10 uS return bit ack unsigned char I2C Receive Byte void unsigned char i 8 d Delay 10 uS I2C SDA 1 while i d d 1 Delay 10 uS I2C SCK 1 if I2C SDA d Delay 10 uS I2C SCK 0 return d void AT24C64 W unsigned char mcu address unsigned int AT24C64 address unsigned int count unsigned int i while count I2C Start I2C Send Byte 0 xa0 AT24C64 address 256 2 24C16 USE I2C Send Byte 0 xa0 I2C Send Byte AT24C64 address 256 高 5 位地址 I2C Send Byte AT24C64 address 256 低 8 位地址 I2C Send Byte unsigned char mcu address 字节所在位置 I2C Stop for i 0 i 100 i Delay 10 uS waiting for write cycle to be completed unsigned char mcu address AT24C64 address void AT24C64 R unsigned char mcu address unsigned int AT24C64 address unsigned int count while count I2C Start I2C Send Byte 0 xa0 AT24C64 address 256 2 24C16 USE I2C Send Byte 0 xa0 I2C Send Byte AT24C64 address 256 I2C Send Byte AT24C64 address 256 I2C Start I2C Send Byte 0 xa1 AT24C64 address 256 2 I2C Send Byte 0 xa1 unsigned char mcu address I2C Receive Byte I2C Nack I2C Stop unsigned char mcu address AT24C64 address 测试 7279 include include 函数定义 void long delay void 长延时 void short delay void 短暂延时 void delay10ms unsigned char 延时 10MS void write7279 unsigned char unsigned char 写入到 HD7279 unsigned char read7279 unsigned char 从 HD7279 读出 void send byte unsigned char 发送一个字节 unsigned char receive byte void 接收一个字节 变量及 I O 口定义 unsigned char key number i unsigned int tmr sbit key P1 4 key 连接于 P1 3 sbit cs P1 5 cs 连接 P1 4 sbit clk P1 6 clk 连接于 P1 5 sbit dat P1 7 dat 连接于 P1 2 HD7279A 指令 define CMD RESET 0 xa4 复位 清除 指令 define CMD TEST 0 xbf 测试指令 define DECODE0 0 x80 方式 0 译码 define DECODE1 0 xc8 方式 1 译码 define CMD READ 0 x15 读键值指令 define UNDECODE 0 x90 不译码 define RTL CYCLE 0 xa3 循环左移指令 define RTR CYCLE 0 xa2 循环右移指令 define RTL UNCYL 0 xa1 左移指令 define RTR UNCYL 0 xa0 右移指令 define ACTCTL 0 x98 消隐指令 define SEGON 0 xe0 段点亮指令 define SEGOFF 0 xc0 段关闭指令 define BLINKCTL 0 x88 闪烁指令 主程序 main while 1 for tmr 0 tmr 0 x200 tmr 上电延时 send byte CMD RESET 复位 HD7279A send byte CMD TEST 测试指令 delay10ms 100 send byte CMD RESET 清除显示 译码方式 1 测试 利用 SEG7 显示 for i 0 i 16 i write7279 DECODE1 7 j 译码方式 1 指令 显示在第 8 位 delay10ms 50 键盘接口测试 读键指并在第 6 7 位数码管显示 key number 0 xff while 1 if key 如果有键按下 key number read7279 CMD READ 读出键码 write7279 DECODE1 7 key number 16 在第 7 位显示键码高 8 位 write7279 DECODE1 6 key number 在第 6 位显示键码低 8 位 while key 等待按键放开 HD7279A 函数库 void write7279 unsigned char cmd unsigned char dta send byte cmd send byte dta unsigned char read7279 unsigned char command send byte command return receive byte void send byte unsigned char out byte unsigned char i cs 0 long delay for i 0 i 8 i if out byte else dat 0 clk 1 short delay clk 0 short delay out byte out byte 2 dat 0 unsigned char receive byte void unsigned char i in byte dat 1 set to input mode long delay for i 0 i 8 i clk 1 short delay in byte in byte 2 if dat in byte in byte
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人教版七年级地理期末模拟试题(带解析)
- 2025年新型聚合物驱油剂项目提案报告
- 2025年数控刃磨床项目申请报告
- 2025年薄膜电容器项目立项申请报告
- 低渗粉砂质水合物沉积物气水渗流特性研究
- 基于原位监测技术研究地质高背景区土壤-水稻系统中镉的解吸迁移及其调控机制
- 生物质基气敏型食品新鲜度指示膜的制备及性能研究
- 基于胜任力模型的JSZY公司烟叶采购人员培训管理优化研究
- 基于深度学习的ISAR成像及其质量评估方法研究
- 城市抗震韧性综合评价方法研究
- 2025年 道路运输企业主要负责人考试模拟试卷(100题)附答案
- 2025至2030中国执法系统行业经营效益及前景运行态势分析报告
- 供应链公司展会策划方案
- 南通市崇川区招聘 社区工作者笔试真题2024
- 2025年广东省万阅大湾区百校联盟中考二模语文试题(含答案)
- 【艺恩】出游趋势洞察报告
- 护士理论考试试题及答案
- 学生因病缺课管理制度
- 2025年江苏省苏州园区星海中考英语二模试卷
- 关于邮政代理金融业务发展转型的思考
- 五年级下册心理健康教育课教学总结
评论
0/150
提交评论