/* Copyright (c) 2006, Spruha Electronic Systems
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* This Program is to be used with AVRTRN Microcontroller Kit from Spruha Electronic Systems
Program Tests the ADC Channel e.g. Channel 1. PA0 PIN 40 of ATMega16.
Connect the Shorting Link near PORTA Header. This Connects Pin 40 PA0 to the Multiturn Potentiometer.
Connect PORTB to LCDPORT by 10 core Cable. This connects the LCD Display to PORTB.
Connect the PC COM Port to the RS232 PORT of the Kit by the Cable provided.
The include files LCD.C, UART.C, DIGITAL_DISPLAY.c are in the directory \include.
The Program measures the Voltage by converting the Analog Voltage to Digital. The ADC here is 10 Bit.
The ADC Count is converted to give Display in Volts. The Internal Reference of 5v is used.
The Output is Displayed on the LCD. If the Digital Display ( Optional Peripheral ) is present the
voltage is Displayed on the Digital Display Card. The Voltage value is also sent to PC through RS232 PORT.
The Hex Count is Displayed on the Top Line and the corrosponding calculated Voltage is displayed on
second line.
*/
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "include\uart.c"
#include "include\lcd.c"
#include "include\digital_display.c"
#define TOLERANCE 4//0//2//10
int mod(int m);
void ADC_Display(unsigned char adc_pin);
void dis_num(int p,char* dis);
void dis_num_lcd(int p,char* lcddis);
void dis_hex(int p,char* lcddis);
void delay1(int );
void delay(uint32_t);
int main(void)
{
char lcddis[7];
char dis[5]="0000";
unsigned short full=55;
unsigned short old=44,lastlast=99;
unsigned char adc_pin=0;
int k;
long int temp;
union _adc_data {
unsigned char dt[2];
unsigned short data;
} adc_data;
dis_string(dis);//Display Data 0000 on the Digital Display
lcd_init();//initialize the LCD Display Unit
uart_init();//Initialize the UART. Set Baud Rate
uart_puts("SPRUHA ADC TEST");//Send String to RS232 Port
uart_putc(13);
uart_putc(10);
ADMUX = (0x40 + adc_pin);//Set Channel 1 of ADC i.e. PA0
while(1)
{
ADCSR = 0xC0; //Control Word And SOC (using divisor of 2)
loop_until_bit_is_set ( ADCSR, ADIF ); //Wait For EOC or while(ADIF==0)
adc_data.dt[0] = ADCL;//full 8bit Read Lower Byte
adc_data.dt[1] = ADCH; //lsb 2 Read Higher Byte
full=adc_data.data & 0x03ff;
if(mod(full-old)>TOLERANCE)//Two samples are compared and displayed only if the Difference is
old=full; //more than TOLERANCE. Here TOLERANCE set as 4. This is to avoid Flickering on the Display
else if(mod(lastlast-full)>TOLERANCE)
{
lastlast=full;
dis_hex(full,lcddis);
lcd_curpos(0);
lcd_string("ADC HEX = ");
lcd_curpos(10);
lcd_string(lcddis);//Displays Hex Count on the 1st Line of LCD
uart_puts(lcddis);//sends the Hex Count on RS232 UART
temp=(long)full*500;//Count Conversion to volt value. 1023=5v
temp/=1023;
k=(int)temp;
dis_num(k,dis);
dis_num_lcd(k,lcddis);
lcd_curpos2L(0);
lcd_string("ADC VOLT: ");
lcd_curpos2L(10);
lcd_string(lcddis);//Displays Voltage on the 2nd Line of LCD
uart_puts(lcddis);//sends the Voltage value on RS232 UART
uart_putc(13);
uart_putc(10);
}
}
}
/**************************************************************************************************
* ADMUX - Multiplexer Selection Register
* 7 6 5 4 3 2 1 0
* REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0
*
* REFS1 REFS0
* 0 0 - AREF, Internal Vref Turned off
* 0 1 - AVCC with external capacitor at AREF pin
* 1 0 - Reserved
* 1 1 - Internal 2.56V voltage reference with external capacitor at AREF pin
*
* ADLAR - Affects the presentation of the ADC conversion result 0=Right Adjusted, 1=Left Adjusted
* MUX4 to MUX0 - Analog channel and Gain selection bits
* Our value is 0100XXXX i.e. 0x4X
**************************************************************************************************
* ADCSR - ADC Control & Status Register
* 7 6 5 4 3 2 1 0
* ADEN ADSC ADATE ADIF ADIE ADSP2 ADSP1 ADSP0
*
* ADEN - ADC Enable
* ADSC - ADC Start Of Conversion
* ADATE - ADC Auto Trigger Enable (on +ive edge)
* ADIF - ADC End Of Conversion (set to High on EOC)
* ADIE - ADC Interrupt Enable
* ADSP2 to ADSP0 - Division Factor between XTAL and internal clock of ADC
* :. our contorl word is 11000000 i.e. 0xC0
**************************************************************************************************/
void delay(uint32_t us)
{
while ( us ) us--;
}
void delay1(int num1)
{
int i;
for(i=0;i<num1;i++)
delay(28000);
}
/* in dis_num you send the integer and the pointer to the string i.e. dis
the dis_string(dis); will then send the number to the digital display.
This subroutine converts the Number into string with ASCCI value
*/
void dis_num(int p,char* dis)
{
int i,j=1000;
for(i=0;i<4;i++)
{
dis[i]=(p/j)%10+'0';
j/=10;
}
dis[4]=0;
dis_string(dis);
}
/* in dis_num_lcd you send the integer and the pointer to the string
the lcd_string(lcddis); will then print the Number with decimal.
In lcddis[0], lcddis[1] msb two digits in lcddis[2] '.' and lcddis[3] and lcddis[4]
lsb two digits and lcddis[5]=' ' lcddis[6]=NULL are put.
This subroutine converts the Number into string with decimal after two digits
in ASCCI.
*/
void dis_num_lcd(int p,char* lcddis)
{
int i,j=1000;
for(i=0;i<2;i++)
{
lcddis[i]=(p/j)%10+'0';
j/=10;
}
lcddis[2]='.';
for(i=3;i<5;i++)
{
lcddis[i]=(p/j)%10+'0';
j/=10;
}
lcddis[5]=' ';
lcddis[6]=0;
}
/* in dis_hex you send the Hex Value and the pointer to the string
the lcd_string(lcddis); will then print the Number.
This subroutine converts the Hexadecimal Number into string with ASCCI value
*/
void dis_hex(int p,char* lcddis)
{
int i;
lcddis[0]=p/256;
lcddis[1]=(p/16)%16;
lcddis[2]=p%16;
for(i=0;i<3;i++)
if(lcddis[i]<=9)
lcddis[i]+='0';
else
lcddis[i]+=0x37;
lcddis[3]=' ';
lcddis[4]=' ';
lcddis[5]=' ';
lcddis[6]=0;
}
int mod(int m)
{
if(m>0)
return m;
else
return (-m);
}
没有合适的资源?快使用搜索试试~ 我知道了~
adc.rar_Free!_adc 10 bit atmega16_adc using avr_atmega16 adc
共14个文件
c:4个
h:3个
hex:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 72 浏览量
2022-09-21
06:00:58
上传
评论
收藏 42KB RAR 举报
温馨提示
This program is written in C for AVR Microcontrollers. It is to be compiled witn GCC compiler which is available for Free. The Program is for learning and using ADC ( 10 Bit) available in AVR Atmega16.
资源推荐
资源详情
资源评论
收起资源包目录
adc.rar (14个子文件)
adc
adc.lst 79KB
adc.pnproj 104B
adc.map 17KB
include
lcd.c 5KB
lcd.h 2KB
digital_display.h 2KB
uart.h 2KB
uart.c 6KB
digital_display.c 2KB
adc.c 7KB
adc.hex 6KB
adc.o 13KB
Makefile 2KB
adc.elf 13KB
共 14 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 91
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 自定义 带时间 戳的 ping 命令
- 害虫数据集YOLOv9标记 9771张图片,可识别稻秆蝇 亚洲稻螟 棕色飞虱 谷物传播蓟马 蛴螬 蝼蛄 稻蛆 稻瘿蚊 稻叶毛虫 稻纵卷叶螟 稻叶蝉 稻壳虫 米水象鼻虫 小褐飞虱 白背飞虱 水稻三化螟
- 基于YOLOV5火灾火焰烟雾检测源码+数据集+训练好的模型-火灾火焰烟雾检测源码+数据集+训练好的模型
- 基于opencv绘图框架的A*算法可视化实现
- 自定义 带时间 戳的 ping 命令
- StockMatchs子项目,模拟的股票交易系统go语言实现,基于http的jsonrpc接口通信.zip
- 公司面试题记录汇总11
- SQuant是使用scala语言编写的量化开发工具箱,提供开箱即用的A股股票数据和外汇数据(docker镜像),以及高效的回测框架与交易模块 方便Java,Scala爱好者进行量化投资研究 .zip
- 面向云端优化的弹性与可扩展高性能计算传输协议SRD
- C# WInForm IrisSkin4控件ssk皮肤
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功