AD conversion experiment of ATmega8/16

Publisher:和谐共处Latest update time:2016-11-18 Source: eefocusKeywords:ATmega8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/********************************************************************
Program name: On-chip analog-to-digital conversion demonstration experiment
Clock frequency: internal RC 1M
Pin: connected to keyboard and display part
    **PC0.......PC7 keyboard and display a.....g**
       **PD0.......PD7 keyboard and display 1.....8**
       **PA0 analog voltage**
    **Aref positive power supply**
************************************************************************/
#include
#include
#include
#include
#pragma interrupt_handler ad:15
unsigned long m=0;
unsigned int adc,adc1=0,adc2=0,adc3=0,adc4=0,l;
const unsigned char f[]=
      {
      0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xde
      };//code segment conversion
void adcc(void)
      {
         PORTA=0x00;
        DDRA=0xf0;
        PORTD=0x00;
        DDRD=0xff;
        PORTC=0x00;
        DDRC=0xff;
        ADMUX=0x40; //ADC status register definition
        ADCSRA=0x8e;//ADC status register definition
        SREG=0x80;//Open global interrupt
        ADCSRA|=BIT(ADSC);//Start a conversion
      }
/*******************************************Status register setting *******************/
void Delay(void)
 {
 unsigned int a, b;
 for (a = 1; a<20; a++)
  for (b = 1; b<20; b++)
   ;
   } 
/****************************Delay*********************/    
void ad(void)
      {
   if (adc3==2)
   adc1=ADC;
   if (adc3==4)
   adc2=ADC;
   if (adc1==adc2)
   adc=adc1;
   adc3++;
   if (adc3>4)
   adc3=0;
   ADCSRA|=BIT(ADSC);
      }
/************************AD sampling interrupt service subroutine**************************/
void main(void)//main program
{
char i=0;
adcc();
while(1)
{
if (i==20)
m=(long)adc*5000/1023,i=0;
PORTC=f[m%10];
PORTD=0xfe;
Delay(); 
PORTC=f[m/10%10];
PORTD=0xfd;
Delay() ;
PORTC=f[m/100%10];
PORTD=0xfb;
Delay() ;
PORTC=f[m/1000%10]|0x01;
PORTD=0xf7;
Delay() ;
i++;
}
}

Keywords:ATmega8 Reference address:AD conversion experiment of ATmega8/16

Previous article:External interrupt, timer interrupt, serial port interrupt C51 program
Next article:DS18B20 Driver

Recommended ReadingLatest update time:2024-11-16 23:50

Design of LCD display controller display system based on W78E516B
Liquid crystal led /' target='_blank'> display screen (LCD) has the advantages of low loss, low price, long life, convenient interface , etc., so it is widely used in industrial products, and there are various LCD display drive solutions. At present, the control solutions for small and medium-sized m
[Analog Electronics]
Design of LCD display controller display system based on W78E516B
LCD1602 dynamic display
The schematic diagram of the simulation element is as follows: /*------------------------------------- Function: LCD1602 local dynamic display Description: Display count at a fixed position on the second line of the screen: Then the number of key presses will be displayed dynamically (00 ~ 99) Author: Zhang Kaizhou D
[Microcontroller]
LCD1602 dynamic display
Design analysis of dual battery power supply solution based on bq24161+TPS2419
   Overview   Today, portable terminal products such as smart phones and portable routers are developing towards a trend of smaller size, thinner thickness and lighter weight. However, as the processing power of portable terminal products continues to improve and their functions continue to enrich, their power consum
[Power Management]
Design analysis of dual battery power supply solution based on bq24161+TPS2419
PIC16F84A MCU Tutorial Board Detailed Explanation (PCB Diagram and Schematic Diagram)
This is a new design, based on the popular PIC16F84A microcontroller tutorial board. It features 8 individual LEDs, a 7-segment display, an LCD display and five buttons. It is an ideal solution for a beginner to take/her first programming steps in the world of microcontrollers. There is an In-Circuit Progr
[Microcontroller]
PIC16F84A MCU Tutorial Board Detailed Explanation (PCB Diagram and Schematic Diagram)
90W universal input single-stage PFC flyback converter circuit composed of NCP1651
90W universal input single-stage PFC flyback converter circuit composed of NCP1651 The 90W universal input single-stage PFC flyback converter circuit composed of NCP1651 is shown in Figure 2. The AC input line voltage range of this converter is 85~265V. The DC output voltage is 48V, and it works
[Power Management]
90W universal input single-stage PFC flyback converter circuit composed of NCP1651
Two-minute charging and 160-kilometer range! StoreDot announces 100inX super-fast charging battery roadmap
Israel’s StoreDot, an innovator in Extremely Fast Charging (XFC) battery technology for electric vehicles, has unveiled its strategic technology roadmap, called 100inX, which will see the company launch a battery that can charge in two minutes and last for 100 miles (160.9 km), with plans to mass produce
[New Energy]
OPPO A1 Pro with 100 million high-pixel ultra-narrow dual-curved screen will be released on November 16
OPPO A1 Pro with 100 million high-pixel ultra-narrow dual-curved screen will be released on November 16 OPPO announced today that the A1 Pro, equipped with "100 million high pixels" and "ultra-narrow dual-curved screen", will be released online on November 16. New OPPO A1 Pro
[Mobile phone portable]
OPPO A1 Pro with 100 million high-pixel ultra-narrow dual-curved screen will be released on November 16
Base station monitoring system based on CM300 and SM79164
Abstract: This paper introduces the design of a communication base station environment and power monitoring system that uses a high-performance 8-bit single-chip microcomputer SM79164 as the main control chip. The system uses various high-performance sensors to collect the environment and power parameters in the bas
[Industrial Control]
Base station monitoring system based on CM300 and SM79164
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号