⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hcs-programmer.asm

📁 hcs300 programer,to program hcs300 with manufacture"code
💻 ASM
字号:
;**************************** HCS PROGRAMMER*******************************
;
;   File name   :  HCS PROGRAMMER.asm
;   DATE        :  2006.4.6-4.
;	DETAILS		:FOR HCS300/500
;				wait for program button-both led sparkling fast
;				in the beginning-both led sparkling for 2s
;				verify-led on
;				error-one led sparkling
;				success-led being on in turn
;*************************[ Included Define Files ]***********************
.include "m169def.inc"
.include "MEM-MAP.inc"
.def	temp=r16
.def	mtime=r17			;delay=m(ms)
.def	utime=r18			;delay=5+utime*3+3(us)
.def	count=r19
.def	wrdl=r20
.def	wrdh=r21
.def	tmpl=r22
.def	tmph=r23
.def	temp1=r24
;*************************[ reset ]**********************
	.org 0x00
	rjmp	reset
	.org	0x20
	reset:
	cli						;禁止全局中断
	ldi temp,0x02			;设堆栈指针
	out sph,temp			
	ldi temp,0x00
	out spl,temp
	ldi	temp,0x34			;设置pc2,4,5口输出,10(dp)
	out	ddrc,temp
	ldi temp,0x00
	out	portc,temp			
	ldi temp,0x03			;pg0,1输出,10(dp)
	out ddrg,temp
	ldi temp,0x00			;pd 输入
	out ddrd,temp
	out portd,temp
wait:
	ldi temp,0x00			;LED on
	out portg,temp
	ldi mtime,250
	call mdelay
	ldi temp,0x03
	out portg,temp
	ldi mtime,250
	call mdelay
	sbis pind,7				;等按键
	rjmp wait
	ldi mtime,100
	call mdelay
	sbis pind,7
	rjmp wait
	call mdelay
	sbis pind,7
	rjmp wait
;*************************[ main ]**********************

main:
	ldi temp,0x03			;LED off
	out portg,temp
	;sbi portc,4				;300 power on

	ldi temp1, 0x00
start:
	inc temp1
	ldi mtime,50			;50ms
	call mdelay
	ldi temp,0x00			;LED on
	out portg,temp
	ldi mtime,50
	call mdelay
	ldi temp,0x03
	out portg,temp
	cpi temp1,0x08
	breq setup
	rjmp start
setup:
	sbi portc,2			;clk=1,data=0
	cbi portc,5
	ldi mtime,Tps			;wait Tps (ms)
	call mdelay
	sbi portc,2			;clk=1,data=1
	sbi portc,5
	ldi mtime,Tph1			;Tph1
	call mdelay
	sbi portc,2			;c=1,d=0
	cbi portc,5
	ldi utime,Tph2			;Tph2
	call udelay
bulk:
	cbi portc,2			;c0d0
	cbi portc,5
	ldi mtime,Tpbw			;Tpbw
	call mdelay
program:
	ldi wrdl,key0
	ldi wrdh,key1
	call txword
	ldi wrdl,key2
	ldi wrdh,key3
	call txword
	ldi wrdl,key4
	ldi wrdh,key5
	call txword
	ldi wrdl,key6
	ldi wrdh,key7
	call txword
	ldi wrdl,SYNC_L
	ldi wrdh,SYNC_H
	call txword
	ldi wrdl,RES_L
	ldi wrdh,RES_H
	call txword
	ldi wrdl,SN0
	ldi wrdh,SN1
	call txword
	ldi wrdl,SN2
	ldi wrdh,SN3
	call txword
	ldi wrdl,SEED0_L
	ldi wrdh,SEED0_H
	call txword
	ldi wrdl,SEED1_L
	ldi wrdh,SEED1_H
	call txword
	ldi wrdl,RES_L
	ldi wrdh,RES_H
	call txword
	ldi wrdl,CONFIG_L
	ldi wrdh,CONFIG_H
	call txword
verify:
	ldi temp,0x01			;led on
	out portg,temp
	ldi	temp,0x04			;设置pc2输出,pc5输入
	out	ddrc,temp
	ldi tmpl,key0			;收第一帧
	ldi tmph,key1			
	call rxword	
	ldi tmpl,key2			
	ldi tmph,key3			
	call rxword			
	ldi tmpl,key4			
	ldi tmph,key5			
	call rxword			
	ldi tmpl,key6			
	ldi tmph,key7			
	call rxword	
	ldi tmpl,SYNC_L			
	ldi tmph,SYNC_H			
	call rxword		
	ldi tmpl,RES_L			
	ldi tmph,RES_H			
	call rxword		
	ldi tmpl,SN0			
	ldi tmph,SN1			
	call rxword		
	ldi tmpl,SN2			
	ldi tmph,SN3			
	call rxword		
	ldi tmpl,SEED0_L			
	ldi tmph,SEED0_H			
	call rxword				
	ldi tmpl,SEED1_L			
	ldi tmph,SEED1_H			
	call rxword				
	ldi tmpl,RES_L			
	ldi tmph,RES_H			
	call rxword				
	ldi tmpl,CONFIG_L			
	ldi tmph,CONFIG_H			
	call rxword								
;*****************[ success ]******************
success:
	ldi temp1,0x10			;4s交替
	;cbi portc,4				;300 power down
a:
	dec temp1
	cpi temp1,0x00
	breq b
	ldi mtime,0xff			;255ms
	call mdelay
	ldi temp,0x01			;LED on
	out portg,temp
	ldi mtime,0xff
	call mdelay
	ldi temp,0x02
	out portg,temp
	rjmp a
b:
	rjmp wait

        
;*****************[ To transmit the word ]******************
txword:
	ldi count,0x00
	clc
txbit:
	sbi portc,2 	;c1
	ror wrdh
	ror wrdl
	brcs hi		
	cbi portc,5		;d0
	rjmp txclk
hi: sbi portc,5		;d1
txclk:
	ldi utime,Tclkh
	call udelay
	cbi portc,2
	ldi utime,Tclkl
	call udelay
	inc count
	cpi count,0x10
	brne txbit
endoftx:
	cbi portc,5		;c0d0
	ldi mtime,Twc 	;Twc
	call mdelay
	ret
	
;*****************[ To receive the word and compare]******************
rxword:
	ldi count,0x00
rxbit:
	clc
	sbic pinc,5
	sec
	ror wrdh
	ror wrdl
rxclk:
	sbi portc,2		;c1
	ldi temp,Tclkh
	call udelay
	cbi portc,2
	ldi temp,Tclkl
	call udelay	
	inc count
	cpi count,0x10
	brne rxbit
endofrx:
	cpse wrdl,tmpl
	call error	
	cpse wrdh,tmph
	rjmp error
	ret
;************************[ ms delay ]**********************
;1mhz晶振,f=(3a+5)b+4=1000,mf(ms)误差+11us
mdelay:  
		ldi count,0x03	;b=3
		nop
del2:   
		ldi temp,0x6d	;a=109
del3:
		dec temp
        brne del3
		dec count
		nop
		nop
		brne del2
		dec mtime 		;m
		brne mdelay
		nop
		ret
;************************[ us delay ]**********************
;delay=5+utime*3+3
udelay:
		dec utime
		brne udelay
		ret
;*****************[ error ]******************
error:
	ldi mtime,0xff			;255ms
	call mdelay
	ldi temp,0x02			;LED on
	out portg,temp
	ldi mtime,0xff
	call mdelay
	ldi temp,0x03
	out portg,temp
	rjmp error

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -