Using a P16f630 to try to blink an LED in MPLAB (coding in C)

Thread Starter

JRT97

Joined Aug 17, 2017
4
Question above.
I have tried multiple approaches, but nothing really works.
I'm using an AC162049 development board and MPLAB to code on to the microcontroller in C.
I'd appreciate any help at this point really.
 

AlbertHall

Joined Jun 4, 2014
12,640
You can write the program and and send it to the PIC but the LED doesn't flash?
Show us your simplest coding attempt and then we can see (I hope) what you are doing wrong.
You will learn nothing if we spoon feed you a solution.
 

jayanthd

Joined Jul 4, 2015
945
Hi, thanks for your reply.
This is currently the simple code Ive got going and the circuit schematic essentially.

p.s. sorry for the bad formatting. Hopefully you can make some sense of it.
Are you sure 40 MHz Fosc will work for that device. Try 4 MHz Fosc.

Show the config settings.
 

AlbertHall

Joined Jun 4, 2014
12,640
What is the component you have connected to the oscillator pins?
The maximum clock frequency is 20MHz. I would suggest you start by using the internal 4MHz clock.
 

be80be

Joined Jul 5, 2008
2,395
Try The see what happens. No crystal needed
Code:
/*
* File:   main.c
* Author: burt
*
* Created on August 20, 2017, 4:41 PM
*/
// CONFIG
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/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       // RA3/MCLR pin function select (RA3/MCLR pin function is MCLR)
#pragma config BOREN = ON       // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = OFF         // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)

// #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>

void main(void) {
    OSCCAL= 0b11111100;
    TRISC0 = 0; //RC0 as Output PIN
  while(1)
  {
    RC0 = 1;  // LED ON
    __delay_ms(1000); // 1 Second Delay
    RC0 = 0;  // LED OFF
    __delay_ms(1000); // 1 Second Delay
  }
    return;
}
 
Last edited:

Thread Starter

JRT97

Joined Aug 17, 2017
4
Thanks for your reply, it gave me the error that it couldn't ind the <xc.h> header.
after doing some digging into the directories, and finding 'pic16f630.h', the header file for the microchip I'm using, it said to use #include <htc.h> instead.

So as instructed I've changed <xc.h> to a <htc.h> which removes that error.
However I am now met with countless 'bad pragma' errors..not sure what to do about this error
bad pragma "x"
bad pragma "F"
bad pragma "x"
bad pragma "W"
bad pragma "x"
bad pragma "P"
bad pragma "x"
bad pragma "M"
bad pragma "x"
bad pragma "B"
bad pragma "x"
 

Thread Starter

JRT97

Joined Aug 17, 2017
4
update: as im using an extremely old
HI-TECH C compiler for PIC10/12/16 MCUs (Lite Mode) V9.81
I have changed these settings to

__CONFIG(FOSC_INTRCIO &WDTE_OFF & PWRTE_ON &MCLRE_ON &BOREN_ON);
using a 10k pullup resistor for MCLRE
 

be80be

Joined Jul 5, 2008
2,395
That's code is xc8 1.36 I wouldn't of dream anyone using HI-TECH C compiler for PIC10/12/16 MCUs (Lite Mode) V9.81
I don't have anyways to test in that but xc8 is free you can even use it online for free.
https://mplabxpress.microchip.com/mplabcloud/ide
You can go there and use the code i posted as is
Hit the make and program button and save the hex then load that to your pic chip.
 
Last edited:
Top