ATtiny10 Reset as mode button

Attiny10 Reset as mode button:


Since I did not want do the high voltage programming (even though I built one for my Attiny13a's and Attiny85's. I wanted the simplest way to implement a mode button on the ATtiny10. Thanks to https://sites.google.com/site/wayneholder/using-the-avr-reset-pin-as-an-input (Wayne's Tinkering Page), who had done this for Attinyx5 series chips. I worked at it only for a little bit and got the ATtiny10 working with it.. (Thanks Wayne!!).

If you want to understand how it works. Go see Waynes sight. But the gist of it is taking advantage of reset flag. and memory not cleared by reset.

Attiny10 code I used:

/*

ATtiny10

+====+

SCK -> PB0 |* | PB3 (RESET)

GND | | Vcc

MOSI -> PB1 | | PB2

+====+

Modified By Sherm

from original code of:

https://sites.google.com/site/wayneholder/using-the-avr-reset-pin-as-an-input

Thanks Wayne..

*/


#include <avr/io.h>

#define EXT_RESET (1 << EXTRF)



volatile unsigned char count __attribute__((section(".noinit"))); // Not cleared on RESET


int main () {

// Any type of RESET clears the IO Regs, so we always need to reconfigure them

DDRB = 0b00000111;

if ((RSTFLR & EXT_RESET) != 0) {

//if ((RSTFLR & 1) != EXT_RESET) {

// If External RESET then increment count and output to pins

RSTFLR = RSTFLR & ~EXT_RESET;

//MCUSR = MCUSR & ~EXT_RESET;

PORTB = ++count;

} else {

// Else, set count to zero and output to pins

PORTB = count = 0;

}

while (1) {

}

}