hi every one
i have problem in my code for send data to pc
i try to write it but it dont work !!
can any one help me
this is code
take data from sensors and convert from analog to digital
then send it to PC
but i have problem in uart
i have problem in my code for send data to pc
i try to write it but it dont work !!
can any one help me
this is code
take data from sensors and convert from analog to digital
then send it to PC
but i have problem in uart
#define F_CPU 10000000UL
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "uart.h"
#define sbi(port, bit) (port) |= (1 << (bit))
#define loop_until_bit_is_clear(sfr, bit) do { } while (bit_is_set(sfr, bit))
FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
void initUART()
{
UBRRH =0;
UBRRL = 31; // for baud rate=19200
UCSRC = 0x86; // mode 8N1
UCSRB = 0x18; // enable RX and TX
}
////////////////////////////////////////////////
void my_delay(int w) //Define delay function.
{
int i;
for(i=0; i<= w ; i++)
_delay_ms(1);
}
////////////////////////////////////////////////
void sendByte(char x)
{ while((UCSRA & 0x20)==0 )
; //wait till bit 5 of UCSRA is set check bit 5 (UDRE)
UDR=x;
}
//////////////////////////////////////
//stdout = stdin = &uart_str; // map stdin and stdout to serial port
int main(void)
{
ADMUX= 0b00100000; // chan 0, left adjusted,Vref=5
ADCSRA= 0b10000110; // ADC enabled, pre-scalar 64
DDRA= 0; //PORT A input
DDRB= 0b11111111; //PORT B output
unsigned x; //declare the temprature
unsigned char y; //declare the Humdaity
unsigned char z; //declare the Solar radition
unsigned char w;
unsigned int result;
uart_init();
stdout = stdin = &uart_str;
//uart_init();
while (1)
{
////////////////////////////////////////////////
ADMUX= 0b00100000; // chan 0, left adjusted,Vref=5
ADCSRA = ADCSRA | 0x40 ; // start conversion.
do {
w = ADCSRA & 0x10;
} while (w == 0); // repeat until EOC
result = ADC; // the sampled data is in result
// we can do whatever with the sampled data.
//For now, we will display in on PORTD
result = (result>>8); // truncate from 10 to
x=result;
/////////////////////////////////////////////
ADMUX= 0b00100001; // chan 0, left adjusted,Vref=5
ADCSRA = ADCSRA | 0x40 ; // start conversion.
do {
w = ADCSRA & 0x10;
} while (w == 0); // repeat until EOC
result = ADC; // the sampled data is in result
// we can do whatever with the sampled data.
//For now, we will display in on PORTD
result = (result>>8); // truncate from 10 to
y=result;
///////////////////////////////////////////
ADMUX= 0b00100010; // chan 0, left adjusted,Vref=5
ADCSRA = ADCSRA | 0x40 ; // start conversion.
do {
w = ADCSRA & 0x10;
} while (w == 0); // repeat until EOC
result = ADC; // the sampled data is in result
// we can do whatever with the sampled data.
//For now, we will display in on PORTD
result = (result>>8); // truncate from 10 to
z=result;
///////////////////////////////////////////////////////////
PORTB=x;
my_delay(1000);
PORTB=y;
my_delay(1000);
PORTB=z;
my_delay(1000);
initUART();
while(1){
sendByte(x);
sendByte(y);
sendByte(z);
}
}
return 0;
}