# [PIC]PIC16F84A - MPLAB programming **Feedback needed **

Status
Not open for further replies.

#### dannyelloko20

##### Newbie level 5
Hi there again, I have another project and is your feedback is needed at this point. This is what I need to do: " Read the 4-bit Switch value and then multiply the switch value by the decimal number 100 ( D’100’). Display the results on the LEDs. Must use a loop counter (“Count”) to implement this Lab. Use the literal D’100’ to set the “Count” variable and each time thru the loop add the switch value to the accumulated “SUM”. Each time thru the loop the “Count” is decrement and when you reach 0, you are done. Use REG1 for the MS byte and REG0 for the LS byte of the SUM. When S17 is a logic “0”, display the LS byte on the LEDs and when S17 is a logic ‘1” display the MS byte.

This is what I have so far and I think it needs some debugging. I would appreciate your feedback.

Code:
BSF   STATUS,RP0
MOVWF   TRISB
BCF     STATUS,RP0
MOVWF   PORTB

LOOP MOVLW   0x5A
MOVWF   REG0
MOVLW   0x39
BTFSS   PORTA,RA0
BTFSC   PORTA,RA0
COMF    REG1,W
GOTO   DONE

BTFSC   PORTA,RA0
BTFSC   PORTA,RA0
MOVWF   PORTB

GOTO  LOOP

DONE  END
PD: Library for PIC16F84A is included in my program. Thank you!

#### pjmelect

##### Advanced Member level 2
Where do I begin? You should post the full circuit and program list if you want help.

Some obvious errors are the bottom 6 lines of code are never executed because of the GOTO DONE instruction and the W register is not set for the MOVWF TRISB instruction. The W register is not set for the MOVWF PORTB instruction (should it have been MOVF PORTB,W?), the register REG1 has not been defined or used etc. I have not checked the logic of the program as I do not see how it can work

Last edited:

#### dannyelloko20

##### Newbie level 5
Thanks for the feedback. This is all of it.

Code:
#include <GENERAL.H> ; PIC library

REG0   EQU   0x40
REG1   EQU   0x41

__CONFIG	0X3FF2
ORG			0X0000
GOTO		START
ORG			0X0004
RETFIE

START   BSF     STATUS,RP0
MOVWF   TRISB
BCF     STATUS,RP0
MOVWF   PORTB

LOOP    MOVLW   0x5A
MOVWF   REG0
MOVLW   0x39
BTFSS   PORTA,RA0
BTFSC   PORTA,RA0
COMF    REG1,W
GOTO    FINISHED

BTFSC   PORTA,RA0
BTFSC   PORTA,RA0
MOVF    PORTB
GOTO    LOOP

FINISHED    END

Status
Not open for further replies.