; general device setup ; this is for the ATtiny 85 ; project contains timer, ADC , pinchange IRQ .NOLIST ; Disable listfile generation .include "tn85def.inc" .LIST ; ; constants 1 Mhz clk (8 mhz /8) , PB 0-1 outputs ,PB 2-4 input ; ; today : a soldering iron controller ; the iron is measured by a thermal element. ; typical voltages are ; 1 mV @ 20 C ; 12mV @ 340 C ; and so on ; with the ADC set to 1.1 Volt reference and 20 X gain we can expect values around ; 240 for 350 C ; 20 for 20 C ; .equ ROMSTART = 0x0100 .equ RAMSTART = SRAM_START .equ debouncecount = 0x08 .equ blinkenlights = 0x20 ; modes are simply preset temperatures ; 300 C, 350 C, 400 C, 450 C .equ maxmode = 0x05 ; configure the ADC .equ ADMUXset = 0b10000111 ; data right adjusted, differential input on PB3/PB4 , 20 x gain, 1.1 volt reference .equ ADCSRAset = 0b00010010 .equ ADCSRBset = 0b00000000 ; no bin mode .equ DIDR0set = 0b00011000 .equ TCCR0Bset = 0b00000000 ; prescaler / 2 = 64 khz @ 128 khz clk ; hardware ports .equ Power = 0 ; output to iron controller .equ buttonlo = 1 ; temperature dec control switch .equ ADinA = 3 ; from temperature diode .equ ADinB = 4 ; in sold. iron .equ button = 2 ; temperature inc control switch ;register usage .def adlo =r10 ; AD value .def adhi =r11 ; .def zero =r12 ; offset value from calib routine .def temp =r16 ;misc usage, must be in upper regs for IMMED mode .def temphi =r17 ;misc usage, higher byte for word access .def del = r18 ; delay counter .def bounce = r19 .def tlo =r22 ; 10 bit temperature preset .def thi =r23 ; .def oldmode =r24 .def mode =r25 ; ************** MAIN PROGRAM STARTS HERE ************************* .CSEG .ORG 0x0 rjmp RESET ; Reset Handler rjmp EXT_INT0 ; IRQ0 Handler rjmp PC_INT0 ; PCINT0 Handler rjmp TIM0_OVF ; Timer0 Overflow Handler rjmp EE_RDY ; EEPROM Ready Handler rjmp ANA_COMP ; Analog Comparator Handler rjmp TIM0_COMPA ; Timer0 CompareA Handler rjmp TIM0_COMPB ; Timer0 CompareB Handler rjmp WATCHDOG ; Watchdog Interrupt Handler rjmp ADC_INT ; ADC Conversion Handler ; EXT_INT0: RETI ; the pinchange irq increments the mode or decrements upon ; buttons pressed ; contains debounce code for pushbutton ; increment value PC_INT0: ldi bounce,debouncecount ; debouncer pcirq2: sbic pinb,button rjmp pcirq3 ; test for other button dec bounce brne pcirq2 ; next test for pressed key bclr SREG_I ; passed, disable irq inc mode ; next mode cpi mode,maxmode ; is limit reached brcs pcirq0 ; no , maxmode is still bigger than mode ldi mode,maxmode ; else set to max pcirq0: ldi bounce,debouncecount ; debouncer pcirq1: sbis pinb,button ; check for button release rjmp pcirq0 dec bounce brne pcirq1 bset SREG_I ;enable irq RETI ; decrement value pcirq3: sbic pinb,buttonlo RETI ; was spurious dec bounce brne pcirq3 bclr SREG_I ; passed bounce test dec mode cpi mode,0xff ; check for lower limit brne pcirq4 ldi mode,0x00 ; set to 0 pcirq4: ldi bounce,debouncecount pcirq5: sbis pinb,buttonlo rjmp pcirq4 dec bounce brne pcirq5 bset SREG_I ; stubs TIM0_OVF: EE_RDY: ANA_COMP: TIM0_COMPA: TIM0_COMPB: WATCHDOG: ADC_INT: RETI ; RESET: cli ; first switch off the WD wdr in temp, MCUSR ; clr the WDRF bit andi temp, (0xff & (0<