atmega8535 Ad conversion c program

Publisher:DreamyEclipseLatest update time:2017-12-13 Source: eefocusKeywords:atmega8535 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

atmega8535 Ad conversion c program

#include 
#define uchar unsigned char 
#define uint  unsigned int 


uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

uchar Data[4]={0,0,0,0}; 

void DelayMs(uint i) //0.25ms 
{uchar j; 
 for(;i!=0;i--) 
  {for(j=250;j !=0;j--) {;}} 


void Display(uchar *p) //Display 
{uchar i,sel=0x01 at 5ms interval; 
 for(i=0;i<4;i++) 
  {PORTD=sel; 
   PORTB=0xff-Table[p[i]]; 
   DelayMs(20); 
   sel=sel<<1; 
  } 


uint ADC_Convert(void) 
{uint temp1,temp2; 
 temp1=(uint)ADCL; 
 temp2=(uint)ADCH ; 
 temp2=(temp2<<8)+temp1; 
 return(temp2); 


void Process(uint i,uchar *p) 
{p[0]=i/1000; 
 i=i%1000; 
 p[1]=i/100; 
 i=i%100; 
 p[2]=i/10; 
 i=i%10; 
 p[3]=i; 


void main(void) 
{ uint i; 
 DDRA=0x00; //Set port A to input without pull-up; 
 PORTA=0x00; 
 DDRB=0xff; //Set port B to push-pull 1 output; 
 PORTB=0xff; 
 DDRD=0xff; //Set port C PORTD 
 =0xff; 
 PORTB=0x00; //Port B initializes output 1; Port C initializes output 0; Light up all digital tubes ; 
 PORTD=0xff; 
 ADMUX=0x01; //Select the second channel ADC1 ; 
 ADCSR=0xe6; //125K conversion rate , free conversion mode; start AD converter; 
 DelayMs(3000); //delay until the system is stable; 
 while(1) 
 {i=ADC_Convert(); 
  Process(i,Data); 
  Display(Data); 
 } 
}


 


#include
#define uchar unsigned char
#define uint  unsigned int

void DelayMs(uint i)
{uchar j;
 for(;i!=0;i--)
  {for(j=255;j!=0;j--) {;}}
}

main()
{DDRA=0xff; //Port A 1 output
 PORTA=0xff;
 DDRB=0xff; //Port B 1 output
 PORTB=0xff;
 while(1)
  {DelayMs(0);
   PORTA=0xff;
   PORTB=0x00;}
}


Keywords:atmega8535 Reference address:atmega8535 Ad conversion c program

Previous article:ATmega8535L Eeprom Example Program
Next article:AVR microcontroller digital tube display clock

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号