cmicrocontrollermikroc

PORTB of PIC18F452 not working


I am trying an example available in the MikroC pro for PIC compiler which writes and reads some bits from the EEPROM, and displays the results on the LEDs attached to the PIC18F452 MCU.

The code is written in C. And I am simulating all this in proteus simulation. My schematic is as shown below:

Schematic

The pins on PORTB are showing change in logic, but they are not able to turn on the LEDs. I know this is not a hardware problem, but a software problem.

Can you see my C code and tell me what I'm doing wrong:

char ii;                                 // loop variable

void main(){
  ADCON1 = 0x07;

  PORTB = 0;
  PORTC = 0;
  PORTD = 0;

  TRISB = 0;
  TRISC = 0;
  TRISD = 0;

  for(ii = 0; ii < 32; ii++)             // Fill data buffer
    EEPROM_Write(0x80+ii, ii);           // Write data to address 0x80+ii

  EEPROM_Write(0x02,0xAA);               // Write some data at address 2
  EEPROM_Write(0x50,0x55);               // Write some data at address 0150

  Delay_ms(1000);                        // Blink PORTB and PORTC LEDs
  PORTB = 0xFF;                          //   to indicate reading start
  PORTC = 0xFF;
  Delay_ms(1000);
  PORTB = 0x00;
  PORTC = 0x00;
  Delay_ms(1000);

  PORTB = EEPROM_Read(0x02);             // Read data from address 2 and display it on PORTB
  PORTC = EEPROM_Read(0x50);             // Read data from address 0x50 and display it on PORTC

  Delay_ms(1000);

  for(ii = 0; ii < 32; ii++) {           // Read 32 bytes block from address 0x80
    PORTD = EEPROM_Read(0x80+ii);        //   and display data on PORTD
    Delay_ms(250);
    }
}

Solution

  • From the schematic, it looks like you have connected the LED bar graph on port B the wrong way around (the polarity appears to be opposite to what you have for the other two bar graphs).