Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top