Beruflich Dokumente
Kultur Dokumente
Lab1
1. Fill Bank1 RAM with value 0x55.
To fill Bank 1 with 0x55, one has to first put 0x55 in the writing register. The memory
address to be addressed first is set to the first memory space of bank 1. POSTINC0 is a
register which uses the contents of FSR0 to address data memory. If the program has not
yet reached the next bank ( bank 2) which is checked by the condition btfss
FSR0H,1; ,
the value in the writing register will be moved to the memory space which POSTINC0 is
pointing to.
When bank 1 is full and bank 2 is reached, the condition btfss
FSR0H,1; becomes true,
therefore it is skipped and the program enters an infinite loop goto $
LIST p=18f45k50
include <p18f45k50.inc>
LOOP:
org 0
clrf
movlw
lfsr
WREG
0x55
0,0x100 ;move literal to fsr,fsr is a special register used
for memory addressing, 100 is starting address
POSTINC0
FSR0H,1 ; checking bank memory number
LOOP
movwf
btfss
goto
goto $
;endless loop, dollar sign means the current address, so
continuously going to current address
END
clrf
movlw
movwf
movlw
movwf
movlw
movwf
movlw
movwf
movf
addwf
movwf
movf
addwfc
movwf
clrf
addwfc
WREG
b'11111111'
val1a
b'11111111'
val1b
b'00000000'
val2a
b'00000001'
val2b
val2b, W
val1b, W
ansb
val2a, W
val1a, W
ansa
WREG
ansc, f
goto $
END
movlw
mulwf
the shifted bit
movf
movwf
movlw
mulwf
movf
movwf
movf
addwf
movlw
shifted bit
WREG
b'00000011'
addthreelow
b'00110000'
addthreehigh
b'01010000'
chkfivehigh
b'00000101'
chkfivelow
b'00001111'
andreg
b'00000100'
counter
b'11111111'
valueone
b'11110000'
valuetwo
b'00000010'
answerone
PRODL, W
answerone
b'00000010'
answertwo
PRODL, W
answertwo
PRODH, W
answerone, F
b'00000010'
mulwf
movf
movwf
movf
addwf
movlw
mulwf
movf
movwf
movf
addwf
valueone
PRODL, W
valueone
PRODH, W
answertwo, F
b'00000010'
valuetwo
PRODL, W
valuetwo
PRODH, W
valueone, f
incf
btfsc
goto
counter
counter, 4
CONT
clrf
addwf
cpfslt
goto
WREG
chkfivehigh, W
answerone
ADDINGHIGHONE
cpfslt
goto
answertwo
ADDINGHIGHTWO
movff
addwf
andwf
cpfsgt
goto
answerone, checker
answerone, W
andreg, W
chkfivelow
ADDINGLOWONE
clrf
movff
addwf
andwf
cpfsgt
goto
goto
WREG
answertwo, checker
answertwo, W
andreg, W
chkfivelow
ADDINGLOWTWO
LOOP
ADDINGHIGHONE:
clrf
addwf
addwf
clrf
addwf
cpfslt
goto
goto
WREG
addthreehigh, W
answerone, F
WREG
chkfivehigh, W
answertwo
ADDINGHIGHTWO
ADDINGLOWONE
ADDINGHIGHTWO:
clrf
addwf
addwf
clrf
addwf
andwf
cpfsgt
goto
clrf
addwf
andwf
cpfsgt
goto
goto
WREG
addthreehigh, W
answertwo, F
WREG
answerone, W
andreg, W
chkfivelow
ADDINGLOWONE
WREG
answertwo, W
andreg, W
chkfivelow
ADDINGLOWTWO
LOOP
ADDINGLOWONE:
clrf
addwf
addwf
clrf
addwf
andwf
cpfsgt
goto
goto
WREG
addthreelow, W
answerone, F
WREG
answertwo, W
andreg, W
chkfivelow
ADDINGLOWTWO
LOOP
ADDINGLOWTWO:
clrf
addwf
addwf
goto
WREG
addthreelow, W
answertwo, F
LOOP
CONT:
goto $
END
4. Convert a BCD digit into a decoded 7-segment pattern using table lookup instructions.
To convert a BCD digiti into a decoded 7-segment pattern, a look up table was used. The
look up table was saved starting from memory address 0x7000. Initially the table pointer
was set to point to 0x7000 memory address. The number which the user want to convert to
a 7- segment pattern is multiplied by 2 (hence rotated to the left by one place) since
memory is organized in two byte words. The resultant rotated number is moved to the low
table pointer and this value then returns the pattern from the look up table which is then
saved in variable test 1. The pattern assumed is for a common anode display displaying 4.
LIST p=18f45k50
include <p18f45k50.inc>
bcd1
test1
equ 0x01
equ 0x05
org 0x0
movlw
0x04
movwf
bcd1
movlw
movwf
movlw
movwf
movlw
movwf
LOW _TABLE
TBLPTRL
HIGH _TABLE
TBLPTRH
UPPER _TABLE
TBLPTRU
rlncf
movff
bcd1, f
bcd1, TBLPTRL
tblrd*
movf
movwf
goto
TABLAT, W
test1
$
org 0x7000
_TABLE
DB
DB
DB
DB
DB
DB
DB
DB
DB
DB
b'11000000'
b'11111001'
b'10100100'
b'10110000'
b'10011001'
b'10010010'
b'10100000'
b'11111000'
b'00000000'
b'10011000'
;0
;1
;2
;3
;4
;5
;6
;7
;8
;9
END
The value which this program is testing for is 0x04, the number 0x08 is the rotated value of
0x04 ( hence multiplied by 2) to get the corresponding pattern in the table. Memory
addresses always end in an even value since the memory is arranged as a set of words each
containing two bytes of data, hence the value had to be multiplied by two since the next
value was found in the next memory space located one word from the current one.