hamradio
Newbie level 6
- Joined
- Jul 17, 2011
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,376
Hello guys, I have a task for my study. The task is simple but for beginner in assembly it's not so easy.
The task is consist of writing a program for converting the ASCII numbers from 0 to 9 and the letters from A to F to it's decimal representation. And if the input value don't match these ranges to turn on a LED. Simple and easy sounds.
I reached a point where the code is working but the last check for the LED I can't explain to myself what is the right way.
So if you have time please have a look any help is appreciated.
The task is consist of writing a program for converting the ASCII numbers from 0 to 9 and the letters from A to F to it's decimal representation. And if the input value don't match these ranges to turn on a LED. Simple and easy sounds.
I reached a point where the code is working but the last check for the LED I can't explain to myself what is the right way.
So if you have time please have a look any help is appreciated.
Code:
;=============================
; DEFINITIONS
;=============================
#include p16f84a.inc ; Include register definition file
;================================
; VARIABLES
;================================
input EQU H'21'
result EQU H'23'
;================================
; RESET and INTERRUPT VECTORS
;================================
reset ORG 0000
goto Start
;================================
; CODE SEGMENT
;================================
ORG 0x10
Start
clrf result
movfw input ;load the input to W
addlw -D'10' ;check if the character code is it from A to F
addlw -H'30' ;substract the base
btfsc STATUS,C ; check the character
goto InputAF ; go to subroutine if the character code is in range A to F
addlw D'10' ; revert back to original character code
movwf result ; subtracted and saved.
goto Terminate
InputAF
addlw D'3' ; fill the number to the correct value
movwf result
goto Terminate
;===============================
Terminate
END