//the whacko maker wierdo alarm clock (of the Short Now), by Raphael Abrams (CC) 2005, very few rights reserved. go nuts. //this C code is written for CCS PCM midrange pic C compiler. It can be easily ported to a different compiler, but you might need to change a few things. //The HEX file is also available for people who don't have the $130 to spend on compilers. It should be on the same page from which you found this file. //first thing you have to do is make sure you set up the fuses correctly: brownout detect, watchdog timer and code protect must all be off. // set the oscillator mode to "LP". The procedure depends on the programming environment and the programing device you are using. #include <16f628.H> #use delay(clock=32000) #use fast_io(A) #use fast_io(B) #byte portb=0x06 //set up some easier to remember register names #byte porta=0x05 #byte trisb=0x86 #byte trisa=0x85 #byte option=0x81 #byte cmcon=0x1F #byte t2con = 0x12 #byte pr2 = 0x92 #bit blinky =porta.1 #bit buzzer =porta.2 int32 seconds; //this variable is global so both the interrupt and the main loop can access it //this is the timer2 interrupt. it increments the seconds counter and blinks the led once each time. //at these settings, the duty cycle for the blinker is about .625%. so a 1 mA led would draw only //about 6 micro amps over time. (right? i don't do this "math" thing. someone good at math check my numbers and eamil me, ok?) //anyway the pic draws about 20 micro amps at this processor speed, add the led and you get... 72000 hours of blinking from a pair of AA batteries? //huh!? that's 8 years, not counting the much larger current draw of the buzzer. really now. someone email me, ok? #int_timer2 void gurk(void){ seconds++; blinky=1; delay_cycles(50);//very brief led pulse once each second blinky=0; } void main(void) { //set up processor: trisa = 0b11111001; //set inputs and outputs trisb = 0b11111111; cmcon = 0x07; //turn off comparator circuit. this is a quirk of some of the newer pics option= 0b10000000;//no internal pull up resistors on port b. doesn't really matter in this design... //set up interrupt: t2con=0b00001110; //32khz clock /4 =8000 /2 =4000 /250= 16 /16 =1 second per tmr2 interrupt //the binary is as follows: 0.. msb not implemented | ..0001.. postscale=2 | ..1.. timer on | ..10 prescale=16 pr2=249; //period register. part of the timer2 peripheral. the "250" in the math above becomes 249 here enable_interrupts(GLOBAL); //set up program: buzzer=0; //make sure buzzer is off seconds=0; enable_interrupts(INT_TIMER2); //start counting seconds! //next line is big giant loop that does nothing until the time is up. the interrupt still blinks the led, though while(seconds<29700){;} //this is where the timespan is set(8:15, in this case) so: 8:15 = 495 minutes = 29700 seconds //i like 8 hours sleep, and i added the 15 minutes to err on the side of too much. //incedentally, 29700 is about how many days one can expect to live... memento mori morning! buzzer=1; //alarm!!! one more day to kill off, worker bee! sleep(); //isn't that ironic? }