A voltage detection meter made with an avr microcontroller with ADC

Publisher:光明2599Latest update time:2019-10-18 Source: eefocusKeywords:ADC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 

Voltmeter Effect


电路原理图如下:
 

单片机源码:
#include  
#include  

#define  uchar  unsigned char 
#define  uint   unsigned int 

void delayms(uint mS)        //微秒                  
{
        uint i,j;
        for( i=0;i                for(j=0;j<200;j++);        
}

unsigned char disp[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
                        0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};

uint ADC_Value; 

void port_init(void) 

   DDRD = 0xff; 
   PORTD= 0x00; 
   DDRE = 0xff; 
   PORTE= 0x00; 
   DDRF = 0x00; 
   PORTF= 0x00; 


void adc_init(void) 

   ADMUX = 0x00; 
   ADCSRA= 0x00; 
   ACSR  =1<   ADMUX =(1<   ADCSRA=(1<

uint ADC_read(void) 

   uint ADC_L,ADC_H,temp; 
   ADCSRA |= (1<<ADSC); 
   ADC_L = ADCL; 
   ADC_H = ADCH; 
   temp  = (ADCH<<8)|ADC_L; 
   return temp; 


uint  convert(uint data) 

   long temp1; 
   uint temp2; 
   temp1 = ((500 * (long)data)>>10);
   temp2 = (uint)temp1; 
   return temp2; 


void main(void)  
  { 
     uint voltage; 
     uchar n;
     port_init(); 
     adc_init(); 
        
         DDRA=0XFF;
         PORTA=0XFF;
        
         DDRC=0XFF;                         
         PORTC=0X00;
         
         DDRF|=0X0E;
         PORTF|=0X0E;
         PORTF&=0xF7;                      
                            
         PORTA=0X00;                       
         
         DDRB |=0X10;                      
         PORTB|=0X10;                      

    while(1)   
    { 
       ADC_Value = ADC_read();         //读取AD寄存器中的数值 
       voltage   = convert(ADC_Value); //计算实际的输入电 
       for(n=0;n<50;n++)
           display(voltage);               //显示 
   }


Keywords:ADC Reference address:A voltage detection meter made with an avr microcontroller with ADC

Previous article:ATmega16 Minimum System Hardware Design
Next article:AVR M16 MCU NRF2401 Wireless Communication Development Kit

Recommended ReadingLatest update time:2024-11-15 15:05

How to solve the problem of wrong fuse position during AVR microcontroller programming
In the process of burning AVR microcontrollers, it is inevitable that the fuse position is wrong, and the result is that the AVR microcontroller cannot be read or written! What should we do at this time? Throw away the expensive chip and use a new one. In fact, this is generally unnecessary. The reason why the microco
[Microcontroller]
How to solve the problem of wrong fuse position during AVR microcontroller programming
ADC0809 Conversion Program
Block Diagram Circuit   program                             ORG 05A0H 05A0    758153      SE11:  MOV    SP,#53H 05A3    757E00              MOV    7EH,#00H 05A6 757D08 MOV 7DH, #08H 05A9    757C00              MOV    7CH,#00H 05AC 757B09 MOV 7BH,#09H 05AF    757A10              MOV    7AH,#10H 05B2 757910 MOV 79
[Microcontroller]
ADC0809 Conversion Program
Introduction to the driving capability of AVR single-chip I/O port
  The I/O drive capability of AVR microcontrollers is first-class among 8-bit microcontrollers. You should carefully read the electrical specifications and typical characteristics in the AVR device manual. (By the way, are there any 8-bit microcontrollers with more device manuals than AVR? And which provide very detail
[Microcontroller]
Introduction to the driving capability of AVR single-chip I/O port
AVR32 portable wireless medical drip monitoring system
introduction   Intelligence and portability are the development trends of modern electronic products. The intelligence of medical electronics makes the operation of medical staff more convenient. Medical staff can carry a handheld monitor to monitor the drip in each ward in real time and keep abreast of relevant s
[Microcontroller]
AVR32 portable wireless medical drip monitoring system
IAR for AVR—Software Application—IAR For AVR implements array function call—04
//------------------------------------------------------------------------------ //LCD displays multiple bytes function void lcd_display_chars(uchar add,uchar __flash *s,uchar num) {   uchar i;   lcd_write_command(add);   for(i=0;i num;i++)   {     lcd_write_data(s );     delay_ms(1);   } } Of ​​course, you can just d
[Microcontroller]
Use Atmel Studio7 and USBasp to burn AVR microcontroller
Many tutorials provide the use of Atmel Studio and MKII to burn AVR microcontrollers, but the most popular burner used by the public is the inexpensive USBasp, which is much more affordable at around 10 yuan than the 200 yuan MKII. However, USBasp cannot be used directly for burning in Atmel Studio, so other software
[Microcontroller]
Use Atmel Studio7 and USBasp to burn AVR microcontroller
Contactless ID card program (AVR and em4095)
/* After extracting the synchronous clock signal, the data can be extracted by detecting the time interval between two rising edges (or falling edges). There are three time intervals between two rising edges (or falling edges): t=T', t=1.5T', and t=2T'.  If the interval between two rising edges is t=T', a data with t
[Microcontroller]
How to Improve High-Speed ​​ADC Clock Signals
It is normal to expect performance that matches the datasheet signal-to-noise ratio (SNR) value when you use a high-speed analog-to-digital converter (ADC). When you test the SNR of an ADC, you might connect a low-jitter clock device to the converter's clock input pins and apply a reasonably low-noise input signal. If
[Power Management]
How to Improve High-Speed ​​ADC Clock Signals
Latest Microcontroller Articles
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号