|
楼主 |
发表于 2006-11-29 21:26:19
|
显示全部楼层
谢谢各位,东改西改后,可以用了,放出改后的正确代码如下,这段程序是用来做光耦传器控制电机的一小段,整个做好后:
;*************************************
;File name : motor_step
;chip type : atmel mega8
;programe type : application
;clock frequency : 8MHZ
;memory model : small
;External SRAM size : 0
;*************************************
;PB0/1/2 AS CONTROL KDY INPUT
;PC0/1/2/3 AS DRIVER SINGAL OUTPUT
.include "m8def.inc"
.def temp =r16
.def temp1 =r17
.def temp2 =r18
.def count =r19
.def np =r20
.equ table_cycle =0x1f0
.org 0x0000
rjmp main
.org 0x0020
main:
ldi temp,0x02
out spl,temp
ldi temp,0x5f
out sph,temp
ldi temp,0b00011011 ;pb.0.1.3.4作为输出
out ddrb,temp
ser temp
out portb,temp
clr count
loop:
;****************
;*
for:
ser temp
out portb,temp
clr count
for_start:
clr np
clr temp
ldi zl,low(table*2)
ldi zh,high(table*2)
for1:
inc np
cpi np,5
breq for_start
push zl
add zl,temp
lpm
mov temp1,r0
out portb,temp1
inc temp
pop zl
rcall delay
inc count
cpi count,200
breq rev
rjmp for1
rev:
ser temp
out portb,temp
clr count
rev_start:
clr np
clr temp
ldi zl,low(table2*2)
ldi zh,high(table2*2)
rev1:
inc np
cpi np,5
breq rev_start
push zl
add zl,temp
lpm
mov temp1,r0
out portb,temp1
inc temp
pop zl
rcall delay
inc count
cpi count,200
breq for
rjmp rev1
;***********************
;*
delay:
ldi temp2,0x1E ;延时20ms程序,3层嵌套延时
push temp2
L0: push temp2
L1: push temp2
L2: push temp2
L3: dec temp2
brne L3
pop temp2
dec temp2
brne L2
pop temp2
dec temp2
brne L1
pop temp2
dec temp2
brne L0
pop temp2
ret
.org table_cycle
table:
.db 0x18,0x11,0x03,0x0a
table2:
.db 0x18,0x0a,0x03,0x11 |
|