Making a Voltage Meter Using AVR Microcontroller

Publisher:omicron25Latest update time:2015-06-24 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Through research and experimentation, it is possible to produce 5V voltage using mega16. The voltage value is displayed by LED.

Below is part of the source code:
uint mega16_ad()
{
     uint addata;
  DDRD|=BIT(4)|BIT(5)|BIT(6);  
  DDRA&=~BIT(PA3);
  PORTA&=~BIT(PA3);
  ADMUX=0x03;
  ADCSR=0X80;//enable conversion
  ADCSR|=BIT(ADSC);//start conversion
  while(!(ADCSR&(BIT(ADIF))));//wait for conversion to end.
  addata=ADC*4.8876; //Convert to four-bit 5V voltage number
  return addata;
}  

     
void main()
{   
     uint ada;  
  while(1)
  {
      ada=mega16_ad(); 
       if(ada>2500)
   PORTD&=~BIT(2);// LED1 lights up when the voltage
value is greater than 2.5V    else
   PORTD|=BIT(2 ); //Otherwise LED1 goes off
   
   show(4,ada%10); 
   delay(1);
   ada=ada/10;  
   show(3,ada%10);
   delay(1);
   ada=ada/10; 
   show(2 ,ada%10);
   delay(1);
   ada=ada/10;
   showdian(1,ada%10);   
  }

}

Keywords:AVR Reference address:Making a Voltage Meter Using AVR Microcontroller

Previous article:Ideas of using AVR microcontroller to make electronic bell
Next article:AVR microcontroller serial port baud rate setting

Recommended ReadingLatest update time:2024-11-16 13:32

AVR MCU ATMEGA16 1602 LCD driver and experience
I developed my own AVR microcontroller chip development board, and the 1602 LCD screen experiment was successful! I was very pleased. I wrote the program for a whole day, and repeated the experiment, and finally succeeded at 0:00 am.      During this process, the biggest problem was the so-called matching 1602 LCD scr
[Microcontroller]
AVR microcontroller eight-bit water light program
Eight-bit running light program The microcontroller source program is as follows: #include iom16v.h #define uint unsigned int #define uchar unsigned char void Delay_ms(uint k) {          uint i,j;          for(;k 0;k--)                  for(i=142;i 0;i--)                         for(j=2;j 0;j--); } void port_init
[Microcontroller]
AVR Development Arduino Method (Part 2) Interrupt Subsystem
Before understanding the interrupt subsystem, we must first understand the concept of interrupts. You are reading a book and the phone rings. What will you do? I believe most people will do this: mark the position you are reading first, and then continue reading after answering the phone. This is an example of an inte
[Microcontroller]
Design of Natural Gas Engine System Based on AVR Single Chip Microcomputer
 1 Fuel supply system     The modification of the original engine mainly involves the modification of the fuel supply and injection system, and a complete natural gas supply system and electronic control system are used to achieve the modification purpose. The natural gas used is compressed natural gas provided by
[Microcontroller]
Design of Natural Gas Engine System Based on AVR Single Chip Microcomputer
AVR bit manipulation
1. Plan 1 1. #ifndef _M16_BIT_OPERATION_H_ #define _M16_BIT_OPERATION_H_ //Define a macro with parameters to replace the bit field structure for easy use #define BITFIELD(addr) (*((volatile bit_field *)(addr))) //Bit field definition structure typedef struct _bit_struct { unsigned Bit0:1; unsigned Bit1:1; unsign
[Microcontroller]
Analysis of the advantages and disadvantages of AVR microcontrollers
Introduction: AVR microcontroller is an enhanced RISC (Reduced Instruction Set CPU) high-speed 8-bit microcontroller with built-in Flash developed by ATMEL in 1997. AVR microcontrollers can be widely used in various fields such as computer peripherals, industrial real-time control, instrumentation, communication equip
[Microcontroller]
AVR microcontroller serial port USART and PC communication example, explain the principle and procedure
"Parallel" communication: refers to the transmission of 8 bits of data through parallel lines at the same time. This greatly increases the data transmission speed, but the length of the parallel transmission line is limited. As the length increases, interference will increase, and data will be more prone to errors.
[Microcontroller]
AVR microcontroller serial port USART and PC communication example, explain the principle and procedure
Introduction to the application example of single-button switch circuit based on AVR microcontroller
1 Introduction The single-key switch circuit has been widely used in digital products such as PDA, mobile phones and electronic dictionaries. There are many ways to implement it. Generally, RS triggers, counters and 555 integrated circuits can be used. In some practical applications of single-chip mic
[Microcontroller]
Introduction to the application example of single-button switch circuit based on AVR microcontroller
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号