I am receiving bytes from my UART as uint8. How do I convert these bytes into ASCII? I am using Atmel 6.0 and my microcontroller is ATMega16L.
EDIT
I am using an android phone to send and receive information to a Wifi module (RN-131) from Roving networks. The wifi module connects to the microcontroller (atmega16L) through UART. Whatever the wifi module receives from the phone is transmitted out its UART. Similarly, whatever is written to its UART is transmitted out through wifi.
Now, what I'm trying to do is send a string from the phone which gets converted into bytes. The code is shown below:
PrintWriter out = new PrintWriter(new BufferedWriter(new outputStreamWriter(socket.getOutputStream())), true);
out.println("Eclipse");
here, the 'BufferedWriter' - Constructs a new BufferedWriter, providing out with a buffer of 8192 bytes. and 'PrintWriter' - Constructs a new PrintWriter with out as its target writer. The parameter autoFlush determines if the print writer automatically flushes its contents to the target writer when a newline is encountered.
now to program the microcontroller, I'm using AVR studio 6.0
uint8_t data;
char arr[32];
data = UDR;
length = strlen(data);
itoa(data, arr, 10);
But what I receive is "50, 53, 52" even when I'm sending "Eclipse".
EDIT 20th June 2012
Here is my code till now. Note: the code is written in AVR Studio 6.0 so it looks a bit different to other codes written in AVR Studio 4.18.
/**************************************************
* Includes
*/
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "../../../../../../Program Files (x86)/Atmel/Atmel Studio 6.0/extensions/Atmel/AVRGCC/3.4.0.65/AVRToolchain/avr/include/avr/iom16.h"
/**************************************************
* Global Variables
*/
int trigger=0, length=0;
int i=0, n=0;
uint8_t data;
char arr[8];
/**************************************************
* Defines
*/
#define LED_PORT PORTA
#define RED_ON (PORTA | 0x01)
#define RED_OFF (PORTA & ~0x01)
#define YELLOW_ON (PORTA | 0x02)
#define YELLOW_OFF (PORTA & ~0x02)
#define GREEN_ON (PORTA | 0x04)
#define GREEN_OFF (PORTA & ~0x04)
/**************************************************
* Function Prototypes
*/
void initialize(void);
void time_display(void);
int main(void){
initialize();
while(1){
//TODO:: Please write your application code
}
}
void initialize(void){
DDRA = 0x07; //PORTA pins 0,1,2 set as outputs
// DDRD = 0x02; //PORTD pin 1 is output (TX) and pin 0 is input (RX)
//Timer SETUP
TCCR1A = 0x80; //OCR1A enable in CTC mode
TCCR1B = 0x0C; //CTC mode, 256 prescale
TIMSK = 0x10; //CTC on OCR1A enabled, overflow disabled
OCR1A = 2000; //OCR value set to get an interrupt every 1 second (15624)
//USART SETUP
UCSRA = 0x00; //no Frame Error, no parity error, no Data OverRun
UCSRB = 0xE0; //receiver enable, transmitter enable (0x18)
UCSRC = 0x8E; //Asynchronous USART mode, no parity, 1 stop bit, 8-bit character size, Data transmitted on rising edge and received on falling edge of the clock
UBRRL = 51; //Baud rate of 9600bps
UBRRH = 0;
sei(); //Global interrupt enable
}
//timer capture interrupt
ISR(TIMER1_COMPA_vect){
}
ISR(USART_RXC_vect){
LED_PORT = RED_ON;
_delay_ms(100);
for(int x=0; x<5; x++){
arr[x] = UDR;
}
LED_PORT = RED_OFF;
_delay_ms(100);
trigger = 1;
}
ISR(USART_UDRE_vect){
if(trigger >= 1){
LED_PORT = GREEN_ON;
_delay_ms(200);
LED_PORT = GREEN_OFF;
_delay_ms(200);
UDR = data; //transmit the data
trigger = 0;
}
}