by on
8051

This is a timer I built using a gutted alarm clock and a 2051. I developed the hardware using a DS5000 based emulater and the 89s8252 based programmer that I built last fall.

Schematic


The emulator

The programmer

Testing with actual chip

The carcas

The finished product buried on the messy bench

code

/*---------------------------------------------------------------------timer.c** This is the code for a soldering iron timer. 
* 
* C 2002 Donald Delmar Davis (delmar@digithink.com).** The hardware is built around the 20 pin atmel 89C2051. 
* (http://www.atmel.com/atmel/products/prod71.htm)* This program was compiled using sdcc (sdcc.sourceforge.com)** P1 is connected to the lower half of a 3.5 digit multiplexed clock display.* P3.0 is connected to the transister driving a relay.* P3.4-3.7 are connected to a BCD switch.* 
* P3.3 is connected to an off switch. (currently unimplimented).** The reset switch causes the machine to read the BCD switch. The timer 
* then counts down from 10 times the switch value plus 5 minutes. 
* 
** Most of the work is done by the timer interupt which not only counts* time but also multiplexes the display. 
*----------------------------------------------------------------------------*/#include #define RELAY P3_0static unsigned int pulses;static unsigned char seconds,ones,tens;code unsigned char tens_b[] = {0x58,0x00,0x38,0x30,0x60,0x70,0x78,0x00,0x78,0x70};code unsigned char tens_a[] = {0xf0,0xb0,0xe0,0xf0,0xb0,0xd0,0xd0,0xf0,0xf0,0xf0};code unsigned char ones_b[] = {0x07,0x06,0x05,0x07,0x06,0x03,0x03,0x07,0x07,0x07};code unsigned char ones_a[] = {0x8b,0x80,0x8e,0x86,0x85,0x87,0x8f,0x80,0x8f,0x87};/*---------------------------------------------------pulse_count * Count "pulses" from timer1 also multiple the display. * timer1 is set up to count 9600 ticks per second. * * * This could probably be optimized to create cleaner assembly. * does the job just fine. 
 */void pulse_count (void) interrupt 3 {pulses++;if (pulses==9600) {  if (++seconds == 60) {        if (ones==0){          ones=9;          if (tens==0) {            RELAY=0;	    P1=0;           /* could power down here */ 
	    while (1) ;          } else {          tens--;          }        } else {        ones--;        }   seconds=0;   }   pulses=0;}if (pulses&0x0001) {  P1=tens_a[tens]|ones_a[ones];} else {  P1=tens_b[tens]|ones_b[ones];}}main(){TMOD &= 0x0f;        /* clear timer 1 control bits     */TMOD |= 0x20;        /* set timer 1 to mode 2          */ 
TL1 = -3; TH1 = -3;  /* 9600bps with 11.059MHz crystal */TR1 = 1;P1=0x11;ones=0;tens=0;seconds=0;pulses=0 ;P3 = 0xff;RELAY=1;tens=(((~P3&0x80)>>1)|(~P3&0x38))>>3;ones=5;ET1=1;     /* enable timer 1 interupt */EA=1;      /* enable interupts        */ 
while (1){; }}

One Response to “Timer”

Leave a Reply

  • (will not be published)