Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC16f1527 configuration bits doubt

Status
Not open for further replies.

ragav4456

Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Activity points
2,568
How to 16f1527 configure bits?

__CONFIG(1, FOSC_HS & PWRTE_ON & BOREN_OFF & WDT_OFF & MCLRE_ON & CP_OFF & CLOCKOUT_ON & IESO_OFF & FCMEN_OFF);
__CONFIG(2, WRT_OFF & VCAPEN_OFF & LVP_OFF & LPBOR_OFF & BORV_OFF & STVR_ON);

Kindly help me

Simple LED On/Off program only? Configuration.png
 

Hi,

You need to say what oscillator your are using, its currently set for a high speed external crystal, is that what you want - more usual to use the internal oscillator.

Also it has Mclre configured as ON, so you must connect that pin to VDD via a 10k resistor or the program will not run.

Thr rest of the parameters should be ok.

To use the internal oscillator change the FOSC_HS to FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
This has a default speed of 500khz but you can change it up to 16mhz in your code by using the OSCCON instruction -see the datasheet page 62
 

Thanks,

Send the sample code for led blinking Hitech c compiler.
 

here is the code for led blinking
 

Attachments

  • LED_BLINK.txt
    914 bytes · Views: 68


Code - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FOSC        INTOSC      0xFFFC
WDTE        OFF     0xFFE7
PWRTE       OFF     0xFFFF
MCLRE       ON      0xFFFF
CP      OFF     0xFFFF
BOREN       OFF     0xF9FF
CLKOUTEN    OFF     0xFFFF
VCAPEN      OFF     0xFFFF
STVREN      OFF     0xFDFF
BORV        LO      0xFFFF
LPBOR       OFF     0xFFFF
LVP     ON      0xFFFF
WRT     OFF     0xFFFF
IESO        OFF     0xFFFF
FCMEN       OFF     0xDFFF

 

How to 16f1527 configure bits?

__CONFIG(1, FOSC_HS & PWRTE_ON & BOREN_OFF & WDT_OFF & MCLRE_ON & CP_OFF & CLOCKOUT_ON & IESO_OFF & FCMEN_OFF);
__CONFIG(2, WRT_OFF & VCAPEN_OFF & LVP_OFF & LPBOR_OFF & BORV_OFF & STVR_ON);

You can typically find the proper Configuration Register Bitmask for a particular device in the device specific header file:

pic16f1527.h
Code:
#ifndef	_HTC_H_
#warning Header file pic16f1527.h included directly. Use #include <htc.h> instead.
#endif

/* header file for the MICROCHIP PIC microcontroller
 *  16F1527
 */


#ifndef __PIC16F1527_H
#define __PIC16F1527_H

//
// Configuration mask definitions
//


// Config Register: CONFIG1
#define CONFIG1              0x8007
// Oscillator Selection
// ECH, External Clock, High Power Mode (4-20 MHz): device clock supplied to CLKIN pin
#define FOSC_ECH             0xFFFF
// ECM, External Clock, Medium Power Mode (0.5-4 MHz): device clock supplied to CLKIN pin
#define FOSC_ECM             0xFFFE
// ECL, External Clock, Low Power Mode (0-0.5 MHz): device clock supplied to CLKIN pin
#define FOSC_ECL             0xFFFD
// INTOSC oscillator: I/O function on CLKIN pin
#define FOSC_INTOSC          0xFFFC
// EXTRC oscillator: External RC circuit connected to CLKIN pin
#define FOSC_EXTRC           0xFFFB
// HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_HS              0xFFFA
// XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_XT              0xFFF9
// LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins
#define FOSC_LP              0xFFF8
// Watchdog Timer Enable
// WDT enabled
#define WDTE_ON              0xFFFF
// WDT enabled while running and disabled in Sleep
#define WDTE_NSLEEP          0xFFF7
// WDT controlled by the SWDTEN bit in the WDTCON register
#define WDTE_SWDTEN          0xFFEF
// WDT disabled
#define WDTE_OFF             0xFFE7
// Power-up Timer Enable
// PWRT disabled
#define PWRTE_OFF            0xFFFF
// PWRT enabled
#define PWRTE_ON             0xFFDF
// MCLR Pin Function Select
// MCLR/VPP pin function is MCLR
#define MCLRE_ON             0xFFFF
// MCLR/VPP pin function is digital input
#define MCLRE_OFF            0xFFBF
// Flash Program Memory Code Protection
// Program memory code protection is disabled
#define CP_OFF               0xFFFF
// Program memory code protection is enabled
#define CP_ON                0xFF7F
// Brown-out Reset Enable
// Brown-out Reset enabled
#define BOREN_ON             0xFFFF
// Brown-out Reset enabled while running and disabled in Sleep
#define BOREN_NSLEEP         0xFDFF
// Brown-out Reset controlled by the SBOREN bit in the BORCON register
#define BOREN_SBODEN         0xFBFF
// Brown-out Reset disabled
#define BOREN_OFF            0xF9FF
// Clock Out Enable
// CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
#define CLKOUTEN_OFF         0xFFFF
// CLKOUT function is enabled on the CLKOUT pin
#define CLKOUTEN_ON          0xF7FF
// Internal/External Switchover
// Internal/External Switchover mode is enabled
#define IESO_ON              0xFFFF
// Internal/External Switchover mode is disabled
#define IESO_OFF             0xEFFF
// Fail-Safe Clock Monitor Enable
// Fail-Safe Clock Monitor is enabled
#define FCMEN_ON             0xFFFF
// Fail-Safe Clock Monitor is disabled
#define FCMEN_OFF            0xDFFF


