汇编语言中从 00 到 99 的计数器
基本上我的任务是使用汇编语言使微控制器板上的计数器从00到99连续计数。
因为不可能同时显示两个7段,所以我的解决方案是显示十位(0),显示个数(0),显示十位(0),显示一(1),显示十位( 0),显示一(2),显示十(0),显示一(3)等。我这样做的方法是有两个循环(一个用于十位数字,一个用于个位数字),通过大批。一旦个位循环遍历整个数组,循环就会中断并返回到十位数字循环,将十位数字移动到下一个元素,然后返回到个位数字循环,
MSB_Display equ $0B ; display on 'tens' digit/second most right of 7-Seg
LSB_Display equ $07 ; display on 'ones' digit/most right of 7-Seg
D_1MS equ 24000 / 6
DelayVal equ 35 ; 35 ms delay simulates both Hex Displays on at once
org $1000
; Lookup table for LED segments
array db $3F,$06,$5B,$4F,$66,$6D,$7C,$07,$7F,$6F
; 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
; Memory Reserved for Delay Routine
DCount ds 1
Counter ds 1
countones db 0
counttens db 0
org $2000 ; Program starts here
lds #$2000 ; Initalize the stack
; Configure Hardware
ldaa #$FF
staa DDRB ; Make PORTB output
staa DDRP ; PTP as Output
start
clr countones ; clear count back to 0
clr counttens
ldx #array
MSB
ldaa 1,x+
staa PORTB
ldaa #MSB_Display
staa PTP ; turn off 7-segment display
bsr Delay_ms
inc counttens
ldaa counttens
cmpa #10
bne LSB
LSB
ldy #array
ldab 1,y+
stab PORTB
ldab #LSB_Display
stab PTP
bsr Delay_ms
inc countones
ldaa countones
cmpa #10
bne LSB
bra MSB
Delay_ms
psha
pshy
ldaa #DelayVal ; Number of msec to delay
staa DCount ; store delay counter
ldaa DCount ; delay Dcount ms
staa Counter
Delay1 ldy #D_1MS ; 6000 x 4 = 24,000 cycles = 1ms
Delay2 dey ; this instruction takes 1 cycle
bne Delay2 ; this instruction takes 3 cycles
dec Counter
bne Delay1 ; not Dcount ms yet, delay again
pula ; Restore contents of ACC A before returning
puly
rts
end
现在看起来程序进入了个位数字循环(LSB)并坐在那里,它不会退出该循环,也不会重新循环本身。我似乎找不到我的程序逻辑有什么问题
Basically my task is to make the counter on a micro controller board count from 00-99 continuously using assembly language.
because it is not possible to show two 7-Seg to display at the same time, my solution is to display the tens(0), display ones(0), display tens(0), display one(1), display tens(0), display one(2), display tens(0), display one(3), etc. my approach to doing this is to have two loops (one for the tens digit, one for the ones digit) that goes through an array. once the ones digit loop have gone through the entire array, the loop breaks and goes back to the tens digit loop, move the tens digit to the next element, then back to the ones digit loop
MSB_Display equ $0B ; display on 'tens' digit/second most right of 7-Seg
LSB_Display equ $07 ; display on 'ones' digit/most right of 7-Seg
D_1MS equ 24000 / 6
DelayVal equ 35 ; 35 ms delay simulates both Hex Displays on at once
org $1000
; Lookup table for LED segments
array db $3F,$06,$5B,$4F,$66,$6D,$7C,$07,$7F,$6F
; 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
; Memory Reserved for Delay Routine
DCount ds 1
Counter ds 1
countones db 0
counttens db 0
org $2000 ; Program starts here
lds #$2000 ; Initalize the stack
; Configure Hardware
ldaa #$FF
staa DDRB ; Make PORTB output
staa DDRP ; PTP as Output
start
clr countones ; clear count back to 0
clr counttens
ldx #array
MSB
ldaa 1,x+
staa PORTB
ldaa #MSB_Display
staa PTP ; turn off 7-segment display
bsr Delay_ms
inc counttens
ldaa counttens
cmpa #10
bne LSB
LSB
ldy #array
ldab 1,y+
stab PORTB
ldab #LSB_Display
stab PTP
bsr Delay_ms
inc countones
ldaa countones
cmpa #10
bne LSB
bra MSB
Delay_ms
psha
pshy
ldaa #DelayVal ; Number of msec to delay
staa DCount ; store delay counter
ldaa DCount ; delay Dcount ms
staa Counter
Delay1 ldy #D_1MS ; 6000 x 4 = 24,000 cycles = 1ms
Delay2 dey ; this instruction takes 1 cycle
bne Delay2 ; this instruction takes 3 cycles
dec Counter
bne Delay1 ; not Dcount ms yet, delay again
pula ; Restore contents of ACC A before returning
puly
rts
end
right now it seems like the program enters the ones digit loop (LSB) and sits there, it does not exit that loop nor does it reloop itself. I can't seem to find whats wrong in the logic of my program
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从堆栈中取出应按照与放入堆栈相反的顺序进行。
正如艾拉指出的那样,你的计数器混淆了......
你应该将“显示两位数字”视为与循环中增加某些计数器不同的事情。
显示是简单地切换带有时间延迟的“活动”输出,并为每个显示周期设置正确的数字值。
这是执行此操作的一种方法(调整延迟值 - 35 毫秒看起来很快...):
如果将显示代码放在单独的例程中,并且每次计数器增加时多次切换活动显示,那就更好了。这对你来说可能是一个很好的练习:)
Pulling from stack should be done in reverse order from putting on stack.
As Ira pointed out you got your counters mixed up...
You should think of 'displaying two digit number' as a separate thing from increasing some counter in a loop.
Displaying is simple switching 'active' output with a time delay, and setting correct digit value for each display cycle.
Here is one way of doing this (adjust delay value - 35ms looks to fast...):
It would be even better to have display code in a separate routine, and to switch active display more than once per counter increase. That could be a nice exercise for you :)