/*Electronic battery Less Dice*/
/*Dhananjay Gadre*/
/*20th September 2007*/
/*Tiny13 Processor @ 128KHz internal RC oscillator*/
/*7 LEDs connected as follows
LED0 - PB1
LED1, 2 - PB2
LED3, 4 - PB3
LED5, 6 - PB4
D3 D2
D5 D0 D6
D1 D4
Pulse input from coil is on PB0
*/
#include <avr/io.h> //
#include <util/delay.h> //
#include <avr/interrupt.h> //
#include<avr/pgmspace.h> //
const char ledcode[] PROGMEM= {0xfc, 0xee, 0xf8, 0xf2, 0xf0, 0xe2, 0xfe};
main()
{
unsigned char temp=0;
int count=0;
DDRB=0xfe; /*PB0 is input*/
TCCR0B=2; /*divide by 8*/
TCCR0A=0;
TCNT0= 0;
PORTB=254; /*disable all LEDs*/
while(1)
{
/*wait for pulse to go high*/
while ( (PINB & 0x01) == 0);
_delay_loop_2(50);
/*wait for pulse to go low*/
while ( (PINB & 0x01) == 0x01);
_delay_loop_2(50);
count=5000;
while ( (count > 0) && ((PINB &0x01) ==0))
{count--;
}
if(count ==0) /* no more pulse so display a random number*/
{
PORTB=0xfe; /*all LEDs off*/
_delay_loop_2(10000);
temp=TCNT0;
temp= temp%6;
temp =pgm_read_byte(&ledcode[temp]);
PORTB=temp;
}
}
}