Connect with us

I'm being really dim here

Discussion in 'Microcontrollers, Programming and IoT' started by JonnyFGM, Nov 3, 2012.

Scroll to continue with content
  1. JonnyFGM

    JonnyFGM

    14
    0
    Oct 24, 2012
    I can't even get this PIC16F676 to flash a laser on and off

    I can manage it with a PIC16F505, but i'm totally stumped here, I cant even get it to output a signal at all

    Any glaring errors in my code?

    Code:
    #include <xc.h>
    #define _XTAL_FREQ 4000000
    
    /*********CONFIG**********/
    
    
    #pragma DATA _CONFIG, _WDT_OFF & _CP_OFF & _INTRC_OSC_NOCLKOUT
    /******** GLOBAL VARIABLES ******/
    
    /******* MAIN PROGRAM *******/
    
    void main ()
    
    {
    
    TRISC = 0b00000000;
    
    	for (;;)
    		{
    
    		PORTC = 0b00000001;
    		__delay_ms(500);
    
    		PORTC = 0b00000000;
    		__delay_ms(500);
    
    		}
    
    }
    The code builds and programs ok so I'm not sure whats going off :S
     
  2. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Are you sure that the 'for' loop is running, why not use 'while' for this?
     
  3. JonnyFGM

    JonnyFGM

    14
    0
    Oct 24, 2012
    I cant be certain it's running as I dont have the header thing to run debugging.

    However it's not the for loop, as if I put the PORTC assignments to just be static, outside of the for loop the pin still doesn't go high
     
  4. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    I suppose this is stupid, but you do use portc bit0 for the output?
     
  5. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Another question, the reset vector is set to main()?

    How do you know that the chip is programmed properly? You have linked the program to release mode?
     
    Last edited: Nov 3, 2012
  6. JonnyFGM

    JonnyFGM

    14
    0
    Oct 24, 2012
  7. CocaCola

    CocaCola

    3,635
    5
    Apr 7, 2012
    Is MCLR taken care of at the board level?

    Also not 100% familar with the chip but, you might need to disable any analog functions on the pins uses...

    CMCON = 0x07; // turn off comparators

    Also add a third led on before the loop just toggle it on, this way you will at least know if the chip is coming to life...
     
  8. JonnyFGM

    JonnyFGM

    14
    0
    Oct 24, 2012
    MCLR is taken care of by the PICKIT2 I believe

    Unfortunately the CMCON thing doesn't seem to have fixed it. This is what the code looks like now

    Code:
    #include <xc.h>
    #define _XTAL_FREQ 4000000
    
    /*********CONFIG**********/
    
    //__CONFIG(MCLRE_OFF & CP_OFF & WDT_OFF & INTRCRB4);
    #pragma DATA _CONFIG, _WDT_OFF & _CP_OFF & _INTRC_OSC_NOCLKOUT
    /******** GLOBAL VARIABLES ******/
    
    /******* MAIN PROGRAM *******/
    
    void main ()
    
    {
    CMCON = 0x07;
    TRISC = 0b00000000;
    PORTC = 0b11111111;
    	for (;;)
    		{
    
    		PORTC = 0b00000001;
    		__delay_ms(500);
    
    		PORTC = 0b00000000;
    		__delay_ms(500);
    
    		}
    
    }
     
    Last edited: Nov 3, 2012
  9. JonnyFGM

    JonnyFGM

    14
    0
    Oct 24, 2012
    Ok I'm so confused :S

    I'm pretty sure the problem is the configuration word, the #pragma data method doesn't seem to do anything, I can put any gibberish after it and it will still build correctly.

    using the __config method means I can make it fail, but I cant figure out how to configure the internal oscillator with it

    Edit: Yes, was being massively massively dim. Turns out in the XC8 documentation there is details on how to setup the configuration data :) all working now :)
     
    Last edited: Nov 3, 2012
  10. wingnut

    wingnut

    242
    9
    Aug 9, 2012
    I am glad you got it working.

    I bought a Pickit3 and use the Pickit3 programmer rather than MPLAB, and Mikrobasic. After a huge struggle with the configuration word settings (which I found for the PIC16F677 on MPLAB under help, index, configuration) everything is working smooth as silk.

    Even doing ADC using Microbasic is so easy - no having to master all the internal registers as one has to do with assembler and JAL.

    Keep us posted on your future projects.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-