GIT.Harvie.CZ
/
mirrors
/
Programs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2f5d151
)
Made USART working (even with internal RC osc. ;-)
author
Harvie
<tomas@mudrunka.cz>
Sat, 14 Jan 2012 11:33:16 +0000
(12:33 +0100)
committer
Harvie
<tomas@mudrunka.cz>
Sat, 14 Jan 2012 11:33:16 +0000
(12:33 +0100)
avr/usart/main.c
patch
|
blob
|
blame
|
history
diff --git
a/avr/usart/main.c
b/avr/usart/main.c
index 853f82aecb097951cc87d5738852f2121925d64f..dcb16b1c8e998fcb9915b4d92977a2967b20099b 100644
(file)
--- a/
avr/usart/main.c
+++ b/
avr/usart/main.c
@@
-1,16
+1,24
@@
#include <avr/io.h>
#define F_CPU 1000000UL //1MHz default internal RC oscillator setting
#include <avr/io.h>
#define F_CPU 1000000UL //1MHz default internal RC oscillator setting
+//#include <avr/iotn2313.h>
+//#include <avr/interrupt.h>
//util/delay.h and util/setbaud.h
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
//util/delay.h and util/setbaud.h
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
+#define LED PD5
+
int main (void)
{
int main (void)
{
+ DDRD |= (1 << LED);
+
char ReceivedByte;
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
//UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes (not in attiny2313?)
char ReceivedByte;
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
//UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes (not in attiny2313?)
+ UCSRC |= (1 << UCSZ0) | (1 << UCSZ1);
+ //Hint: stty -F /dev/ttyUSB1 9600 sc7
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
@@
-20,6
+28,8
@@
int main (void)
while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR
ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived"
while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR
ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived"
+ PORTD ^= (1 << LED); //Toggle LED after each received byte
+
while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
UDR = ReceivedByte; // Echo back the received byte back to the computer
}
while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
UDR = ReceivedByte; // Echo back the received byte back to the computer
}
This page took
0.105023 seconds
and
4
git commands to generate.