summaryrefslogtreecommitdiff
path: root/md/writeup/avr_echo.md
diff options
context:
space:
mode:
Diffstat (limited to 'md/writeup/avr_echo.md')
-rw-r--r--md/writeup/avr_echo.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/md/writeup/avr_echo.md b/md/writeup/avr_echo.md
new file mode 100644
index 0000000..0dac9fb
--- /dev/null
+++ b/md/writeup/avr_echo.md
@@ -0,0 +1,36 @@
+title:AVR echo
+keywords:avr,echo,c,atmega
+
+
+# AVR echo
+This code tested on ATmega16
+
+```c
+#include <avr/io.h>
+
+#define FOSC 16000000UL
+#define BAUD 9600
+#define MYUBRR FOSC/16/BAUD-1
+
+void USART_Init( unsigned int ubrr)
+{
+ UBRRH = (unsigned char)(ubrr>>8);
+ UBRRL = (unsigned char)ubrr;
+ UCSRB = (1<<RXEN)|(1<<TXEN);
+ UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
+}
+
+int main()
+{
+ char c;
+ USART_Init( MYUBRR );
+ while(1)
+ {
+ while ( !(UCSRA & (1<<RXC))){};
+ c = UDR;
+ while (!(UCSRA & (1<<UDRE))){};
+ UDR = c;
+ }
+ return 0;
+}
+```