atmega128 AD conversion program

Publisher:捡漏来了Latest update time:2020-04-14 Source: eefocusKeywords:atmega128 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  • /*************************************Include header file********************************/

  • #include

  • #include


  • /************************************Digital tube segment code table*******************************/

  • extern const unsigned char tab[]={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,

  •                                   0x7F,0x6F};


  • /*************************************Port definition**********************************/

  • #define sclon PORTG |= BIT(0); // Clock high

  • #define  scloff   PORTG &=~BIT(0);

  • #define dion PORTG |=BIT(1); //Data high

  • #define  dioff   PORTG &=~BIT(1);


  • /*************************************Global variables**********************************/

  • unsigned int adc_rel;

  • int that;


  • /****************************************************************************

  • Function: ADC initialization function

  • Entry parameters:

  • Export parameters:

  • ****************************************************************************/

  • void adc_init(void)

  • {

  • ADCSRA=0x00; //turn off ADC

  • ADMUX = (1<

  • ADCSRA = (1<ADSC)|(1<

  • }


  • /****************************************************************************

  • Function: ADC interrupt function

  • Entry parameters:

  • Export parameters:

  • ****************************************************************************/

  • #pragma interrupt_handler adc_isr:iv_ADC

  • void adc_isr(void)

  • {

  •    int data_H,data_L;

  •   ADCSRA = 0x00;

  •   adc_rel=ADC;

  •   ADCSRA = (1<

  • }


  • /****************************************************************************

  • Function: Data output program

  • Entry parameter: temp

  • Export parameters:

  • ****************************************************************************/

  • void dataOUT(unsigned char temp)

  • {

  •     unsigned char i,temp1;

  •     temp1 = tab[temp];

  •     for(i = 0;i < 8;i++ )

  •     {

  •         scloff;

  •   IF((temp1&0x80)!= 0x80)

  •          {  dioff;}

  •         else

  •          { dion;}

  •   sclon;

  •         temp1 <<=1;

  •   scloff;

  •     }

  • }


  • /****************************************************************************

  • Function: Delay subroutine

  • Entry parameters:

  • Export parameters:

  • ****************************************************************************/

  • void delay(void)

  • {

  •    int i;

  •     for(i=0;i<200;i++);

  • }


  • /****************************************************************************

  • Function: Display subroutine

  • Entry parameter: k

  • Export parameters:

  • ****************************************************************************/

  • void display(unsigned int k)

  • {

  •    dataOUT(k/1000);

  •   PORTG &=0x03;

  •   delay();

  •   dataOUT(k/100%10);

  •   PORTG |=0x04;

  •   delay();

  •   dataOUT(k/10%10);

  •   PORTG &=0x0B;

  •   PORTG |=0x08;

  •   delay();

  •   dataOUT(k%10);

  •   PORTG |=0x0C;

  •   delay();

  • }


  • /****************************************************************************

  • Function: Main program

  • Entry parameters:

  • Export parameters:

  • ****************************************************************************/

  • void main(void)

  • {

  •    DDRE=0x00;

  •   DDRG=0xff;

  •   adc_init();

  •   BE();

  •   display(0);

  •   while(1)

  •   {

  •     delay();

  •    display(adc_rel);

  •   }

  • }


Keywords:atmega128 Reference address:atmega128 AD conversion program

Previous article:Design of museum anti-theft protection system based on AVR microcontroller
Next article:Embedded Controller Designed Based on Atmega128 Single Chip Microcomputer

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号