AVR query mode A/D conversion test program

Publisher:数字狂舞Latest update time:2016-10-22 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/*============================================================
File Name :main.c
illustrate:
1. Query mode A/D conversion test program
=============================================================*/
#include 
#include 
#define uchar unsigned char
#define uint unsigned int
uint AdcConvert(void)
{
 unsigned char i;
 unsigned int ret;
 ADMUX=0X40; //Internal 2.56V reference voltage, channel 0
 ADCSRA=_BV(ADEN); // Enable ADC, single conversion mode ADEN=7
 ADCSRA|=_BV(ADSC); //ADC starts converting ADSC=6
 while(ADCSRA&_BV(ADSC)) ; // Wait for the conversion to end
 right=ADCL;
 ret|=(uint)(ADCH<<8);
 ret=ret/4; // Convert 10 bits to 8 bits, and use 8 LEDs to display the result
 ADCSRA=0; // Turn off ADC
 return right;
}
int main(void)
{
DDRF=0x00;
DDRA=0XFF;
while(1)
{
PORTA=AdcConvert();
}
}
Keywords:AVR Reference address:AVR query mode A/D conversion test program

Previous article:BCD code conversion and calculation in the implementation of Mege16 AVR microcontroller
Next article:51. IO port operation of AVR and PIC

Recommended ReadingLatest update time:2024-11-16 12:56

PIC16F877A timing TMR0
The following experimental program is written to make the 8 LEDs on the RC port light up one by one, and then turn off one by one after all are lit, and repeat this cycle. The timer query method is used to control the delay, and the timer interrupt is not used. The interrupt program will be written above later.
[Microcontroller]
Decoding program for infrared coding chips such as AVR microcontroller uPD6121/AS6122
#include  #define uchar unsigned char     #define ulong unsigned long   /*------------------------------Display-----------------------------------*/   #define  LED _DATA PORTB   const uchar tab ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};   /*                        0 1 2 3 4 5 6
[Microcontroller]
BASCOM-AVR uses AVR-DOS library to read and write SD card
试验了用BASCOM读写SD卡,完全可以把SD卡当作磁盘来操作,与VB/QB语法兼容,编程非常简单。   AVR-DOS介绍   Features:            ·  Read and writeASCII-Files ·  Read and writeBinary-Files ·  Drivers available forCompact Flash Cards, Hard disk, MMC, SD etc. ·  Completly integrated inBASCOM-AVR Compiler ·  QB/VB compatible syntax ·  Completly written inAVR-Assem
[Microcontroller]
Samsung Galaxy A03s mobile phone FCC certification information: 5000mAh battery
      According to foreign media GSMArena, the FCC certification information of Samsung's upcoming Galaxy A03s mobile phone was recently exposed. The certification information shows that the phone has a 5000mAh battery.   IT Home learned that, combined with previous leaked information, the phone will be equipped wi
[Mobile phone portable]
Samsung Galaxy A03s mobile phone FCC certification information: 5000mAh battery
AVR's excellent C language programming style
There was a programming master who wrote unstructured programs. A beginner deliberately imitated him and also wrote unstructured programs. When he showed his progress to the master, the master criticized his unstructured program: "What is suitable for a programming master may not be suitable for a beginner. Before goi
[Microcontroller]
Leading Edge Equipment receives Series A funding
Leading Edge Equipment, a US company providing new technology for silicon wafer manufacturing, has announced that it has received $7.6 million in financing. The Series A round was led by Prime Impact Fund, with participation from previous investors Clean Energy Ventures and DSM Venturing. The company’s technology
[Semiconductor design/manufacturing]
Detailed explanation of the difference and selection skills between Avr and Stm32 in single chip microcomputer
The development of single-chip microcomputer is quite rapid. Now various manufacturers are competing fiercely in terms of speed, memory and function. At the same time, a large number of manufacturers with representative single-chip microcomputers have emerged: Atmel, TI, ST, MicroChip, ARM... The domestic Hongjing STC
[Microcontroller]
STC12C5A60S2 AD conversion details
The STC89LE516AD/X2 in the STC series of microcontrollers provides 8-channel 8-bit high-speed A/D converters, located on the P1 port, thus eliminating the trouble of an off-chip ADC. These 8-channel ADCs are voltage input type and can be used for key scanning, battery voltage detection, spectrum detection, etc. The AD
[Microcontroller]
STC12C5A60S2 AD conversion details
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号