Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PICKit 1 and Simple LED

Status
Not open for further replies.

Dalaran

New Member
Hi all,

I am very new to microcontrollers but am very excited to learn the fundamentals of them. I have purchased a PICkit1 for just this reason.

I have tried to create a simple blinking LED using a PIC16F684 and PICkit 1 development board from Microchip. However, all I am getting is constant LED luminance (D0 on the PICKit1 demo board) and it does not seem to be pulsing at all.

I have created it in c using the HI-TECH C Compilier.

Does anyone see any problems in my few lines of code here? Basically have a 2ms delay nested inside a for-loop for 128 repetitions. This should give me approximately 2Hz on the output.

#include <htc.h>
#define _XTAL_FREQ 4000000

main(){
int i;
PORTC = 0x00; // PORTC low
CMCON0 = 0x07; // turn off comparators
ANSEL = 0x00; // turn off ADC
TRISC = 0x00; // set as output
while(1 == 1){
PORTC = 0xff; //PORTC set high
for(i = 0; i <= 127; i++){
__delay_ms(2);
CLRWDT();
}

PORTC = 0x00; //PORTC set low
for(i = 0; i <= 127; i++){
__delay_ms(2);
CLRWDT();
}
}
}

Thanks for the help.
 
Last edited:

Dalaran

New Member
No, no problem. Thanks for your time. I have atleast a tiny bit of background in C so I figured this was the best place to start.

Cheers
 

Dalaran

New Member
It is the 'Clear Watchdog Timer' command. I actually took this from an example given in the Hi-Tech directory for 'delays'. It performs the same with or without the command.

Thanks.
 

skyhawk

New Member
The default period for the WDT is 17 ms, so it's timing out before you clear it. Unless you have a reason to use the WDT, I would disable it in the configuration word and software. See 12.1 and 12.6 in the data sheet. The other option is to change the period to a longer value.

edit: I just looked at the code more carefully. I see that the CLRWDT command is inside the loop and being executed every 2 ms; therefore, I have no explanation.
 
Last edited:

skyhawk

New Member
I haved worked with the PICkit 1 demo board in awhile. In fact, I gave mine away when I got a PICkit 2. Aren't the LEDs connected to PORT A not PORT C? In addition, aren't the LEDs Charlieplexed so that the anode has to be high and the cathode low in order to light?
 

Dalaran

New Member
Thanks all. I really appreciate the help. I will look into understanding the WDT and MCLR disabling. As for the delay_ms(500); it wouldn't let me do. It told me I exceeded 'x' amount of cycles.

Skyhawk, you are correct, the LED's are connected to PORTA. I was actually following an example from class where I guess the TA had not actually tried his code out. They are also connected in a very weird fashion. By looking at the schematic it looks like I will have to control more than one of the PORTA outputs to control a single LED - will need to set one low and one high. Guess I had it in my head that they would all be connected to ground.

Thanks for the help. I will play around with this and get back to you guys with my findings.
 

Dalaran

New Member
Thanks all. Now have the code working. The only issue I still have is that initially when I load the program the LED is illuminated. It seems that the program does not actually start running i.e. LED turning on and off, until I push the push-button switch on the pickit 1 board. Is this normal for these pickits, or is there a way I can go at by-passing this?

Thanks again.
 

skyhawk

New Member
The PIC resets with all the pins in a high impedance state, so no LED should light. In order to light an LED you have to set the pins driving the LED to output with the anode high and the cathode low. An LED is off when either of its driving pins are in a hi-Z state (or when it is reverse biased).

The program responds to the bottom push because there is some statement in the code testing the pin to which the buttom is attached. Based on the test the program starts looping, but the program starts running as soon as it finishes reset.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top