AVR Bootloader (avrboot cleanup)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.1 KiB

  1. // Martin Thomas 4/2008
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4. #include <avr/wdt.h>
  5. #include <util/delay.h>
  6. #define LED_PORT PORTB
  7. #define LED_DDR DDRB
  8. #define LED_BIT PB2
  9. #define BT_PORT PORTC
  10. #define BT_DDR DDRC
  11. #define BT_PIN PINC
  12. #define BT_BIT PC7
  13. static inline void my_wdt_off(void)
  14. {
  15. cli();
  16. wdt_reset();
  17. /* Clear WDRF in MCUSR */
  18. MCUSR &= ~(1<<WDRF);
  19. /* Write logical one to WDCE and WDE */
  20. /* Keep old prescaler setting to prevent unintentional time-out */
  21. WDTCSR |= (1<<WDCE) | (1<<WDE);
  22. /* Turn off WDT */
  23. WDTCSR = 0x00;
  24. }
  25. static void my_delay( void )
  26. {
  27. int i;
  28. for ( i=0; i<500; i++ ) {
  29. _delay_ms(1);
  30. }
  31. }
  32. int main( void )
  33. {
  34. my_wdt_off();
  35. LED_PORT |= ( 1<<LED_BIT );
  36. LED_DDR |= ( 1<<LED_BIT );
  37. BT_DDR &= ~( 1<<BT_BIT );
  38. BT_PORT |= ( 1<<BT_BIT );
  39. while ( 1 ) {
  40. LED_PORT &= ~( 1<<LED_BIT );
  41. my_delay();
  42. LED_PORT |= ( 1<<LED_BIT );
  43. my_delay();
  44. if ( !( BT_PIN & ( 1<<BT_BIT ) ) ) {
  45. /* start bootloader */
  46. wdt_enable( WDTO_250MS );
  47. while (1) { ; }
  48. }
  49. }
  50. return 0; /* never reached */
  51. }