0
\$\begingroup\$

I've been struggling for the past few days trying to get this to work right and need a professional to take a look at this and see where I am going wrong:

Code:

; James 
; 5/8/24
; Global Vars
TrisA equ 0x85
TrisB equ 0x86
Status equ 0x03
PortA equ 0x05; This bit is the register, so PortA is not used in Setup.
PortB equ 0x06
;Setup+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BSF Status, 0x05; Bit 5 points to bank 1
Movlw 0x0f; moves 0000 1111 into W reg
Movwf TrisA; Moves W to TrisA, Port A is input
Movlw 0x00; moves 0000 0000 into W reg
Movwf TrisB; Moves W to TrisB, Port B is output
BCF Status, 0x05; Bit 5 points back to bank 0
;Run======================================================================
START clrf PortB; clears PortB
    clrf PortA; clears PortA
    Movf PortA,0; Moves inputs to W reg
    Movwf PortB; Moves W reg to outputs
Call Delay
Goto START
Delay Movlw 0X08; moves 0000 1000 to Reg W, sets 8ms timer
    MOVWF 0X0C; Moves Reg W to Reg C
Dec DECFSZ 0X0C,1; Decrements Reg C by 1 ms
    goto Dec; will keep looping until Reg C hits 0, timer ends
        Return
end

Schematic: The schematic

The Breadboarded design The Breadboarded design

Lab reqs:

  1. Using a slow clock or delay loops, develop a program that will output in 4 bit binary code the input of 4 switches.
  2. The program, once started should continue to run and scan or search the input switches until the power is removed.

I would like to note that the code I am using here was provided as-is from my professor, however, either an element in the code or design just gives me a dead circuit.

\$\endgroup\$
7
  • \$\begingroup\$ You forgot to mention what the circuit and code is supposed to do and what it actually does! Hit the edit link. \$\endgroup\$ Commented May 21, 2024 at 1:07
  • \$\begingroup\$ I just updated it to include the lab requirements. \$\endgroup\$ Commented May 21, 2024 at 1:14
  • 1
    \$\begingroup\$ Please make your source readable. Start with some good indentation (labels on the left, mnemonics at a fixed column, operands at a second fixed column, comments at a third), use consistent case (mnemonics all caps or none), separate logical blocks by empty lines, consider to avoid redundant comments... Additionally draw a readable schematic using the editor provided by this site. Your handwriting is blurry and barely readable. Is that power supply really 9V? \$\endgroup\$ Commented May 21, 2024 at 5:44
  • 1
    \$\begingroup\$ Use of a decoupling capacitor is recommended. \$\endgroup\$ Commented May 21, 2024 at 6:11
  • 1
    \$\begingroup\$ Your schematic has a label on the right which reads "VSS +9V". Leaving aside the fact that "Vss" is usually the negative supply (not positive), if you've applied 9V to your PIC then it's probably dead. a PIC18F84's maximum operating voltage is 6V (and most people typically operate it in the 3-5V range). \$\endgroup\$ Commented May 21, 2024 at 11:47

1 Answer 1

2
\$\begingroup\$

There are issues with your code, schematic and component choices.

  • The photo of your prototype does not show the power busses connected correctly.

  • The maximum voltage used to power the PIC16F84A must be 5.0 volts.

  • The values of RC network used to create the system oscillator of 600KHz are not connected correctly and should be 10K ohms and 100 picofarads.

  • A bypass capacitor of 100 nanofarads should be connected between pin 5 and 14 of the PIC16F84A to help filter the power to the controller.

This is what your code should look like:

