Microcontroller › AVR › avr adc reading to 7 segment
- This topic has 1 reply, 2 voices, and was last updated 12 years, 4 months ago by srinu.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
November 10, 2011 at 10:23 am #1391udgish patelParticipant
hi all i am new at atmega i need to help in c code how to display adc reading in 7segment
i hav LVDt sensor and i hav adc voltage span of 2v
i hav scale 0 to 100kg load can any buddy help me in start coding.
November 16, 2011 at 6:10 am #6841srinuParticipanthi….udgisham give u one adc code..but it is in atmega8.in this project am sending AADC values to UART…..i hope u undstd this code………#define F_CPU 8000000UL#include<avr/io.h>#include<util/delay.h>#include “lcd.h”/*********************************************************************** adc init *******************************************************************/void InitADC(){ADMUX=(1<<REFS0);ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);}/**************************************************** READING ADC BITS ***************************************************/uint16_t ReadADC(uint8_t ch){ch=ch&0b00000111;ADMUX =ch | (1<<REFS0);ADCSRA|=(1<<ADSC);while(!(ADCSRA & (1<<ADIF)));ADCSRA|=(1<<ADIF);return(ADC);}/********************************************************* UART***********************************************************************************************/void uart_init(){// SETTING BIT PARITY (8BIT OR 9 BIT)UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8 BIT//FOR TX AND RXUCSRB=(1<<RXEN)|(1<<TXEN);// ENABLING TX,RX.UBRRL=0x33; // baud rate(51 for 9600)}void tx_data(unsigned char c){//SENDING DATA;UDR=c;while(!(UCSRA & (1<<TXC))); //set the TX flag//clear the TX flagUCSRA=(1<<TXC);}unsigned char rx_data(){// Wait for data to be receivedwhile ( !(UCSRA & (1<<RXC)) ); // set the rx flagUCSRA=(0<<RXC);// CLEAR THE rx flag/* Get and return received data from buffer */return UDR;}void Tx_String(unsigned char *str){while(*str){tx_data(*str);str++;}}/*********************************************************MAIN PROGRAM ** ** ** ** ** ** ** ** ** ** *********************************************************/void main(){int adc_result0;uart_init();InitADC();InitLCD(LS_BLINK|LS_ULINE);LCDWriteStringXY(0,0,”adc_test”);while(1){_delay_ms(1000);ReadADC(0);adc_result0=ReadADC(0);LCDWriteIntXY(0,1,adc_result0,4);tx_data(adc_result0);}} -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.