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.

how to write configuration bits in MPLAB + HIGH TEC C compiler ....i have written but

Status
Not open for further replies.

haroon_tech

Member level 2
Member level 2
Joined
Apr 28, 2011
Messages
51
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
bangalore
Activity points
1,727
hi,
i am writing a program in C for PIC16F877A ,but i am getting error because of configuration bits , any body know how to define configuration bits..

COMPILER: mplab8.66+HIGH TECH C

MY PROGRAM IS ...
#include<htc.h>
#define _XTAL_FREQ 8000000
__CONFIG(RC & WDTEN );
main()
{
RP0=0;
RP1=0;
PORTB=0x00;
RP0=1;
TRISB=0x00;
RP0=0;
while(1)
{
__delay_us(5);
PORTB=0x55;
__delay_us(5);
PORTB=0xAA;
__delay_us(5);
}
}

i am getting error as follows............
.....

Error [800] led.as; 45. undefined symbol "WDTEN"
Error [800] led.as; 45. undefined symbol "RC"

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

any body help me ...........
 

I guess, the secret is reviewing the documentation or include files for the correct constant names ...
 

For PIC16F877A, use this config
__CONFIG(0x3F32);

Example code you can find here LED.
 

Actually all the #defines for your device are contained in the appropriate header file, in this case "pic16f877a.h" contained in:

C:\Program Files\HI-TECH Software\PICC\9.81\include


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef _HTC_H_
#warning Header file pic16f877a.h included directly. Use #include <htc.h> instead.
#endif
 
/* header file for the MICROCHIP PIC microcontroller
 *  16F877A
 */
 
 
#ifndef __PIC16F877A_H
#define __PIC16F877A_H
 
//
// Configuration mask definitions
//
 
 
// Config Register: CONFIG
#define CONFIG               0x2007
// Oscillator Selection bits
[COLOR="#FF0000"]// RC oscillator
#define FOSC_EXTRC           0xFFFF[/COLOR]
// HS oscillator
#define FOSC_HS              0xFFFE
// XT oscillator
#define FOSC_XT              0xFFFD
// LP oscillator
#define FOSC_LP              0xFFFC
// Watchdog Timer Enable bit
/[COLOR="#FF0000"]/ WDT enabled
#define WDTE_ON              0xFFFF[/COLOR]
// WDT disabled
#define WDTE_OFF             0xFFFB
// Power-up Timer Enable bit
// PWRT disabled
#define PWRTE_OFF            0xFFFF
// PWRT enabled
#define PWRTE_ON             0xFFF7
// Brown-out Reset Enable bit
// BOR enabled
#define BOREN_ON             0xFFFF
// BOR disabled
#define BOREN_OFF            0xFFBF
// Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
// RB3/PGM pin has PGM function; low-voltage programming enabled
#define LVP_ON               0xFFFF
// RB3 is digital I/O, HV on MCLR must be used for programming
#define LVP_OFF              0xFF7F
// Data EEPROM Memory Code Protection bit
// Data EEPROM code protection off
#define CPD_OFF              0xFFFF
// Data EEPROM code-protected
#define CPD_ON               0xFEFF
// Flash Program Memory Write Enable bits
// Write protection off; all program memory may be written to by EECON control
#define WRT_OFF              0xFFFF
// 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
#define WRT_256              0xFDFF
// 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
#define WRT_1FOURTH          0xFBFF
// 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
#define WRT_HALF             0xF9FF
// In-Circuit Debugger Mode bit
// In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
#define DEBUG_OFF            0xFFFF
// In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
#define DEBUG_ON             0xF7FF
// Flash Program Memory Code Protection bit
// Code protection off
#define CP_OFF               0xFFFF
// All program memory code-protected
#define CP_ON                0xDFFF
 
 
//
// Special function register definitions
//
 
 
// Register: INDF
volatile unsigned char           INDF                @ 0x000;
// bit and bitfield definitions
 
// Register: TMR0
volatile unsigned char           TMR0                @ 0x001;
// bit and bitfield definitions
 
// Register: PCL
volatile unsigned char           PCL                 @ 0x002;
// bit and bitfield definitions
 
