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

Thread Starter

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();
	}
}
But instead of blinking, I get absolutely no activity.

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:

Thread Starter

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).
 

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....
 

Thread Starter

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 :p. 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:
Top