// Config Register: CONFIG2
#define CONFIG2              0x8008
// Flash Memory Self-Write Protection
// Write protection off
#define WRT_OFF              0xFFFF
// 000h to 1FFh write protected, 200h to 3FFFh may be modified by PMCON control
#define WRT_BOOT             0xFFFE
// 000h to FFFh write protected, 2000h to 3FFFh may be modified by PMCON control
#define WRT_HALF             0xFFFD
// 000h to 3FFFh write protected, no addresses may be modified by PMCON control
#define WRT_ALL              0xFFFC
// Voltage Regulator Capacitor Enable bit
// VCAP pin function disabled
#define VCAPEN_OFF           0xFFFF
// VCAP pin function enabled
#define VCAPEN_ON            0xFFEF
// Stack Overflow/Underflow Reset Enable
// Stack Overflow or Underflow will cause a Reset
#define STVREN_ON            0xFFFF
// Stack Overflow or Underflow will not cause a Reset
#define STVREN_OFF           0xFDFF
// Brown-out Reset Voltage Selection
// Brown-out Reset Voltage (VBOR) set to 2.4V
#define BORV_LO              0xFFFF
// Brown-out Reset Voltage (VBOR) set to 2.7V
#define BORV_HI              0xFBFF
// Low-Power Brown Out Reset
// Low-Power BOR is disabled
#define LPBOR_OFF            0xFFFF
// Low-Power BOR is enabled
#define LPBOR_ON             0xF7FF
// Low-Voltage Programming Enable
// Low-voltage programming enabled
#define LVP_ON               0xFFFF
// High-voltage on MCLR/VPP must be used for programming
#define LVP_OFF              0xDFFF


//
// Special function register definitions
//


// Register: INDF0
volatile unsigned char           INDF0               @ 0x000;
// bit and bitfield definitions

...
...
...


BigDog
 

I joint this header file in my program.
How to edit the header file ?

[example] I am using HS oscillator, how to select the FOSC?

Can i delete FOSC other options?
 

No, you should not edit the device specific header file.

Only use in for reference to select the proper Configuration Bit Masks for the Config() compiler directives:

Code:
__CONFIG(1, FOSC_HS & PWRTE_ON & BOREN_OFF & WDT_OFF & MCLRE_ON & CP_OFF & CLOCKOUT_ON & IESO_OFF & FCMEN_OFF);
__CONFIG(2, WRT_OFF & VCAPEN_OFF & LVP_OFF & LPBOR_OFF & BORV_OFF & STVR_ON);

For example the Oscillator offers eight possible configuration options which can be used in the top Config() directive, FOSC_ECH, FOSC_ECM, FOSC_ECL, FOSC_INTOSC, FOSC_EXTRC, FOSC_HS, FOSC_XT or FOSC_LP.

Only one bitmask of a particular category can be include in the Config() directive at a time.

Code:
// Oscillator Selection
// ECH, External Clock, High Power Mode (4-20 MHz): device clock supplied to CLKIN pin
#define FOSC_ECH             0xFFFF
// ECM, External Clock, Medium Power Mode (0.5-4 MHz): device clock supplied to CLKIN pin
#define FOSC_ECM             0xFFFE
// ECL, External Clock, Low Power Mode (0-0.5 MHz): device clock supplied to CLKIN pin
#define FOSC_ECL             0xFFFD
// INTOSC oscillator: I/O function on CLKIN pin
#define FOSC_INTOSC          0xFFFC
// EXTRC oscillator: External RC circuit connected to CLKIN pin
#define FOSC_EXTRC           0xFFFB
// HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_HS              0xFFFA
// XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_XT              0xFFF9
// LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins
#define FOSC_LP              0xFFF8

BigDog
 

I use this PIC16f1527.h file.

#include <htc.h>
#include "sci.h"
#include "definitions.h"
#include "PIC16F1527.h"

include this PIC16f1527.h file in my program. But i got the following error

Clean: Deleting intermediary and output files.
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\test.p1".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\sci.p1".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.cof".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.hex".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.sym".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.map".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.hxl".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\startup.lst".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\startup.rlf".
Clean Warning: File "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\doprnt.p1" doesn't exist.
Clean Warning: File "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\doprnt.pre" doesn't exist.
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.obj".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.lst".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.rlf".
Clean: Deleted file "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main.sdb".
Clean: Done.
Build D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\main for device 16F1527
Using driver C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe

Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\test.c" -q --chip=16F1527 -P --runtime=default --opt=default -D__DEBUG=1 --rom=default --ram=default -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [100] ; . unterminated #if[n][def] block from line 10
Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\Testing\PWM Light ctrl\PIC16f1527\Testing\MasterBoard\Test 1\sci.c" -q --chip=16F1527 -P --runtime=default --opt=default -D__DEBUG=1 --rom=default --ram=default -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"

********** Build failed! **********
 

__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_ON);
__CONFIG(WRT_OFF & VCAPEN_OFF & LPBOR_OFF & STVREN_OFF & BORV_HI & LVP_OFF);

I got it thanks guys
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top