Need Help With Code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need Help With Code

I need some help with my project. Im reading a accelerometer with ADC on port PA0 on a Atmega16. Im reading only X-axes. I want to add Y and Z also, but I dont know how.
Im reading the input with TeraTerm, line by line downwards. I want the y and Z to be added on the side of the X value.
IM using AVR studio 4.

Can anyone help me with thsis?



#define LONGOUT 7
char buffer[LONGOUT];

void adc_init(void);
unsigned int adc_read(void);
void adc_conversion(uint16_t);

// ADC configuration
void ADC_init(void) {

uint16_t ADC_get_reading(void) {
ADCSRA |= (1<<ADSC);
while(ADCSRA & (1<<ADSC));
return ADC;

uint16_t ADC_read(void) {
uint8_t i;
uint16_t retval = 0;
ADC_get_reading(); // dummy read - just discarded
for (i=0; i<8; i++) {
retval += ADC_get_reading();
return retval / 8;

void init_UART(void)
UCSRB = ((1 << RXCIE) | (1 << RXEN) | (1 << TXEN));
UCSRC = ((1 << UCSZ1) | (1 << UCSZ0));

//Baud rate till 19200.
UBRRL = 25;
UBRRH = 0;

void uart_sendchar(char c) {
while(!(UCSRA & (1<<UDRE)));
UDR = c;

void uart_printstring(char * str) {
while (*str) {

void main(void) {

DDRC = 0x00;

if (PINC & 0x01) //If PortC pin 0 is True, program stops.

char buffer[8];
itoa(ADC, buffer, 10);

Sign In or Register to comment.