Dear community,
I'm pretty new to microcontroller programming. So, please correct me if I say anything weird. And I'm new to the forums - hello, let's get along well allaboutcircuits community.
I'm still figuring out the basics of microcontroller programming, but I've read several guides here and there and wanted to experiment with some of them.
I'm using a PIC18f4550. (link datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf)
It can be recognized by the computer as a Human Interface Device.
USB connected to pins 24(D+), 23(D-), 32(Vdd) and 12(Vss).
I have 8 LEDs connected to pins 33(RB0) up to 40(RB7). If I'm not mistaken these are PORTB pins?
I'm using MPLAB with the mplabc18 compiler. I've written a small program, it's supposed to light the LEDs but they won't light and I don't know why.
In my project I've included the pic18f4550.h header file and a rm18f4550.lkr linker script.
I'm still not sure about the minimum files requirements which I should include to the project are. Are the header file of the pic and the linker script all?
Anyway, other than these two files, ofcourse my main:
This code builds fine and after I put the hex on my microcontroller and disconnect it from my computer,
I attach the circuit to a 5V adapter. Only the 7th LED lights, not even the 8th, as if it's only indicating there's current on the board.
I don't know what I'm doing wrong and some help would be greatly appreciated.
If anything is unclear or if I've provided unsufficient information please let me know.
Thanks for reading.
I'm pretty new to microcontroller programming. So, please correct me if I say anything weird. And I'm new to the forums - hello, let's get along well allaboutcircuits community.
I'm still figuring out the basics of microcontroller programming, but I've read several guides here and there and wanted to experiment with some of them.
I'm using a PIC18f4550. (link datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf)
It can be recognized by the computer as a Human Interface Device.
USB connected to pins 24(D+), 23(D-), 32(Vdd) and 12(Vss).
I have 8 LEDs connected to pins 33(RB0) up to 40(RB7). If I'm not mistaken these are PORTB pins?
I'm using MPLAB with the mplabc18 compiler. I've written a small program, it's supposed to light the LEDs but they won't light and I don't know why.
In my project I've included the pic18f4550.h header file and a rm18f4550.lkr linker script.
I'm still not sure about the minimum files requirements which I should include to the project are. Are the header file of the pic and the linker script all?
Anyway, other than these two files, ofcourse my main:
Rich (BB code):
#include <stdio.h>
#include <p18f4550.h>
#pragma config WDT = OFF
void main(void)
{
TRISB = 0 //set PORTB bits to output
/* Reset the LEDs */
PORTB = 0;
/* Light the LEDS */
PORTBbits.RB0 = 1;
PORTBbits.RB1 = 1;
PORTBbits.RB2 = 1;
PORTBbits.RB3 = 1;
PORTBbits.RB4 = 1;
PORTBbits.RB5 = 1;
PORTBbits.RB6 = 1;
PORTBbits.RB7 = 1;
while(1); //do nothing
}
I attach the circuit to a 5V adapter. Only the 7th LED lights, not even the 8th, as if it's only indicating there's current on the board.
I don't know what I'm doing wrong and some help would be greatly appreciated.
If anything is unclear or if I've provided unsufficient information please let me know.
Thanks for reading.