存储数字 PIC ASM
所以,我知道如何在按下按钮时生成一个随机数,但我不确定如何存储一个数字,更不用说两个数字,然后当它不在按钮循环中时让它不会发疯。 现在这是我的代码。
抱歉,它不整洁,不知道如何为该网站正确格式化它。
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay1
Delay2
Display
Num1
Boolean
Boolean2
Boolean3
Num2
Num3
LastStableState
Counter
endc
org 0
Start:
BANKSEL TRISA
movlw 0xFF
movwf TRISA
movwf TRISB
clrf TRISC
BANKSEL ANSEL
clrf ANSEL
BANKSEL PORTC
clrf Display
clrf Num1
clrf Num2
clrf Boolean
clrf PORTC
movlw 1
movwf Boolean
movwf Boolean2
movwf Boolean3
movwf LastStableState
clrf Counter
MainLoop:
btfsc LastStableState,0
goto LookingForUp
LookingForDown:
clrw
btfss PORTB,7
incf Counter,w
movwf Counter
goto EndDebounce
LookingForUp:
clrw
btfsc PORTB,7
incf Counter,w
movwf Counter
incf Display,f
EndDebounce:
movf Counter,w
;xorlw 4
btfss STATUS,Z
goto Delay1mS
comf LastStableState,f
clrf Counter
btfss LastStableState,0
goto Delay1mS
btfsc Boolean,0
goto Num1Set
btfsc Boolean2,0
goto Num2Set
goto Step3
Delay1mS:
movlw .02
Call Delay
goto MainLoop
Delay:
movwf Delay2
DelayLoop:
decfsz Delay1,f
goto DelayLoop
decfsz Delay2,f
goto DelayLoop
return
Num1Set:
movf Display,w
movwf Num1
movwf PORTC
clrf Boolean
goto Delay1mS
Num2Set:
movf Display,w
movwf Num2
movwf PORTC
clrf Boolean2
goto Delay1mS
Step3:
;movf Display,w
movlw Num2
movwf PORTC
goto Delay1mS
;andlw Num1
;movwf PORTC
;call Delay1mS
;goto Start
end
So, I know how to generate a random number when a button is pressed, but I am not sure how to store one number, let alone two, and then have it not go crazy when it's not in the button loop.
Here is my code now.
Sorry for the untidiness of it, don't know how to properly format it for this site.
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay1
Delay2
Display
Num1
Boolean
Boolean2
Boolean3
Num2
Num3
LastStableState
Counter
endc
org 0
Start:
BANKSEL TRISA
movlw 0xFF
movwf TRISA
movwf TRISB
clrf TRISC
BANKSEL ANSEL
clrf ANSEL
BANKSEL PORTC
clrf Display
clrf Num1
clrf Num2
clrf Boolean
clrf PORTC
movlw 1
movwf Boolean
movwf Boolean2
movwf Boolean3
movwf LastStableState
clrf Counter
MainLoop:
btfsc LastStableState,0
goto LookingForUp
LookingForDown:
clrw
btfss PORTB,7
incf Counter,w
movwf Counter
goto EndDebounce
LookingForUp:
clrw
btfsc PORTB,7
incf Counter,w
movwf Counter
incf Display,f
EndDebounce:
movf Counter,w
;xorlw 4
btfss STATUS,Z
goto Delay1mS
comf LastStableState,f
clrf Counter
btfss LastStableState,0
goto Delay1mS
btfsc Boolean,0
goto Num1Set
btfsc Boolean2,0
goto Num2Set
goto Step3
Delay1mS:
movlw .02
Call Delay
goto MainLoop
Delay:
movwf Delay2
DelayLoop:
decfsz Delay1,f
goto DelayLoop
decfsz Delay2,f
goto DelayLoop
return
Num1Set:
movf Display,w
movwf Num1
movwf PORTC
clrf Boolean
goto Delay1mS
Num2Set:
movf Display,w
movwf Num2
movwf PORTC
clrf Boolean2
goto Delay1mS
Step3:
;movf Display,w
movlw Num2
movwf PORTC
goto Delay1mS
;andlw Num1
;movwf PORTC
;call Delay1mS
;goto Start
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你真的必须使用汇编程序吗?如果没有,用 C 语言编写你想要的东西是很容易的。在 ASM 中手动管理内存位置中的数据很麻烦,在 C 中你只需要声明 2 个变量来存储随机数。
您甚至可以保留 ASM 函数,只需将它们包装起来(使用所需的推送、弹出调用),以便您可以从 C 上下文中调用它。
Do you really have to use assembler? If not, writing what you want in C is quite easy. Hand managing data in memories positions is cumbersome in ASM, in C you just need to declare the 2 variables to store your random numbers.
You can even keep your ASM functions, just wrap them (with the needed push, pop calls) so you can call it from a C context.