Led not blinking.

JohnInTX

Joined Jun 26, 2012
4,787
@lemario You have to use INTOSC, not INTOSCIO which has a different meaning.

Also, make sure you connected the anode to GP2 and the cathode to GND.

@JohnInTX I, sometimes, neglect the ANSEL register and still get a proper output.

LE: @lemario Have you ever considered using Proteus? It's a virtual simulation machine which enables you to use various components.
INTOSCIO is correct here - it uses the internal oscillator without outputting the clock to GP4. That said, you could temporarily use that mode to verify that the clock is running at the frequency you expect.
The LED should be connected as stefan said.
You might get away with ignoring ANSEL in a few cases but not in this one. Bit-oriented IO won't work on an analog port.

If you set OSCCON to 31khz with the current project settings, the delays computed by MikroC won't be correct. In this case, a 1 sec delay will take about 129 sec to execute because MikroC thinks the clock is running at 4MHz and will make the delays have more counts to compensate.

MikroC's sim will step through the code in a debug window. You also can import the .COF file into MPLAB/X.

@lemario Post a schematic - it doesn't have to be fancy. Use the Upload a File button. Also, I think you have to have 10 posts (maybe more) before you are allowed to edit. Its an anti-spam thing.

How are you using PICkit2 with MikroC? If you are importing the .HEX file into some other program, make SURE that the configuration bits are included in the .HEX (inspect the CONFIG settings in the programmer's operation window). MikroC doesn't always include CONFIG bits in their .HEX unless you are programming through their interface.

EDIT: revisit your project settings an:
Disable Internal/External switchover, BrownOut and FailSafe Clock monitor for now.
 
Last edited:

stefan.54

Joined Dec 26, 2015
28
@lemario Your software Pickit2 programmer should look like this (with a 2 instead of 3 in the name)

I'd suggest you read some tutorials/articles about the PIC basics aswell as how you code and upload you "project" to the MCU.

Don't worry, we all started from the bottom.
 

Attachments

Thread Starter

lemario

Joined Jan 31, 2016
22

Mod edit: Please upload images to AAC instead of a 3rd party site. That way images stay with the posts forever.
 
Last edited by a moderator:

JohnInTX

Joined Jun 26, 2012
4,787
Looks like the config bits are there - you still should disable the FailSafe monitor, BrownOut and SwitchOver bits. Your INTERNAL oscillator is outputting to GP4. If you set that TRIS bit to 0, you should see the clock out to verify its running. If you have done the other stuff it should run. I would still set TRISIO with a byte write i.e. TRISIO = 0x00; to set all the bits to output. You might consider flashing all bits for now to eliminate r-m-w issues as a problem i.e.

C:
TRISIO = 0x00; // all out
ANSEL = 0x00; // all digital
OSCCON = ob01100000;  // 4MHz, Clock determined by CONFIG bits

while(1){
GPIO = 0xff;  // write IO as a byte, not as r-m-w
delay_ms(1000);
GPIO = 0x00;
delay_ms(1000);
}//while
Post your current code and we can compare notes.
Aside: don't worry if you don't understand r-m-w yet. Many don't. Some think they do and still don't. Try the byte write and if it works, we can discuss why that is. One thing at a time :)
 

Thread Starter

lemario

Joined Jan 31, 2016
22
you still should disable the FailSafe monitor, BrownOut and SwitchOver bits
I have done that.

When i build it gives me an error at "ob01100000"

- "Unddeclared indentifier 'ob01100000' "



Code:
void main() {
   TRISIO = 0x00;
   ANSEL = 0x00;
   OSCCON = ob01100000;  // 4MHz, Clock determined by CONFIG bits
 
   while(1)
   {
           GPIO.B2 = 0xff;
           Delay_ms(1000);
           GPIO.B2 = 0x00;
           Delay_ms(1000);
   }
}
 

Thread Starter

lemario

Joined Jan 31, 2016
22
@dannyf thanks, it builded.

But it still aint blinking.. :/

Tomorrow ill probably get a "voltage reader device" to give me more info to give you guys..
 

dannyf

Joined Sep 13, 2015
2,197
I tryed everything i belive.
Nope.

To help you out, try burn this .hex to the pic and see what happens.
Code:
:02000000EA2FE5
:100FD4008301EC2F83169F01073083129900831637
:100FE4008501FF30831285068230F100DD30F00088
:0C0FF400F00BFA2FF10BFA2FFF2FF32F58
:02400E00D4F0EC
:00000001FF
You should see the led blinking at 0.1s intervals (on 0.1s and off 0.1s).

It is essentially your code, with one additional statement.
 

Thread Starter

lemario

Joined Jan 31, 2016
22
I did. Did not work :/ <- what i mean by this is that i took your hex code and it still does not work. just to clarify :)
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830

JohnInTX

Joined Jun 26, 2012
4,787
One thing you could try is to pull the PIC and just connect the socket pin to Vdd (with a resistor of course) to ensure that you have the LED circuit correct.
Sorry for the 'o'
 

Thread Starter

lemario

Joined Jan 31, 2016
22
GOOD NEWS BOYS! It was the leds! I was using some leds that came gifted when i bought the microcontroller's. I did what JohnInTX sugested and tryd the led circuit alone and it was not working. So i switched to some other leds that were "still in the box" and it worked :)

Thank you all for your help and patience with my nooby questions :)
 
Last edited:
Top