source: avrstuff/chiptest/main.c@ 6390cc3

main
Last change on this file since 6390cc3 was 6390cc3, checked in by Adrien Destugues <pulkomandy@…>, 7 years ago

chiptest: Start to hack on ATmega128 and STK500 devboard.

  • Set the proper clock for it (generated by the STK500 master MCU, did

not get crystal working reliably yet)

  • Instead of just 'H', generate the whole alphabet for more action!
  • Use ATmega128 since that's what happens to be seated on my board for

now.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <usart.h>
2
3#include <avr/io.h>
4#include <avr/interrupt.h>
5#include <avr/wdt.h>
6#include <avr/pgmspace.h>
7#include <util/delay.h>
8
9#include <string.h>
10#include <stdbool.h>
11
12// muSerial: ATTiny2313 - LED = PD6
13// K4KUSB: ATTiny2313 - LED = PB2
14// STK500: anything, PORTD is convenient if available.
15#define DDRLED DDRC
16#define PORTLED PORTC
17#define LEDBIT (1 << PC2)
18
19int main() {
20 wdt_enable(WDTO_2S);
21 // configure timer 0 for a rate of FCPU/(256 * 256)
22#ifdef __AVR_ATtiny2313__
23 TCCR0A = 0; // timer 0 prescaler: 256
24 TCCR0B = 4;
25#else
26 TCCR0 = 6; // timer 0 prescaler: 256
27#endif
28
29 //debug LED - output
30 DDRLED |= LEDBIT;
31 PORTLED &= ~LEDBIT;
32
33 USARTInit();
34
35 // Let's rock!
36 uint8_t counter = 0;
37 char c = 'a';
38 for(;;) {
39 wdt_reset();
40
41 // Wait for timer overflow...
42 if (TIFR & (1 << TOV0)) {
43 TIFR = (1 << TOV0); // reset flag
44 counter++;
45
46 if (counter == 0)
47 {
48 PORTLED ^= LEDBIT; // Toggle the LED
49 USARTWriteChar(c++); // Send a byte to the UART
50 if (c > 'z')
51 c = 'a';
52 }
53 }
54 }
55
56 return 0;
57}
58
Note: See TracBrowser for help on using the repository browser.