0
\$\begingroup\$

I started learning PIC some days ago and have played around with different tutorials. Many of the tutorials I have read, doesn't work for me. I always have to change stuff in the code to make it work, so I actually havn't had any succes yet.

Now I have some code, that SHOULD work (if yiu ask me), but it doesn't. It builds without any errors, byt after burning it, nothing happends. No LED's are blinking or anything.

Could someone please help me figure out why this is not working and maybe explain why. I have read alot of pages on the net, but havn't found anything that could give me a solution, so now I have to ask for help. Thanks

I'm working with a 12F629 and Pickit 1

#include <htc.h> 

#define _XTAL_FREQ 4000000     // oscillator frequency
#include <delay.h>           // defines DelayMs() 

__CONFIG(FOSC_INTRCIO & WDTE_OFF & CP_OFF & MCLRE_OFF);

void main() 
{ 
// Initialisation 
    TRISIO = 0b111100;

// Main loop 
for (;;) { 
    GP0 = 1;
    GP1 = 1; 
            __delay_ms(200);      
    GP0 = 0;
    GP1 = 0; 
            __delay_ms(200);            
}                  
} 
\$\endgroup\$
6
  • \$\begingroup\$ See the example code I gave in this question, it should work fine with the 12F629. \$\endgroup\$
    – Oli Glaser
    Sep 25 '11 at 11:15
  • \$\begingroup\$ Show the schematic! (We shouldn't have to ask for obvious things like this) Show the actual schematic, don't hand wave in words what you meant to have hooked up to what. \$\endgroup\$ Sep 25 '11 at 14:02
  • \$\begingroup\$ Thanks for helping me out. I already read your answer in the other thread, but nothing worked. I switched the PIc for another and I found out it was my PIC :( It can read and write without errors, but it seems to be bugged somehow. the new one is working great. \$\endgroup\$
    – user5860
    Sep 25 '11 at 19:18
  • \$\begingroup\$ Thanks for helping me out. I already read your answer in the other thread, but nothing worked. I switched the PIc for another and I found out it was my PIC :( It can read and write without errors, but it seems to be bugged somehow. the new one is working great. I have another small problem though. The timer is running very unstable even with a capacitor between + and -. I have a LED that should flash twice with 50ms between and then wait 100ms and start over. Like a police flash. But I can see that the timing is off and it's flashing very unstable. Any idear how to fix this? \$\endgroup\$
    – user5860
    Sep 25 '11 at 19:22
  • \$\begingroup\$ It would help if you update your question with current code and maybe a schematic or description of your setup. In the meantime, try putting a small delay (e.g. __delay_us(5)) in between the GP0 = 1; and GP1 = 1; (and the GPx = 0; pair too) Or you can set/clear both pins at once with GPIO = 0x03; and GPIO = 0x00; (or use a shadow register) This is to do with read modify write, see here for some info. \$\endgroup\$
    – Oli Glaser
    Sep 25 '11 at 20:36
2
\$\begingroup\$

My blink-a-led page at http://www.voti.nl/blink/ has circuits and .hex files for ao. the 12f629. Use it to check whether your circuit and programming procedure are OK. Getting your own code to work is a next step.

\$\endgroup\$
1
\$\begingroup\$

The 12F629 has a anlog comparator, so you have to disable it for the pins it uses to work in digital mode. I don't remember which pins those are. See the datasheet.

Also, if you're trying to blink a LED, why are you leaving any pins inputs that could be outputs? Write 0 to the TRIS register so that all pins that can be outputs are. Remember that not all pins can be outputs. Again, see the datasheet.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.