;
; File:     main.asm
; Compiler: MPASMWIN v5.51
; IDE:      MPLAB v8.92
;
;
;                        PIC16F84A
;                +----------:_:----------+
;      SW3 <>  1 : RA2               RA1 : 18 <> SW2
;      SW4 <>  2 : RA3               RA0 : 17 <> SW1
;          <>  3 : RA4/T0CKI        OSC1 : 16 <- 10K/100pF (Fosc 600KHz @ 5.0V)
; ICSP_VPP ->  4 : MCLR             OSC2 : 15 ->
;      GND ->  5 : GND               VDD : 14 <- 5v0
;     LED1 <>  6 : RB0/INT       PGD/RB7 : 13 <> ICSP_PGD
;     LED2 <>  7 : RB1           PGC/RB6 : 12 <> ICSP_PGC
;     LED3 <>  8 : RB2               RB5 : 11 <>
;     LED4 <>  9 : RB3               RB4 : 10 <>
;                +-----------------------:
;                         DIP-18
;
;
; James
; 5/8/24
; Global Vars
TRISA   equ 0x85
TRISB   equ 0x86
STATUS  equ 0x03
PORTA   equ 0x05            ; This bit is the register, so PORTA is not used in Setup.
PORTB   equ 0x06

    __CONFIG (0x3FF3)
;
; The RC components should be selected for a Fosc clock of 600KHz
;
;Setup+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    org     0x0000
    bsf     STATUS,0x05     ; Bit 5 points to bank 1
    movlw   0x0f            ; moves 0000 1111 into W reg
    movwf   TRISA           ; Moves W to TrisA, Port A is input
    movlw   0x00            ; moves 0000 0000 into W reg
    movwf   TRISB           ; Moves W to TrisB, Port B is output
    bcf     STATUS,0x05     ; Bit 5 points back to bank 0
;Run======================================================================
START:
    clrf    PORTB           ; clears PortB
    clrf    PORTA           ; clears PortA
    movf    PORTA,0         ; Moves inputs to WREG
    movwf   PORTB           ; Moves WREG to outputs
    call    Delay
    goto    START
Delay:
    movlw   0XC8            ; Moves 1100 1000 decimal (250) to Reg W, sets 200Hz delay
    movwf   0X0C            ; Moves Reg WREG(250) to Reg C
Dec:
    decfsz  0X0C,1          ; Decrements Reg C by 20us
    goto    Dec             ; Will keep looping until Reg C hits 0, timer ends
    return                  ; Returns after 5 milliseconds
    end

This is what your HEX file should look like:

:020000040000FA
:1000000083160F308500003086008312860185013B
:10001000050886000C200628C8308C008C0B0E28A2
:020020000800D6
:02400E00F33F7E
:00000001FF
\$\endgroup\$
7
  • 2
    \$\begingroup\$ Nice code formatting. That's how I remember it from many years ago. Revision date format should be yyyy-mm-dd though. We're programmers! \$\endgroup\$ Commented May 22, 2024 at 22:40
  • \$\begingroup\$ @Transistor, Revision date? MY CODE IS TIMELESS! Besides I'm from the land of the middle-endians our dates are mm-dd-yy, frustration, confusion, chaos, my work is complete :) \$\endgroup\$ Commented May 22, 2024 at 23:10
  • \$\begingroup\$ Definitely seems like it may work, however, the smallest capacitors I am provided are .001 uF, versus the .0001 uF (100 pF) listed in the schematic. Are there any potential changes I may apply to get at least a close enough result? \$\endgroup\$ Commented May 23, 2024 at 1:06
  • \$\begingroup\$ I decided to try and do the math and am using a .001 uF cap with a 1M resistor instead of a 10k plus a .0001 uF cap, only deviation I have with the changes you proposed, and I am still not getting any outputs... \$\endgroup\$ Commented May 23, 2024 at 1:54
  • \$\begingroup\$ @JamesTDG, The PIC16F84A data sheet specifies the MAXIMUM value for the resistor is 100K ohms. Using 100K and .001uF capacitor in place of 10K and 100pF capacitor should make the Fosc clock at about 6KHz rather than 600KHz. When the RC resistor is too large the OSC pin input leakage current can cause RC oscillator to stop. \$\endgroup\$ Commented May 23, 2024 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.