atmega8 routine: query mode AD acquisition

Publisher:数字航海家Latest update time:2016-12-29 Source: eefocusKeywords:atmega8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/****************************************************** ********** 

* Function library description: ATMEGE8 AD analog-to-digital conversion                         

* Version: v1.0                                                                           

*                                                           

* Description: Query method AD collection 

*                                                           

* Version update: See readme.txt for details                                             

       

*************************************************** ********** 

*Note: res PC5  

* CE PB0 

* RST PB1 

* DC PB2 

* SDIN PB3 

* SCLK PB4                                          

*************************************************** *********/  

  

  

#include "includes.h"  

  

/****************************************************** ********** 

** Name: void AD_Init(void) 

** Function: AD initialization 

** Input parameters: None 

** Export parameters: None 

** Instructions for use: None 

*************************************************** **********/  

void AD_Init(void)  

{  

    //Reference voltage AREF, left aligned, ADC5 single-ended input   

    ADMUX |= (1 << ADLAR) | (1 << MUX2) | (1 << MUX0);   

    //AD enabled, continuous conversion, interrupt disabled, 32 division, 6M / 32 = 187.5khz  

    ADCSRA |= (1 << ADEN) | (1 << ADFR) | (1 << ADPS2) | (1 << ADPS0);  

    //AD starts conversion  

    ADCSRA |= (1 << ADSC);        

}  

  

int main(void)  

{  

    int result = 0;  

    char buf[] = "5.00V";  

      

    LCD_Init();  

    AD_Init();  

    LCD_Write_Chinese_String(0, 0, 12, 5, Chinese_Font, 0, 0);  

      

  

    while(1)  

    {  

        while((ADCSRA & (1 << ADIF)) == 0);  

        //Read the converted value  

        result = ADCH;  

        result = result * 500.0 / 255;  

          

        //Data Update  

        buf[0] = result / 100 + '0';  

        buf[2] = result / 10 % 10 + '0';  

        buf[3] = result % 10 + '0';  

          

        //Data Display  

        LCD_Write_English_String(0, 3, buf);  

    }  

      

    return 0;  

}  


Keywords:atmega8 Reference address:atmega8 routine: query mode AD acquisition

Previous article:atmega8 routine: AD interrupt mode acquisition
Next article:Introduction to AVR I/O drive capabilities

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

ATmega88 watchdog reset
When the watchdog timer overflows, a reset pulse with a duration of 1 CK cycle will be generated. At the falling edge of the pulse, the delay timer starts counting tTOUT. Please refer to P44 for the specific operation of the watchdog timer.
[Microcontroller]
ATmega88 watchdog reset
Digital frequency meter made with ATmega8 microcontroller
Introduction: This article introduces the relevant functions of T/CO and T/C1 based on the relevant knowledge used in case programming. Readers can deepen their understanding by referring to the relevant content of the supporting program when studying. Frequency refers to the number of times a periodic signal change
[Microcontroller]
Digital frequency meter made with ATmega8 microcontroller
ATmega8 Power-On Reset
The Power-On Reset (POR) pulse is generated by the on-chip detection circuit. The detection levels are shown in Table 15. Whenever VCC falls below the detection level, a POR occurs. The POR circuit can be used to trigger a reset or to detect a power failure. The POR circuit ensures that the device is reset at power-
[Microcontroller]
ATmega8 Power-On Reset
ATmega88 Status Register
The ATmega88 status register contains information about the results of the most recently executed arithmetic instruction. This information can be used to change the program flow to implement conditional operations. As described in the instruction set, all ALU operations will affect the contents of the status register.
[Microcontroller]
ATmega88 Status Register
Use Arduino IDE to program ATMEGA8 and other microcontrollers
 Why do you want to use Arduino IDE to program ATMEGA8? Perhaps any of the following three reasons may impress you: Using a cheaper AVR microcontroller Require an AVR microcontroller with more or even less pins than ATmega328 You have all kinds of AVR except ATmega328
[Microcontroller]
Use Arduino IDE to program ATMEGA8 and other microcontrollers
ATMEGA8 Counter
//Can measure 1MHZ frequency #include iom8v.h #include DELAY.H #define uchar unsigned char #define uint unsigned int /***********The corresponding digital tubes display********************/ const uchar table ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned long load=0; uchar data ={0,0,0,0};//
[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号