# Problems with LED flashing, chaser, motor driver, basically anything I do.

#### Artikbot

Joined Nov 7, 2010
45
Hello,

I've been trying to get into the microcontroller world for some time now, but every time I make a new attempt, I miserably fail and quit for a month.

I'm currently on my fifth attempt, and probably well over my 100 hours of reading, coding, programming, re-checking code, re-checking circuitry, programming again,... But my circuits keep failing to work.

I'm trying to do the simple LED blinker, as sad as it sounds.

I run a 18F4220, programmed with a Kits R Us K150 programmer (I bought it built to ensure working condition).

The code is as follows. Ports in side B declared as all outputs, then a loop that turns them off, waits, turns them on, waits, and repeats itself. Clock set by INTOSCIO2, and set at 8MHz internal frequency.

Rich (BB code):
#include <p18f4220.h>

#pragma config OSC = INTIO2
#pragma config FSCM = OFF
#pragma config WDT = OFF,DEBUG = OFF

void delay (void)
{
int i;
for (i = 0; i < 10000; i++);
}
void main(void)
{
OSCCON = 0x72;

TRISB = 0;
while(1)
{
PORTB = 0;
delay();
PORTB = 0x5A;
delay();
}
}

The layout is pretty easy. Power from VDD pin, ground from VSS. From any of the side B pins to a resistor, then to a LED, to ground.

Power is fed via a 5V 1A LM7805 regulator-based PSU.

I think it has to do with fuses not being properly programmed, or whatnot. Because the code cannot be simpler...

Any help will be widely appreciated

Last edited:

#### t06afre

Joined May 11, 2009
5,934
What compiler do you use?

#### Artikbot

Joined Nov 7, 2010
45
First of all, thanks for reading

I use Microchip's own C18. I code on MPLAB 8.76, as MPLAB X seems to bug out in my system.

To burn the PIC I use Kits R Us' own MicroBrn, with the .hex files that come out of MPLAB needing to be fixed using their tool, FixHex (not entirely sure why, but if I don't do this the burner throws an error).

#### t06afre

Joined May 11, 2009
5,934
First then it comes to #pragma settings. As you are a beginner. Try to set the config bits in MPLAB it is in the toolbar under configure. Go thourgh all the bits. Also remember to disable the MCLR function. Then download this document. I know you do not use the same chip. But it can be useful as a primer

#### nerdegutta

Joined Dec 15, 2009
2,670
The layout is pretty easy. Power from VDD pin, ground from VSS. From any of the side B pins to a resistor, then to a LED, to ground.

Power is fed via a 5V 1A LM7805 regulator-based PSU.
Shouldn't one more pin be connected to POS via a resistor? MCLR or something. I don't remember and I could be way off....

#### MrChips

Joined Oct 2, 2009
19,387
Which pin of PORTB are you using to connect to the LED?
Why are you setting PORTB = 0x5A; ?
Use PORTB = 0xFF;

#### t06afre

Joined May 11, 2009
5,934
Shouldn't one more pin be connected to POS via a resistor? MCLR or something. I don't remember and I could be way off....
Good point. I think ALL VDD, VSS pins need to be connected

#### Artikbot

Joined Nov 7, 2010
45
Okay, I discovered that I can manually program the fuses in the burner. Apparently they are set properly now.

After doing this, I completely removed the delay routines in the code, and it turns on now, making me thing that the issue is the delay routine.

@nerdegutta: No idea... But why is it running now? o.o

@MrChips: I read it somewhere in the internet, in some of the thousand tutorials I've gone throug . I used to use a binary bit only for this matter until I read that 0x5A thing... I'll use your suggestion instead

@t06afre: Thanks for the heads-up, I'll pop cables to every Vdd and Vss pin

I'm writing a blinker using the delay.h as we speak. Reporting back soon!

Thanks a lot guys, you help is priceless

Edit: EPIC. I have a blinking led in front of me, a TRUCKLOAD of thanks to you guys, words cannot describe the happiness that fills me right now

Edit2: Implemented a table (or a vector, for this purpose) and an incremental variable to make a chaser, which happens to work

This weekend I'll experiment with the PWM controllers and try to build a DC motor driver, an RGB controller or whatever crosses my mind LOL. Thanks again!

Last edited: