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
RevLine 
[6d8c366]1#include <usart.h>
2
[98713b5]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
[f51aacc]12// muSerial: ATTiny2313 - LED = PD6
13// K4KUSB: ATTiny2313 - LED = PB2
[6390cc3]14// STK500: anything, PORTD is convenient if available.
15#define DDRLED DDRC
16#define PORTLED PORTC
17#define LEDBIT (1 << PC2)
[82d2b68]18
[98713b5]19int main() {
20 wdt_enable(WDTO_2S);
[82d2b68]21 // configure timer 0 for a rate of FCPU/(256 * 256)
[6390cc3]22#ifdef __AVR_ATtiny2313__
[98713b5]23 TCCR0A = 0; // timer 0 prescaler: 256
24 TCCR0B = 4;
[6390cc3]25#else
26 TCCR0 = 6; // timer 0 prescaler: 256
27#endif
[98713b5]28
29 //debug LED - output
[6d8c366]30 DDRLED |= LEDBIT;
31 PORTLED &= ~LEDBIT;
[8f4b118]32
[6d8c366]33 USARTInit();
[98713b5]34
[82d2b68]35 // Let's rock!
36 uint8_t counter = 0;
[6390cc3]37 char c = 'a';
[82d2b68]38 for(;;) {
[98713b5]39 wdt_reset();
40
[82d2b68]41 // Wait for timer overflow...
[98713b5]42 if (TIFR & (1 << TOV0)) {
43 TIFR = (1 << TOV0); // reset flag
[82d2b68]44 counter++;
[8f4b118]45
[efe25a8]46 if (counter == 0)
47 {
48 PORTLED ^= LEDBIT; // Toggle the LED
[6390cc3]49 USARTWriteChar(c++); // Send a byte to the UART
50 if (c > 'z')
51 c = 'a';
[efe25a8]52 }
[98713b5]53 }
54 }
55
56 return 0;
57}
58
Note: See TracBrowser for help on using the repository browser.