[SOLVED] Getting started using PIC16F630 on MPLAB - Page 1
Forum section: electronics / general

author: MrT123
author_rank: Contributor
timestamp: August 20, 2017, 11:10:18 am
content: Hi everyone,I've been trying to just blink an LED using a PIC16F630 and nothing really works.I want to start from scratch again after multiple failed attempts.I'm using an AC162049 development board and MPLAB to code on to it in C.Would someone be ever so kind as to provide a circuit schematic and code of how you'd go about it? Im quite lost at this point.Thanks for any advice you'd have to offer.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: August 20, 2017, 06:49:40 pm
content: Code:#define _XTAL_FREQ 4000000#include <xc.h>// Configuration Bits#pragma config FOSC = INTRCIO // 4MHz internal RC oscillator#pragma config WDTE = OFF // Wathdog timer disabled#pragma config PWRTE = OFF // Power-Up Timer disabled#pragma config MCLRE = OFF // GP3/MCLR is digital I/O#pragma config BOREN = ON // Brown-out Detect enabled#pragma config CP = OFF // Code Protection disabled#pragma config CPD = OFF // Data Code Protection disabled// LED output pin, connected to Vdd via current-limiting resistor#define LED PORTAbits.RA1void main(){CMCON = 7; // disable analog comparator, enable digital inputsTRISA = 0; // set RA0-2, 4-5 to output mode (RA3 is input only)TRISC = 0; // set RC0-5 to output modewhile(1){LED = 0; // LED on__delay_ms(500);LED = 1; // LED off__delay_ms(500);}}

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 08:05:06 am
content: Thanks for your reply, however it comes up with the error that it can't open the include file. No such file or directoryEDIT: Ive changed <xc.h> to a <htc.h> to remove this error.but am now met with countless 'bad pragma' errorsbad 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"

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: August 21, 2017, 08:19:51 am
content: I'm a newcomer to MPLAB, but which compiler are you running? Did you check the project settings that it's the right one?Right click project -> properties. This should show you some helpful information.When an include makes an error like "no such file or directory" it means it cannot find that file where it's told to look. This often means a) it's not told to look anywhere or b) it's told to look at the wrong place.See this:http://www.microchip.com/forums/m802891.aspx

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 08:54:40 am
content: You were correct, 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>but am now met with countless 'bad pragma' errorsbad 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"ps. soz for the repetition, but helps with the flow of the thread i suppose.

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2017, 08:59:30 am
content: It looks like you haven't got the Microchip XC8 C compiler for PIC10/12/16 and PIC18 installed correctly. It is *NOT* bundled with MPLAB X, you have to install it separately. From the errors you are getting its most likely you have some version of the discontinued and obsolete HiTech C compiler for PIC10/12/16 installed. Unless you have a paid licence for it I *STRONGLY* recommend upgrading to XC8Also, are you sure about that development board number?AC162049 is the old version of Microchip's Universal Programming Module.It is only intended for *PROGRAMMING* DIP package PICs that you are then going to move to a different board to run them. Its got no switches or LEDs and no provision for external power.N.B. Please don't abbreviate PIC part numbers as it causes great confusion. Fortunately this time there are no other devices with '630' in their part number to cause confusion so we know you mean the PIC16F630.P.S. you can copy the error messages direct from the MPLAB output window and paste them here inBBcode code tags. Start by clearing the output window, do a build and copy the result. You may wish to first paste it into a text editor so you can replace your user name in file paths with a string of ***** before pasting the result here. If we have the *original* error message(s) we can often provide far more specific help.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: August 21, 2017, 09:00:12 am
content: Are you using a HI TECH compiler?Which compiler are you using?Did you check project properties? Toolchain, and maybe also linker.EDIT: Ian.M beat me to it.

author: Wilksey
author_rank: Super Contributor
timestamp: August 21, 2017, 09:00:37 am
content: Are you using MPLAB or MPLABX?If you have the XC8 compiler you should be able to use "#include <xc.h>".Sounds like you are trying to use the older HiTec C compiler?

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 09:10:56 am
content: I am using MPLAB IDE v8.70 and I am using the HI-TECH Universal Toolsuite. The development board that I am using is the one shown in the picture provided by Ian. For the purposes of this project I am unfortunately stuck with this.EDIT: with regards to the AC162049 development board, I was under the impression that I could supply external power through pins 9 and 10 on the board itself and have Vdd, Vss and GND connected as seen in your picture

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2017, 09:13:44 am
content: You would be better off putting your PIC in a solderless breadboard and wiring the programmer direct to its ICSP pins. What programmer are you using?Also, what HiTech C compiler version are you using?

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 09:16:40 am
content: How would I find out which HiTech C compiler version im using?

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2017, 09:27:31 am
content: When you do a build, it will print the version number in the output window on the line immediately after the one that invokes the compiler (picc.exe).

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 09:30:46 am
content: Right, ok,What I get isHI-TECH Compiler for PIC10/12/16 MCUs (Lite Mode) V9.81Copyright (C) 2010 Microchip Technology Inc.(1273) Omniscient Code Generation not available in Lite mode (warning)followed by the errors

author: Ian.M
author_rank: Super Contributor
timestamp: August 21, 2017, 09:51:51 am
content: Ok, that's post the Microchip buyout of HiTech, and has got *some* of the newer features found in XC8, but it doesn't support #pragma config.Rip out all those lines and to replace them, try:Code:__CONFIG(FOSC_INTRCIO &WDTE_OFF & PWRTE_ON &MCLRE_OFF &BOREN_ON);If you can provide a 10K pullup for /MCLR its better to use:Code:__CONFIG(FOSC_INTRCIO &WDTE_OFF & PWRTE_ON &MCLRE_ON &BOREN_ON);as MCLRE_OFF (+ making RA0 and/or RA1 outputs) can make it very difficult to reprogram your PIC if you are using a programmer that doesn't properly support Vpp First mode.If you've got admin rights on the PC you may wish to upgrade to MPLAB v8.93 and XC8. The install is a little kludged as XC8 dropped toolsuite registration for MPLAB 8 a few versions back so ask if you want to do that.

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 10:22:52 am
content: Ah thanks,it compiles with no warnings and errors now.I will use the circuit suggested by bruce above but with a 10k pullup resistor attached to MCLR (as Im using the MCLRE_ON method as suggested by Ian)

author: MrT123
author_rank: Contributor
timestamp: August 21, 2017, 11:14:42 am
content: Works perfectly, thanks for our time and help folks.