📄 no2.asm
字号:
;************* 宏方科技 HFKJAVR.asm ************************
;*
;* 标题:AT90S8535 集散式洁净空调自动控制系统
;* 版本: 1.0
;* 最后更新日期: 2002.11.01
;* 支援 TEL: 8102124 & 8106097
;*
;*************************************************************
.include"8535def.inc"
.org 0x00
.equ label=$0200
rjmp RESET ;
;.org 0x01 ;通用中断
;INTT0: RJMP GINT ;
;.org 0x06 ;timerl
;INTTT: RJMP TINT ;
.org 0x020 ;
RESET:
SYS: ldi R16,low(RAMEND) ;设置堆栈
out SPL,R16
ldi R16,high(RAMEND)
out SPH,R16
ldi r16,$28 ;8279写控制寄存器
out portd,r16
ldi r16,$d1
out portb,r16
sbi portd,4
ldi r20,0X30
rcall Delay
;wdr ;看门狗复位
;ldi R16,$0F ;0b00001111
;out WDTCR,R16 ;狗周期2048MS
ldi R16,$F8 ;0B11111000
out DDRA,R16 ;A口0~2输入,3~7输出
sbi porta,2
ldi R16,$FA ;0B11111110
out DDRD,R16 ;D口0/2输入,1/3~7输出
ldi R16,$FF ;0B11111111
out DDRC,R16 ;C口输出
out DDRB,R16 ;B口输出
ldi R16,$85 ;设置ADC转换,中断触发,ADC为单次模式且32M分频
out adcsr,R16
clr R16
out admux,R16 ;ADC 0通道
sbi adcsr,6 ;启动ADC
ldi r16,$98 ;初始化COM
out ucr,r16 ;设置UART控制寄存器---UCR
ldi r16,25
out ubrr,r16 ;设置UART波特率
ldi r16,$40 ;INT0可用,INT1屏蔽
out GIMSK,R16
ldi r16,$3 ;INT0上升沿触发
out mcucr,r16
cbi portd,4
ldi r16,$00 ;8279键盘显示方式初始
out portb,r16
sbi portd,4
nop
cbi portd,4
ldi r16,$22 ;8279时钟分频=2
out portb,r16
sbi portd,4
clr r17
clr r19 ;ADIN 4051地址计数
ADC1: sbic adcsr,adsc ;转换结束跳行否则等待
rjmp ADC1
in r2,adcl ;把转换结果送r2,r3
in r3,adch
sbic pina,2 ;读开关量
ldi r18,$0 ;开关量关
ldi r18,$1 ;开关量开
cpi r19,16
breq cl
rjmp cl1
cl: clr r19
cl1: ldi r27,$01 ;传数据到SRAM 0100 处
mov r26,r19
st x+,r2 ;传低位数据 0100
st x,r3 ;传高位数据 0101
adiw r26,$10
st x,r18 ;传开关量到 0111
rcall display ;调用显示子程序
inc r19
cpi r17,8 ;比较4051地址是否到8通道相等跳转
breq ta
rjmp tb
ta: clr r17
sbic admux,0
rjmp t0
sbi admux,0
rjmp addmux
t0: cbi admux,0
rjmp addmux
tb: inc r17
rjmp addmux
addmux: cpi r17,0 ;确定4051地址
breq ina
cpi r17,1
breq inb
cpi r17,2
breq ini
cpi r17,3
breq ind
cpi r17,4
breq ine
cpi r17,5
breq inf
cpi r17,6
breq ing
cpi r17,7
breq inh
rjmp adc1
ina: cbi porta,3 ;4051地址通过置位清位输出
cbi porta,4
cbi porta,5
rjmp ys
inb: sbi porta,3
sbi portd,5
cbi portd,4
rjmp ys
ini: cbi porta,3
sbi porta,4
rjmp ys
ind: sbi porta,3
rjmp ys
ine: cbi porta,3
cbi porta,4
sbi porta,5
rjmp ys
inf: sbi porta,3
rjmp ys
ing: cbi porta,3
sbi porta,4
rjmp ys
inh: sbi porta,3
rjmp ys
ys:
ldi r20,0X56 ;延时1秒
rcall Delay
sbi adcsr,6 ;启动ADC
rjmp adc1 ;
display:
sbi portd,5
cbi portd,4
ldi r23,$90
out portb,r23
sbi portd,4
cbi portd,5
ldi zh,high(label*2)
mov zl,r19
lpm
cbi portd,4
out portb,r0
sbi portd,4
ldi zh,high(label*2)
mov r16,r3
swap r16
rcall outpd1
mov r16,r3
rcall outpd2
mov r16,r2
swap r16
rcall outpd3
mov r16,r2
rcall outpd4
ret
outpd1: andi r16,$0f
ldi zl,low(label*2)
add zl,r16
lpm
cbi portd,4
out portb,r0
sbi portd,4
ret
outpd2: andi r16,$0f
ldi zl,low(label*2)
add zl,r16
lpm
cbi portd,4
out portb,r0
sbi portd,4
ret
outpd3: andi r16,$0f
ldi zl,low(label*2)
add zl,r16
lpm
cbi portd,4
out portb,r0
sbi portd,4
ret
outpd4: andi r16,$0f
ldi zl,low(label*2)
add zl,r16
lpm
cbi portd,4
out portb,r0
sbi portd,4
sbi portd,5
ret
delay: push r20 ;2t延时子程序
l0: push r20 ;2t
l1: push r20 ;2t
l2: push r20 ;2t
l3: dec r20 ;1t
brne l3 ;1t/2t
pop r20 ;2t
dec r20 ;1t
brne l2 ;1t/2t
pop r20 ;2t
dec r20 ;1t
brne l1 ;1t/2t
pop r20 ;2t
dec r20 ;1t
brne l0 ;1T/2T
pop r20 ;2t
ret ;4t
.cseg
.org $0200
.dw 0x063f,0x4f5b,0x6d66,0x077d
.dw 0x6f7f,0x7c77,0x5e39,0x7179
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -