Interfacing POT(ADC) With AVR ATmega16 Mini Development Board
AVR ATmega16 mini development board has a POT connected to pin PA0 i.e, ADC0 via jumper J3. Sample code to check the ADC module of ATmega16 with potentiometer is given below. The output is displayed on LCD and the variation can be checked with the POT.
Note: To use the POT, don’t forget to short jumper J3. Leaving it open frees PA0 and it can be used for any other desired purpose.
Schematic
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
/************************************************************************************** HEADER FILES ***************************************************************************************/ #define F_CPU 8000000UL #include<avr/io.h> #include<util/delay.h> /************************************************************************************** FUNCTION DECLARATIONS ***************************************************************************************/ void Command(unsigned char cmd); void Data(unsigned char dat); int Adc_Converssion(unsigned char channel); void Int_Asci(int); void Display(char loc, const char *LCD); /************************************************************************************** VARIABLE DECLARATION ***************************************************************************************/ volatile unsigned char a=0; int Adc_Check=0,j=0; /************************************************************************************** MAIN FUNCTION ***************************************************************************************/ int main() { DDRA = 0X00; /* set PA0 PIN as input */ DDRB = 0xFF; /* set LCD data lines as output */ DDRD = 0X62; /* (RS(PD5),RW(GND),EN(PD6)set as Output */ ADCSRA = 0X85; /* ADEN=1,ADPS2=1,ADPS1=0,ADPS0=0 */ _delay_us(15); /* Min Delay To Power On LCD To RX Mode */ Command(0x30); /* LCD Specification Commands */ _delay_us(5); Command(0x30); /* LCD Specification Commands */ _delay_us(2); Command(0x30); /* LCD Specification Commands */ Command(0x38); /* LCD Double Line Display Command */ Command(0x06); /* LCD Auto Increment Location Address Command */ Command(0x0C); /* LCD Display ON Command */ Command(0x01); /* LCD Display Clear Command */ _delay_us(1200); Display(0x80, "ADC Checking..."); while(1) { Adc_Check=Adc_Converssion(0X40); /* reading sensor out from PA0 pin */ Command(0XC5); /* command to set display position */ Int_Asci(Adc_Check); /* display adc reading */ } } /************************************************************************************** * Function : Adc_Conversion * * * * Description : Function to convert analog value to digital * * * * Parameters : channel - channel for ADC conversion * ***************************************************************************************/ int Adc_Converssion(unsigned char channel) { volatile int b; volatile int ad=0; ADMUX=channel; /* channel selection */ ADCSRA=ADCSRA|0X40; /* ADSC=1,start conversion */ while((ADCSRA & 0x40) == 0x40); /* checking flag */ b = ADCL; /* reading LSB result */ ad = ADCH; /* reading MSB result */ ad = ad<<8; /* shift MSB 8 times */ ad = ad|b; /* combining MSB and LSB */ return ad; /* return adc reading */ } /************************************************************************************** * Function : Int_Asci * * * * Description : Function to convert integer value to ASCII * * * * Parameters : ab - integer to be converted * ***************************************************************************************/ void Int_Asci(int ab) { char i; char array[4]; for(i=1;i<=4;i++) /* decimal to ascii conversion */ { array[i]=ab%10; /* spliting decimal value using '/'and '%' */ ab=ab/10; } for(i=4;i>=1;i--) { Data(array[i]+'0'); /* display in lcd */ } } /************************************************************************************** * Function : Command * * * * Description : Function to send a command to LCD * * * * Parameters : cmd - command to be sent * ***************************************************************************************/ void Command(unsigned char cmd) { PORTD |= 0X40; /* contol line RS-0(cmd register), R/W-GND(write),E-1(enable) */ PORTB=cmd; /* command loaded to data port */ _delay_us(50); /* Minimun Delay For Hold On Data */ PORTD = 0X00; /* contol line RS-0(cmd register), R/W-GND(write),E-0(enable) */ } /************************************************************************************** * Function : Data * * * * Description : Function to display data on LCD * * * * Parameters : dat - data to be displayed * ***************************************************************************************/ void Data(unsigned char dat) { PORTD |= 0X60; /* contol line RS-1(data register), R/W - GND(write), E-1(enable) */ PORTB = dat; /* data loaded to data port */ _delay_us(50); /* Minimun Delay For Hold On Data */ PORTD = 0X00; /* contol line RS-0(data register) R/W - GND(write), E-0(enable) */ } /************************************************************************************** * Function : Display * * * * Description : Function to display string in LCD * * * * Parameters : loc - location * * LCD - String to be displayed * ***************************************************************************************/ void Display(char loc, const char *LCD) { Command(loc); /* Address of location to display data */ while(*LCD!='\0') /* Check for termination character */ { Data(*LCD); /* Display the character on LCD */ LCD++; /* Increment the pointer */ } } /************************************************************************************** END OF PROGRAM ***************************************************************************************/ |
Topics related to AVR ATmega16 Mini Development Board
- AVR ATmega16 Mini Development Board – Overview
- AVR ATmega16 Mini Development Board - Interfacing LED
- AVR ATmega16 Mini Development Board – Interfacing LCD
- AVR ATmega16 Mini Development Board – Serial communication(USART)
- AVR ATmega16 Mini Development Board – Interfacing Switch
- AVR ATmega16 Mini Development Board – Interfacing Buzzer
- AVR ATmega16 Mini Development Board - Interfacing POT(ADC)
- AVR ATmega16 Mini Development Board – Interfacing Temperature sensor
- AVR ATmega16 Mini Development Board – Interfacing Servo Motor
- AVR ATmega16 Mini Development Board – Interfacing μRFID
Resources
How to buy?
- Click here to buy rhydoLABZ AVR ATmega16 Development Board-Mini
- Click here to buy rhydoLABZ AVR ATmega32 Development Board-Mini
SupportPlease share your ideas with us, visit our forum for discussion