Changeset 82d2b68 in avrstuff for chiptest/main.c
- Timestamp:
- Jul 29, 2014, 9:17:17 PM (10 years ago)
- Branches:
- main
- Children:
- efe25a8
- Parents:
- 5ef7bfc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chiptest/main.c
r5ef7bfc r82d2b68 14 14 #define LEDBIT 1 << PB2 15 15 16 #define BAUD 9600 // Safe value even for low clocks. (used by setbaud.h) 17 16 18 int main() { 17 19 wdt_enable(WDTO_2S); 18 // configure timer 0 for a rate of 16M/(256 * 256) = ~244Hz20 // configure timer 0 for a rate of FCPU/(256 * 256) 19 21 TCCR0A = 0; // timer 0 prescaler: 256 20 22 TCCR0B = 4; … … 25 27 PORTLED = 0; 26 28 27 // Serial PORT 28 UBRRH = 0; 29 UBRRL = 10; 29 // Serial baudrate - use avrlibc magic to compute the baudrate register 30 // values. 31 #include <util/setbaud.h> 32 UBRRH = UBRRH_VALUE; 33 UBRRL = UBRRL_VALUE; 34 #if USE_2X 35 UCSRA |= (1 << U2X); 36 #else 37 UCSRA &= ~(1 << U2X); 38 #endif 30 39 40 // Enable the serial port. 31 41 UCSRB = (1<<RXEN) |(1<<TXEN); 32 42 UCSRC = (1 << UCSZ1) | (1 << UCSZ0); 33 43 34 while(1) { 44 // Let's rock! 45 uint8_t counter = 0; 46 for(;;) { 35 47 wdt_reset(); 36 48 37 38 // check timer if we need periodic reports 49 // Wait for timer overflow... 39 50 if (TIFR & (1 << TOV0)) { 40 51 TIFR = (1 << TOV0); // reset flag 41 PORTLED ^= LEDBIT; 52 counter++; 53 } 42 54 43 UDR = 'H'; 55 if (counter == 0) 56 { 57 PORTLED ^= LEDBIT; // Toggle the LED 58 UDR = 'H'; // Send a byte to the UART 44 59 } 45 60 }
Note:
See TracChangeset
for help on using the changeset viewer.