Friday, 2 December 2016

pic - Need help with hardware and software config on PIC12F675 to light up an LED



I'm trying to get an output from a PIC12F675, but I can't seem to get it to work. Here is my hardware setup that I breadboarded:


enter image description here


And here is my code programmed using a PicKit2:


#include 
__CONFIG(FOSC_INTRCIO & WDTE_OFF & CPD_OFF);

void main()
{
TRISIO = 0b111101;
GP1 = 1;

for(;;)
{
;
}
}

What am I missing here?


Any help is appreciated, Thanks!


EDIT: fixed code, but still not functional


    TRISIO = 0b111110;

GP0 = 1;
for(;;)

Answer



If the schematic is correct, then you are setting the wrong pin. You need to set GP0 to 1 (and alter the TRISIO accordingly too)


EDIT - Okay, see code below. This has been confirmed to work in MPLAB SIM using HI-Tech v9.81. I tried to comment a bit to give an idea of what is going on. Note I turned MCLR off in the config bits.
The main thing was the Comparator needing to be disabled (CMCON, see comments/datasheet)
I added a (commented) flashing routine in the for loop for interest.
For the GPIO port pins, GPIOx, or GPx should work fine.


#include 


// Define oscillator frequency for delay routines
#define _XTAL_FREQ 4000000

// Make sure config bits are correct in your version
//(e.g. v9.61, 9.81, etc) These work in v9.81 but NOT in v9.61
// Config bits are listed in e.g. Program Files->Hi-Tech->PICC->v9.81->include
__CONFIG(FOSC_INTRCIO & WDTE_OFF & CPD_OFF & MCLRE_OFF);

void main()
{

GPIO = 0; // Initialise GPIO to a known state
ANSEL = 0x00; // Analog inputs disabled so we can read state of pin (e.g. in MPSIM, or needing to read-modify-write)
CMCON = 0x07; // Comparator peripheral turned off
TRISIO = 0b11111110; // Set GPIO0 to output

GPIO0 = 1; // Note GPIO0 used, not GP0 (see 12F675 include file in directory mentioned above)

for(;;)
{
/*

GPIO0 = 1; // Uncomment to flash GPIO0
__delay_ms(100); // Hi-Tech "built in" delay routine - needs _XTAL_FREQ (oscillator frequency) defining
GPIO0 = 0;
__delay_ms(100);
*/
}

}


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...