Hi all, I need a help with one of my first programs, wich function is to visualize in a 7 segment display connected to PORTD, the number of bits set to 1 in input on the PORTC.
The program is not complete, but I started to compile and try it as I always do when I write software.
I post the code and than I explain which is my problem.
At the moment I am just trying to put in output the binary value of the bits set to 1 in PORTC to PORTD (copied from i to nbits), just to understand if I doing it correctly, but seems that in PORTD I have the binary value of the address of nbits, wich is 0x21.
Can you help me please to understand and solve this problem?
Thank you.
Simo
The program is not complete, but I started to compile and try it as I always do when I write software.
I post the code and than I explain which is my problem.
Rich (BB code):
; Name: EX5
; Author: Simo
LIST p=16f877a, r=HEX
INCLUDE p16F877A.INC
__CONFIG _CP_OFF&_DEBUG_OFF&_WRT_OFF&_CPD_OFF&_LVP_OFF&_BODEN_ON&_PWRTE_ON&_WDT_OFF&_HS_OSC
ORG 0x00
;step tp bank #1
bsf STATUS, RP0 ;set RP0
bcf STATUS, RP1 ;clear RP1
movlw 0xff ;set PORTC as input
movwf TRISC
movlw 0x00 ;set PORTD as output
movwf TRISD
;step to bank #0
bcf STATUS, RP0 ;clear RP0
bcf STATUS, RP1 ;clear RP1
CBLOCK 0x20
i
nbits
ENDC
main:
call count
movwf PORTD ;copy data to PORTD
count
clrf i ;clear i to make sure it starts from 0
btfsc PORTC, 0 ;if bit0 is not set, look up to bit1
incf i, 1 ;if set increse i by one
btfsc PORTC, 1 ;if bit1 is not set, look up to bit2
incf i, 1 ;if set increse i by one
btfsc PORTC, 2 ;if bit2 is not set, look up to bit3
incf i, 1 ;if set increse i by one
btfsc PORTC, 3 ;if bit3 is not set, look up to bit4
incf i, 1 ;if set increse i by one
btfsc PORTC, 4 ;if bit4 is not set, look up to bit5
incf i, 1 ;if set increse i by one
btfsc PORTC, 5 ;if bit5 is not set, look up to bit6
incf i, 1 ;if set increse i by one
btfsc PORTC, 6 ;if bit6 is not set, look up to bit7
incf i, 1 ;if set increse i by one
btfsc PORTC, 7 ;if bit7 is not set leave function
incf i, 1 ;if set increse i by one
movlw i
movwf nbits
return
end
Can you help me please to understand and solve this problem?
Thank you.
Simo