Maker Pro
Maker Pro

I'm being really dim here

JonnyFGM

Oct 24, 2012
14
Joined
Oct 24, 2012
Messages
14
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
 

gorgon

Jun 6, 2011
603
Joined
Jun 6, 2011
Messages
603
Are you sure that the 'for' loop is running, why not use 'while' for this?
 

JonnyFGM

Oct 24, 2012
14
Joined
Oct 24, 2012
Messages
14
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
 

gorgon

Jun 6, 2011
603
Joined
Jun 6, 2011
Messages
603
I suppose this is stupid, but you do use portc bit0 for the output?
 

gorgon

Jun 6, 2011
603
Joined
Jun 6, 2011
Messages
603
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:

CocaCola

Apr 7, 2012
3,635
Joined
Apr 7, 2012
Messages
3,635
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...
 

JonnyFGM

Oct 24, 2012
14
Joined
Oct 24, 2012
Messages
14
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:

JonnyFGM

Oct 24, 2012
14
Joined
Oct 24, 2012
Messages
14
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:

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
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.
 
Top