File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 23
23
#define F_CPU 3333333
24
24
#define USART1_BAUD_RATE (BAUD_RATE ) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
25
25
#define MAX_COMMAND_LEN 8
26
- #define INIT_DELAY 10 /* delay in ms */
26
+ #define INIT_DELAY 10 /* Delay to invalidate the after-reset noise on the PC0 pin (TX) */
27
27
28
28
#include <avr/io.h>
29
29
#include <stdio.h>
@@ -41,12 +41,12 @@ void executeCommand(char *command);
41
41
42
42
void USART1_init (void )
43
43
{
44
- PORTC .DIR &= ~PIN1_bm ;
45
- PORTC .DIR |= PIN0_bm ;
46
-
47
44
USART1 .BAUD = (uint16_t )USART1_BAUD_RATE (9600 );
48
45
49
46
USART1 .CTRLB |= USART_RXEN_bm | USART_TXEN_bm ;
47
+
48
+ PORTC .DIR |= PIN0_bm ;
49
+ PORTC .DIR &= ~PIN1_bm ;
50
50
}
51
51
52
52
void USART1_sendChar (char c )
@@ -114,12 +114,13 @@ int main(void)
114
114
char command [MAX_COMMAND_LEN ];
115
115
uint8_t index = 0 ;
116
116
char c ;
117
-
118
- LED_init ();
117
+
118
+ /* This delay invalidates the initial noise on the TX line, after device reset. */
119
+ _delay_ms (10 );
120
+
119
121
USART1_init ();
120
-
121
- _delay_ms (INIT_DELAY );
122
-
122
+ LED_init ();
123
+
123
124
USART1_sendString ("Type ON/OFF to control the LED.\r\n" );
124
125
125
126
while (1 )
You can’t perform that action at this time.
0 commit comments