PIC16F648A not doing anything

Thread Starter

MrDarkArtz

Joined Aug 22, 2017
1
Hi Ladies & Gents

This is my first post here! I was wondering if there was anyone that could shine some light on an issue I have?

I am extremely new to all this so bare with! I have a PIC16F648A micro controller, a PicKit3 and a few other bits. I wrote a simple code that would turn RA1 on and off with a delay of 1s. It's about 5 lines of code and I wrote it in MPLAB XC8 v4. I uploaded it to my PIC successfully, popped a 1k resistor on RA1 and LED positive on the other end of the resistor, the negative on a separate rail running from the negative of a 5v breadboard power supply. Waited and nothing... at all. I'm confident it's going to be me doing something wrong I just don't know what yet! PIC is powered by the PicKit3 but I've also tested powering it without the PicKit3, still nothing.

Am I making sense here or talking rubbish?

Thanks guys, I appreciate any help.

James
 

jayanthd

Joined Jul 4, 2015
945
Comparator on PORTA not disabled.

You have to configure CMCON register.

Is the code compiled for Debug or Release ? If Debug then change it to Release.

Have you enabled MCLR pin. If yes, then you need a 10k pull-up resistor for it.

Code:
CMCON = 0x07;
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
I messed with this a bit the xc8 will not let you set osccon after a hour looking at the files there is not a osccon fixed just add the header to your mplab x name it 16f684a.h
Code runs fine in sim just make sure you add the header and name it to 16f684a.h
Code:
/*
* File:   main.c
* Author: burt
*
* Created on August 22, 2017, 10:00 AM
*/


// CONFIG
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = ON         // Low-Voltage Programming Enable bit (RB4/PGM pin has PGM function, low-voltage programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 4000000
#include <xc.h>
#include "16f684a.h"
void main(void) {


    OSCCON = 01100111;
    ANSEL = 0x00;
    CMCON  = 0x07;
    TRISA = 0; //RA0 as Output PIN

  while(1)
  {
    RA0 = 1;  // LED ON
    __delay_ms(1000); // 1 Second Delay
    RA0 = 0;  // LED OFF
    __delay_ms(1000); // 1 Second Delay
  }
    return;
}
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
You need to add this header file to set osccon and ANSEL
Code:
#ifndef    _HTC_H_
#warning Header file pic16f684.h included directly. Use #include <htc.h> instead.
#endif


/* header file for the MICROCHIP PIC microcontroller
  * PIC16F684
*/

#ifndef    __PIC16F684_H
#define    __PIC16F684_H

// Special function register definitions


volatile       unsigned char    OSCCON        @ 0x8F;
volatile    unsigned char       ANSEL        @ 0x91;

                 
#define CONFIG_ADDR    0x2007

#endif
Heres a little video of the sim
 
Last edited:
Top