;*************************************************************************** ;* File : DCKpar.inc (included by DCKprog.asm) ;* Author : Dave Keenan ;*************************************************************************** ;* ;* INTERRUPT ;* TIM0_OVF - Software UART Service Routine ;* and square-wave generator for voltage multiplier. ;* ;*************************************************************************** TIM0_OVF: in savedSREG,SREG ; store SREG ldi tempi,(256-N+8) out TCNT0,tempi ; reset T/C0 to one bit lenght inc bit_cnt ; increment bit counter sbrs u_stat,TXC ; if (transmit complete flag clear) rjmp transmit ; goto transmit sbrc u_stat,RXC ; if (receive complete flag clear) rjmp END_TX_RX ; goto receive receive: sec ; set carry sbis PIND,RXPIN ; if (RxD == LOW) clc ; clear carry ror u_data ; shift carry into u_data cpi bit_cnt,8 ; if (bit_cnt == 8) brne END_TX_RX ; { out TIMSK,zero ; disable T/C0 Overflow Interrupt sbr u_stat,1<2ms). ldi temp1,2*PROC_CLOCK/7710+1 rjmp delay ;Equiv to: rcall delay, ret ;Can't call subroutines from these routines when ;the timer interrupts are enabled because the ;AT90S1200 only has a 3 deep return stack. ;*************************************************************************** LEAVE_PAR_PROG_MODE: ;Kill the voltage multiplier. cbr u_stat,1<15ms for the voltage multiplier capacitors ; to discharge sufficiently to ensure that slave /RESET is low. ldi temp1,15*PROC_CLOCK/7710+1 rcall delay ;Note that these delays cannot be arbitrarily increased because the host read ;will timeout when reading fuse and lock bits. ret ;*************************************************************************** WR_FUSE_BITS: ;from u_data ;Load the "Write fuse-bits" command. ldi temp1,WR_FUSE_BITS_CMD ;Set the command to "write fuse bits". out PORTB,temp1 ;XTAL1 action already set to "load command". sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 ;Load the fuse-bits data. sbi PORTD,XA0_RX ;Change XA0 first so it has time to rise (180k resistor) before pulsing XTAL1. ldi temp1,PROC_CLOCK/10000-1 ;Wait at least 3 us (180 k) d3us: dec temp1 brne d3us . cbi PORTD,XA1 ;Set XTAL1 action to "load data". out PORTB,u_data ;Set data to value from host. sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 ;Give /WR a negative pulse of at least 1ms duration. ; This is also sufficient time for RDY/BSY to go high, ; and therefore we don't get a negative pulse on RDY/BSY at all. cbi PORTD,NOT_WR_TX ;This won't affect TX to the host because NOT_OE is high. ldi temp1,1*PROC_CLOCK/7710+1 rjmp delay ;Equiv to: rcall delay, ret ;*************************************************************************** RD_FUSE_LOCK_BITS: ;into u_data ;Load the "Read fuse and lock bits" command. ldi temp1,RD_FUSE_LOCK_CMD ;Set the command to "read fuse and lock bits". out PORTB,temp1 ;XTAL1 action already set to "load command". sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 out DDRB,zero ;Make port B all inputs. ;Read the data sbi PORTD,XA0_RX ;Set BS high by setting both XA0 and XA1 high. ;XA1 should already be high from ENTER_PAR_PROG_MODE. cbi PORTD,NOT_OE ;This won't affect TX to the host because NOT_WR_TX is high. nop ;Give time for NOT_OE to fall (4k7 resistor). nop nop in u_data,PINB ;Get data ready to send to host. ret ;*************************************************************************** PAR_CHIP_ERASE: ;Parallel chip erase ;Load the "Chip erase" command. ldi temp1,CHIP_ERASE_CMD ;Set the command to "chip erase". out PORTB,temp1 ;XTAL1 action already set to "load command". sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 ;Give /WR a negative pulse of at least 10ms duration. cbi PORTD,NOT_WR_TX ;This won't affect TX to the host because NOT_OE is high. ldi temp1,10*PROC_CLOCK/7710+1 rjmp delay ;Equiv to: rcall delay, ret ;*************************************************************************** PAR_WR_LOCK_BITS: ;Parallel write lock bits ;Load the "write lock bits" command. ldi temp1,WR_LOCK_BITS_CMD ;Set the command to "write lock bits". out PORTB,temp1 ;XTAL1 action already set to "load command". sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 ;Load the lock-bits data. sbi PORTD,XA0_RX ;Change XA0 first so it has time to rise (180k resistor) before pulsing XTAL1. ;May need more delay here for faster clock??? cbi PORTD,XA1 ;Set XTAL1 action to "load data". out PORTB,u_data ;Set data to value from host. sbi PORTD,XTAL1 ;Pulse slave XTAL1 high. cbi PORTD,XTAL1 ;Give /WR a negative pulse of at least 10ms duration. cbi PORTD,NOT_WR_TX ;This won't affect TX to the host because NOT_OE is high. ldi temp1,10*PROC_CLOCK/7710+1 rjmp delay ;Equiv to: rcall delay, ret