;Dick Cappels' project pages sap@cappels.org - you should be able to copy and paste this text into an assembler file.
   ;©2002 Richard Cappels All Rights Reserved
;Use of information presented on this page is for personal, nonprofit educational
;and noncommercial use only. This material (including object files) is copyrighted
;by Richard Cappels and may not be republished or used directly for commercial
;purposes without explicit permission For commercial license,
click HERE.
;

;HOME

;*********************************
;AT90S1200 program to restore fuses on ATtiny12 to factory defaults.
;;*********************************
   
;This has successfully restored the RESET ENABLE, SPI DISABLE, INTERNAL CLOCK, and SECUIRTY MODE 1 fuses.
   
   
.include "1200def.inc"     
.list
   
.def	temp	=r16
.def	tmult =r17
   
   
; AT90S1200 specific information and definitions
   
   
;PORTB assignments
.equ	LED	=0	;B0 	High to light LED
   
;PORTD assignments
;Pins on PORTD correspond to pins on target PORTB
.equ	sin 	= 0	;D0	Serial data in to target
.equ	sinst 	= 1	;D1	Serail instructions in to target
.equ	dout	= 2	;D2	Data out from target
.equ	clk	= 3	;D3	Clock in to targtet
.equ	vcc	= 4	;D4	VCC to target
.equ	nreset	= 5	;D5	Ground reset pin (PB5) on target
.equ	plus12	= 6	;D6	+12V to target reset pin (PB5)
   
;Note that PD5 is kept as an input and weak pullups are switched to 
; switch the grounded emitter transistor connected to its output.
   
.cseg
   
.ORG $0000
	
;.ORG $0002
;	rjmp timerservice
   
start:
   
	ldi	tmult,$0
startdelay:
	ldi	temp,$0
tloop:
	dec	temp
	brne	tloop
	dec	tmult
	brne	tloop
   
	ldi	temp,$5B		;Setup PORTD data
	out	DDRD,temp
   
	ldi	temp,$20		;Setup DDRD
	out	PORTD,temp
   
	ldi	temp,$00		;Set up PORTB data all zeros
	out	PORTB,temp
	
	ldi	temp,$FF		;Set up DDRB
	out	DDRB,temp
   
   
   
	rcall	shortdelay
	
	sbi	PORTD,vcc		;Apply VCC to target
	
	rcall	shortdelay	
   
   
	ldi	temp,$10	;Toggle Bit 3 16 times
toggle3:
	
	rcall	clockit
	dec	temp
	brne	toggle3
	
	rcall	shortdelay
	
	ldi	temp,$50	;Apply +12V to target
	out	PORTD,temp
	
	rcall 	shortdelay
   
   
	
				;Shift out data
	
	;coded as PD0 as lsb and PD1 as msb
	
   
	;Instruction 1
	rcall	p0	
	rcall	p0
	rcall	p3
	rcall	p0
	rcall	p0
	rcall	p2
	rcall	p2
	rcall	p0
	rcall	p0
	rcall	p0
	rcall	p0
   
	
	;Instruction 2
	rcall	p0
	rcall	p0
	rcall	p1
	rcall	p2
	rcall	p1
	rcall	p2
	rcall	p2
	rcall	p1
	rcall	p0
	rcall	p0
	rcall	p0
   
	;Instruction 3
	rcall	p0
	rcall	p0
	rcall	p2
	rcall	p2
	rcall	p0
	rcall	p0
	rcall	p2
	rcall	p0
	rcall	p0
	rcall	p0
	rcall	p0
   
		
	;Intsruction 4
	rcall	p0
	rcall	p0
	rcall	p2
	rcall	p2
	rcall	p0
	rcall	p2
	rcall	p2
	rcall	p0
	rcall	p0
	rcall	p0
	rcall	p0
	
	;STOP AND SHUT DOWN
	
	ldi	temp,$40
	out	PORTD,temp
	rcall	shortdelay
	ldi	temp,$00
	out	PORTD,temp
	
finished:
	sbi	PORTB,LED		;Light the LED on PB0
	rjmp	finished ;320 us
	
	
	
p0:
	cbi	PORTD,sinst	;PD1
	cbi	PORTD,sin	;PD0
	rcall	clockit
	ret
	
   
p1:
	cbi	PORTD,sinst	;PD1
	sbi	PORTD,sin	;PD0
	rcall	clockit
	ret
	
p2:
	sbi	PORTD,sinst	;PD1
	cbi	PORTD,sin	;PD0
	rcall	clockit
	ret
	
   
	
p3:
	sbi	PORTD,sinst	;PD1
	sbi	PORTD,sin	;PD0
	rcall	clockit
	ret
		
   
   
   
clockit:
	sbi	PORTD,clk
	cbi	PORTD,clk
	ret
	
   
shortdelay:	;16 cycle delay routine (about 13 us at 4 MHz)
	ldi	temp,$10
stilldelaying:
	dec	temp
	brne	stilldelaying
	ret		
   
   
   
   
   
;www.projects.cappels.org/
   
   ;HOME