0

I made a simple circuit to blink an LED, but the code does not work in proteus simulation. See the code and the simulation below.

#INCLUDE "P18F2550.INC"

CONFIG WDT=OFF
CONFIG OSC=HS
CONFIG LVP=OFF

R2  EQU 0x2
R3  EQU 0x3
R4  EQU 0x4

ORG 0x0000

;Definindo todos os pinos de TRISA como entrada
MOVLW   b'11111111'
MOVWF   TRISA

;Definindo todos os pinos de TRISB como entrada
;exceto o pino 0 (RB0)
MOVLW   b'00000000'
MOVWF   TRISB

MOVLW 0x0000
MOVWF INTCON2 ;habilita a portB para 1

MAIN
    BTFSS   PORTA, RA0 ;Lê entrada do bit 0 de PORTA
    GOTO    ESTA_OFF
    ESTA_ON
        BSF PORTB, RB0; Manda 1 para RB0
        GOTO MAIN

ESTA_OFF
    BCF PORTB, RB0 ;Manda 0 para RB0
    GOTO MAIN

enter image description here

Does anyone have a solution to the problem? Thank you very much.

1 Answer 1

0

I'm not super familiar with the PIC, so I'm not sure if this is applicable, but it doesn't look like you have anything pulling down the RA0 pin on the PIC, so it'll float when the button isn't pressed. Try adding a high-value (say, 10k) resistor between the pin and ground to pull it down.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the tip, but I put the 10k resistor between the button and pin RA0, but failed.

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.