Low Cost PCB's Low Cost Components

Author Topic: [SOLVED] Getting started using PIC16F630 on MPLAB  (Read 1036 times)

0 Members and 1 Guest are viewing this topic.

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
[SOLVED] Getting started using PIC16F630 on MPLAB
« on: August 20, 2017, 09:10:18 PM »
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.
« Last Edit: August 22, 2017, 10:08:01 PM by MrT123 »
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: Getting started using PICF630 on MPLAB
« Reply #1 on: August 21, 2017, 04:49:40 AM »
Code: [Select]
#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.RA1

void main(){
   CMCON = 7;          // disable analog comparator, enable digital inputs
   TRISA = 0;         // set RA0-2, 4-5 to output mode (RA3 is input only)
   TRISC = 0;        // set RC0-5 to output mode
   while(1){
      LED = 0;         // LED on   
      __delay_ms(500);
      LED = 1;         // LED off         
      __delay_ms(500);
   }
}
« Last Edit: August 21, 2017, 05:24:46 AM by Bruce Abbott »
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PICF630 on MPLAB
« Reply #2 on: August 21, 2017, 06:05:06 PM »
Thanks for your reply, however it comes up with the error that it can't open the include file. No such file or directory
EDIT: Ive changed <xc.h> to a <htc.h> to remove this error.
but am now met with countless 'bad pragma' errors
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"
« Last Edit: August 21, 2017, 06:51:27 PM by MrT123 »
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 535
  • Country: no
  • Musician, programmer and EE hobbyist
    • alexanderbrevig.com
Re: Getting started using PICF630 on MPLAB
« Reply #3 on: August 21, 2017, 06:19:51 PM »
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
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PICF630 on MPLAB
« Reply #4 on: August 21, 2017, 06:54:40 PM »
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' errors
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"

ps. soz for the repetition, but helps with the flow of the thread i suppose.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 5545
Re: Getting started using PICF630 on MPLAB
« Reply #5 on: August 21, 2017, 06:59:30 PM »
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 XC8

Also, 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 in BBcode 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.
« Last Edit: August 21, 2017, 07:05:25 PM by Ian.M »
 
The following users thanked this post: MrT123

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 535
  • Country: no
  • Musician, programmer and EE hobbyist
    • alexanderbrevig.com
Re: Getting started using PICF630 on MPLAB
« Reply #6 on: August 21, 2017, 07:00:12 PM »
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.
« Last Edit: August 21, 2017, 07:02:09 PM by alexanderbrevig »
 
The following users thanked this post: MrT123

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1003
Re: Getting started using PICF630 on MPLAB
« Reply #7 on: August 21, 2017, 07:00:37 PM »
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?
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PIC16F630 on MPLAB
« Reply #8 on: August 21, 2017, 07:10:56 PM »
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
« Last Edit: August 21, 2017, 07:13:46 PM by MrT123 »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 5545
Re: Getting started using PIC16F630 on MPLAB
« Reply #9 on: August 21, 2017, 07:13:44 PM »
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?
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PIC16F630 on MPLAB
« Reply #10 on: August 21, 2017, 07:16:40 PM »
How would I find out which HiTech C compiler version im using?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 5545
Re: Getting started using PIC16F630 on MPLAB
« Reply #11 on: August 21, 2017, 07:27:31 PM »
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).
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PIC16F630 on MPLAB
« Reply #12 on: August 21, 2017, 07:30:46 PM »
Right, ok,
What I get is
HI-TECH Compiler for PIC10/12/16 MCUs (Lite Mode) V9.81
Copyright (C) 2010 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)

followed by the errors
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 5545
Re: Getting started using PIC16F630 on MPLAB
« Reply #13 on: August 21, 2017, 07:51:51 PM »
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: [Select]
__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: [Select]
__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.
« Last Edit: August 21, 2017, 07:54:38 PM by Ian.M »
 
The following users thanked this post: MrT123

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PIC16F630 on MPLAB
« Reply #14 on: August 21, 2017, 08:22:52 PM »
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)
 

Offline MrT123

  • Contributor
  • Posts: 12
  • Country: gb
Re: Getting started using PIC16F630 on MPLAB
« Reply #15 on: August 21, 2017, 09:14:42 PM »
Works perfectly, thanks for our time and help folks.  :phew: :clap: :clap:
 
The following users thanked this post: Ian.M


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf