匿名
未登录
登录
丢石头百科
搜索
查看“AVR AD转换 中断”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
AVR AD转换 中断
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<table border="0" cellpadding="0" cellspacing="0" width="780"><tr><th class="type_483D8B" scope="col" style="font-size: 12px; line-height: 20px; font-weight: normal; border-top-style: none; color: rgb(72, 61, 139);" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">系统功能</th></tr></table><br/> <span class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">大部分AVR内部带有AD,本节以使用ATMEGA16的内部AD为例,给出AD转换中断程序。</span><br/> <br/></div></th></tr><tr><th class="type_483D8B" scope="col" style="font-size: 12px; line-height: 20px; font-weight: normal; border-top-style: none; color: rgb(72, 61, 139);" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">硬件设计</th></tr></table><p align="center">[[File:AVR_AD转换_中断-0.jpg|400px]]<br/>AVR主控电路原理图(点击图片放大,不需要放大镜![[File:AVR_AD转换_中断-1.gif|400px]])<br/>[[File:AVR_AD转换_中断-2.jpg|400px]] <br/>AD转换值低位,LED控制电路原理图(点击图片放大,不需要放大镜![[File:AVR_AD转换_中断-1.gif|400px]]) <br/>[[File:AVR_AD转换_中断-4.jpg|400px]]<br/>AD转换值高位,LED控制电路原理图(点击图片放大,不需要放大镜![[File:AVR_AD转换_中断-1.gif|400px]]) <br/><br/></p></div></th></tr><tr><th class="type_483D8B" scope="col" style="font-size: 12px; line-height: 20px; font-weight: normal; border-top-style: none; color: rgb(72, 61, 139);" valign="top"><div align="left"><table border="0" cellpadding="0" cellspacing="0" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">软件设计</th></tr></table><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">下面部分从TXT拷出,拷到网页,代码部分缺省了很多空格,比较凌乱,请谅解!</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">//目标系统: 基于AVR单片机<br/>//应用软件: ICC AVR</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">/*01010101010101010101010101010101010101010101010101010101010101010101<br/>----------------------------------------------------------------------<br/>实验内容:<br/>使用中断检测AD0口,使用PB/PD口的LED指示AD读到的数据。<br/>----------------------------------------------------------------------<br/>硬件连接:<br/>将“ADJ0.AD0”引针与“MCU.AD0” 引针使用短路帽短接。<br/>将PB/PD口的LED指示灯使能开关切换到"ON"状态。<br/>----------------------------------------------------------------------<br/>注意事项: <br/>(1)若有加载库程序,请将光盘根目录下的“库程序”下的“ICC_H”文件夹拷到D盘<br/>(2)请详细阅读:光盘根目录下的“产品资料\开发板实验板\SMK系列\SMK1632\说明资料”<br/>----------------------------------------------------------------------<br/>10101010101010101010101010101010101010101010101010101010101010101010*/</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">#include <iom16v.h><br/>#include "D:\ICC_H\CmmICC.H"</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">#define H_VAL_DISP_DDR DDRD<br/>#define L_VAL_DISP_DDR DDRB<br/>#define H_VAL_DISP_PORT PORTD<br/>#define L_VAL_DISP_PORT PORTB</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">const uint8 ADEnStatus[8] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">uint8 AdcMux; //ADC通道<br/>uint16 AdcVal; //ADC转换值</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">/*--------------------------------------------------------------------<br/>程序名称:AD转换初始化程序<br/>程序功能:<br/>注意事项:<br/>提示说明:<br/>输 入:<br/>返 回:<br/>--------------------------------------------------------------------*/<br/>void adc_init()<br/>{<br/>/* 设置对应的IO口为输入高阻态 */<br/> DDRA &= ADEnStatus[AdcMux]; <br/> PORTA &= ADEnStatus[AdcMux];</p><p class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;"> ADCSRA = 0x00; //disable adc<br/> ADMUX = (1<<REFS1)|(1<<REFS0)|(AdcMux&0x0F); //select adc input channel<br/> ACSR = (1<<ACD); //close analog comparator<br/> ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1); <br/>}<br/>/*--------------------------------------------------------------------<br/>程序名称:AD转换中断服务程序<br/>程序功能:<br/>注意事项:<br/>提示说明:<br/>输 入:<br/>返 回:<br/>--------------------------------------------------------------------*/<br/>#pragma interrupt_handler adc_isr:15<br/>void adc_isr(void)<br/>{<br/> AdcVal = ADC&0x3FF;<br/> ADMUX = (1<<REFS0)|(AdcMux&0x0F); //使用 AVcc 作为ADC参考电源<br/> ADCSRA |= (1<<ADSC); //ADSC: AD start conversion<br/>}<br/>/*--------------------------------------------------------------------<br/>程序名称:<br/>程序功能:<br/>注意事项:<br/>提示说明:<br/>输 入:<br/>返 回:<br/>--------------------------------------------------------------------*/<br/>void main(void)<br/>{<br/> H_VAL_DISP_DDR = 0xFF;<br/> L_VAL_DISP_DDR = 0xFF;<br/> AdcMux = 0; //使用ADC通道0<br/> adc_init(); <br/> SEI(); <br/> while(1)<br/> { <br/> H_VAL_DISP_PORT = (AdcVal&0x300)>>8; //ADC的高2位Val<br/> L_VAL_DISP_PORT = AdcVal&0xFF; //ADC的低8位Val<br/> }<br/>}</p><p></p><p></p><p></p></div></th></tr><tr><th class="type_483D8B" scope="col" style="font-size: 12px; line-height: 20px; font-weight: normal; border-top-style: none; color: rgb(72, 61, 139);" valign="top"><div align="left"><br style="font-family: Arial, 新宋体, 微软雅黑;"/><table border="0" cellpadding="0" cellspacing="0" style="color: rgb(72, 61, 139); font-family: Arial, 新宋体, 微软雅黑; font-size: 12px; line-height: 20px;" width="120"><tr><th bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="color: rgb(255, 255, 255); font-family: Arial, Helvetica, sans-serif;">系统调试</th></tr></table><p style="font-family: Arial, 新宋体, 微软雅黑;">用LED显示AD转换值,调“<span class="type_666666_12px" style="color: rgb(102, 102, 102); border-top-style: none; font-family: Arial, Helvetica, sans-serif;">ADJ0.AD0</span>”的可调电阻可改变AD转换值,观察它的变化。</p><div><br/></div></div></th></tr></table>
返回至
AVR AD转换 中断
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志