// Register: STATUS
volatile unsigned char           STATUS              @ 0x003;
// bit and bitfield definitions
volatile bit CARRY               @ ((unsigned)&STATUS*8)+0;
volatile bit DC                  @ ((unsigned)&STATUS*8)+1;
volatile bit ZERO                @ ((unsigned)&STATUS*8)+2;
volatile bit nPD                 @ ((unsigned)&STATUS*8)+3;
volatile bit nTO                 @ ((unsigned)&STATUS*8)+4;
volatile bit IRP                 @ ((unsigned)&STATUS*8)+7;
volatile bit RP0                 @ ((unsigned)&STATUS*8)+5;
volatile bit RP1                 @ ((unsigned)&STATUS*8)+6;
#ifndef _LIB_BUILD
volatile union {
    struct {
        unsigned    C                   : 1;
        unsigned    DC                  : 1;
        unsigned    Z                   : 1;
        unsigned    nPD                 : 1;
        unsigned    nTO                 : 1;
        unsigned    RP                  : 2;
        unsigned    IRP                 : 1;
    };
    struct {
        unsigned                        : 5;
        unsigned    RP0                 : 1;
        unsigned    RP1                 : 1;
    };
} STATUSbits @ 0x003;
#endif
 
...
...
...



It is preferable to use the Configuration Register Bit Mask Definitions rather than a simple Hex number to setup the Configuration Register, their use allows for features to be selected, activated and deactivated without deciphering a Hex number.

Your configuration line:


Code C - [expand]
1
__CONFIG(RC & WDTEN );



Should be:


Code C - [expand]
1
__CONFIG(FOSC_EXTRC & WDTE_ON );



I often add the appropriate device header file to the project window, so that I may refer to it while coding.

Hope the info helps in your endeavors.
 

hi....plz anyone tell me whats tha problem in my code i write in hi tech c compiler.....its build successfully but not work in real hardware... plzzzzz
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(0x3F32); //__CONFIG(RC & WDTEN )
#define LED PORTB
void pic_init();
void T0Delay();
int count=0;
main()
{
pic_init(); //initialize PIC
LED=0x00;
void T0Delay();
LED=0xFF;
}
void T0Delay()
{

T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
PS2 = 0; // bits 2-0 PS2:pS0: Prescaler Rate Select bits
PS1 = 0;
PS0 = 0;

//OPTION=0x6f;
TMR0 = 194; // preset for timer register
while(!T0IF);
T0IF=0;
count++;
if(count==15)
{
count=0;

}

}




void pic_init()
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
ADCON1=0b00000110;
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
}
 

Try
main()
{
pic_init(); //initialize PIC
while(1)
{
LED=0x00;
T0Delay();
LED=0xFF;
T0Delay();
}
}

still not working then i think you need to check the delay function.
 
Last edited:

T0Delay();

---------- Post added at 12:17 ---------- Previous post was at 11:58 ----------

main()
{
pic_init(); //initialize PIC
while(1)
{
LED=0x00;
T0Delay();
LED=0xFF;
T0Delay();
}
}

still not working then i think you need to check the delay function.

i think Problem in configration bit or timer0...plz tell me where is problem.!
this code run in proteus.!
 

actually you can easily confirm the configuration bits are correct or not by just checking it in mplab. There you could see can option to find configuration bits for yous need. Moreover it is there in the datasheet also. Just verify it.

Then which oscillator you are using ?

You can confirm the problem is in the timer0 configuration just by replacing the delay function using some 'for' or 'while' loop delays..
Moreover, you should check how much milli second delay is provide by the delay function. If it is too low then you may not be able to identify the blinking...if so, then try to increase the delay ...
 
Last edited:

it looks like a osc problem

on the config choose XT or HS and see wich one works on you ;)

(XT for me always ^^)
 

thanx vinodstanur, Zwilorg..
my code run.
with these configrantion....
#include<pic.h>
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);

so can you explain me.. who we can create interrupt..
 

thanx vinodstanur, Zwilorg..
my code run.
with these configrantion....
#include<pic.h>
#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);

so can you explain me.. who we can create interrupt..

Hi Fawadbutt,

Only the,

Code:
#include<htc.h>

is require, this header will also include the pic.h and appropriate pic specific header during compilation

What model PIC are you using in your design?

All the #defines and Configuration Register Bit Mask Definitions for your device are contained in the appropriate header file and explained in my previous post #4 above.

I could step you through setting up an Interrupt Service Routine (ISR), however there are excellent tutorials which cover this topic in a much better fashion than I could in the limited space of this posting:

**broken link removed**

Checkout lesson #3, Introduction to Interrupts the accompanying source code is also available for free download.

Let me know if you have any further problems implementing an interrupt routine.

BigDog
 
Last edited:

no problem m8, always good to be able to help someone.

For the interrupts you better read the datasheets (and see the register settings) or as bigdogguru said (and well) check out some already made codes.

It is pretty simple once you understand the basics of it ;)


have fun coding
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top