PIC18F4580 isn't turning the LED on in Proteus

68 views Asked by At

I have this code for the MCU (pic18f4580) :

#include <pic18F4580.h>

#pragma config OSC=HS
#pragma config LVP=OFF
#pragma config PBADEN=OFF
#pragma config WDT=OFF
#pragma config MCLRE=ON

#define _XTAL_FREQ 4000000

void main(void) {
    TRISB = 0x00;
            
    while(1) {
        PORTB = 0xFF;
        //_delay_ms(500);
    }
    return;
}

I have generated the hex file with MPLAPX and compiler XC8

This is the schemata I made in Proteus, but the LED won't turn on:

enter image description here

2

There are 2 answers

0
Mike On

You had to switch the port RB0 to digital, on default it is an analog port.

ADCON1 = 0x01;

See section 20.0 in the datasheet.

0
Mohamed Ahmed Mokhtar On

There is 2 problem

1)In proteus you have to connect power to "VPP" pin (pin number 1 in the microcontroller at the bottom right).

2)In code PORTB used to read inputs on pins(reads the levels on the pins of the device), instead you have to use LATB register (output latch) to control pin as high or low.

Remove

PORTB = 0xFF;

TO

LATB = 0xFF;

and if you need to toggle it every 500 milliseconds

LATB ^= 0xFF;