kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,482
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
unsigned char rc,i;
#define FOSC 16000000 // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD -1
int main(void)
{
/*Set baud rate */
UBRR0H = (MYUBRR >> 8);
UBRR0L = MYUBRR;
UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter
UCSR0B |= (1 << RXCIE0); // Enable reciever interrupt
UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8data, 1 stp
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
LCDcursorOFF();
while(1)
{
while (! (UCSR0A & (1<<RXC0)));
rc=UDR0;
LCDsendChar(rc);
}
retrun (0);
}
Thank you in advance!
Code C - [expand] 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 #include <avr/io.h> #include <avr/interrupt.h> unsigned char rc,i; unsigned char table[16]={}; #define FOSC 16000000 // Clock Speed #define BAUD 9600 #define MYUBRR FOSC/16/BAUD -1 int main(void) { /*Set baud rate */ UBRR0H = (MYUBRR >> 8); UBRR0L = MYUBRR; UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter UCSR0B |= (1 << RXCIE0); // Enable reciever interrupt UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8data, 1 stp LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); while(1) { for (i=0;i<16;i++) { while (! (UCSR0A & (1<<RXC0))); rc=UDR0; table[i]=rc; } LCDstring(table,16); } return (0); }
Code C - [expand] 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 #include <avr/io.h> #include <avr/interrupt.h> unsigned char rc,i=0,table[16]={}; #define FOSC 16000000 // Clock Speed #define BAUD 9600 #define MYUBRR FOSC/16/BAUD -1 int main(void) { /*Set baud rate */ UBRR0H = (MYUBRR >> 8); UBRR0L = MYUBRR; UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter UCSR0B |= (1 << RXCIE0); // Enable reciever interrupt UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8data, 1 stp LCDinit();//init LCD bit, dual line, cursor right LCDclr();//clears LCD LCDcursorOFF(); sei(); while(1) { if( rc =='\0') { LCDstring(table,16); rc=0; } } return 0; } ISR(USART_RX_vect) { rc=UDR0; table[i]=rc; i++; } This is the output of the above code:
I'm sending "Hello world" from my PC using Hterm application!There is no "Hello world!" on your code.
Are you sure you're actually updating the firmware on device ?
I think that Hterm doesn't send any \0 at all, that's the problem!Hi,
so .. 11 characters?
but usually a terminal program adds some delimiters like Cr...
So what do you send exactly?
or 11 + 1? ("Hello world" + 0)
or 11 + 1? ("Hello world" + Cr)
or 11 + 1? ("Hello world" + Lf) --> (most UNIX)
or 11 + 2? ("Hello world" + Cr + Lf) --> (most Windows)
or 11 + 2? ("Hello world" + Cr + 0)
or 11 + 2? ("Hello world" + Lf + 0)
or 11 + 3? ("Hello world" + Cr + Lf + 0)
(.... without taking care of the order of Cr, Lf and \0)
from my experience it is not likely that it sends a \0 at all.
Klaus
Thank you guys for your help. I used the Carriage return, and it's working fine!Hterm can't send a null character at the end of the line, it has no way to tell where the end of the line is!
Better to use a pre-determined delimiter, maybe a carriage return or line feed character.
Brian.
Code C - [expand] 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 #include <avr/io.h> #include <avr/interrupt.h> unsigned char rc,i=0,table[16]={}; #define FOSC 16000000 // Clock Speed #define BAUD 9600 #define MYUBRR FOSC/16/BAUD -1 int main(void) { /*Set baud rate */ UBRR0H = (MYUBRR >> 8); UBRR0L = MYUBRR; UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter UCSR0B |= (1 << RXCIE0); // Enable reciever interrupt UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8data, 1 stp lcd_init();//init LCD bit, dual line, cursor right lcd_clrscr();//clears LCD sei(); while(1) { if( rc !='\r') { lcd_goto(0x40); lcd_puts(table); // rc=0; } } return 0; } ISR(USART_RX_vect) { rc=UDR0; table[i]=rc; i++; }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?