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] PIC 16f876a circuit diagram and 1st program not working

Status
Not open for further replies.

embpic

Advanced Member level 3
Advanced Member level 3
Joined
May 29, 2013
Messages
742
Helped
80
Reputation
160
Reaction score
77
Trophy points
1,308
Location
india
Visit site
Activity points
5,213
Hello master's
i had used till now 8051 family but from few days ago i started to work on PIC family and controller is 16f876a and compiler is xc. i am using jdm programmer and PICpgm software to load hex file.
so my problems are as
1. when i start PICpgm software to load program 1st warming encountered as
Capture.PNG
2. after writing 1st program as
Code:
#include<htc.h>
#include<xc.h>
#include <stdio.h>
#include <stdlib.h>

void delay(unsigned char del);

int main(void)
{
    TRISB = 0x00;
    while(1)
    {
        PORTB = 0x55;
//        delay(100);
 //         PORTB = 0;
   //     delay(100);
    }
    return 0;
}

void delay(unsigned char del)
{
    unsigned char i;
    for(;del>0;del--)
        for(i=0;i<120;i++);
}

it create hex file but on controller as checked port pins voltage it says something different as 2.11 volts on each pin instead of 0x55.

3. How to set config in XC conpiler.

4. My circuit diagram is as follows very simple
Capturde.PNG
 

your code look ok but i don't use JDM programer i used pickit2 try pickit programers if you have access to it and see
 

i just used jdm programmer to burn program i think it not meant any role in program execution.
 

You need to investigate getting the config bits into the file with the JDM setup.

There are two "configuration" steps, the first which is programmed into the chip at the program step (by your JDM) which sets the oscillator configuration, watch dog timer etc., and this is different for each chip (in general).

Your software includes "configuration" info on what the compiler needs to know such as the clock frequency, but this does not affect the chip which will be configured at the program step.

So I haven't used the JDM but have got confused in the past with MPLAB etc., as to what is setting what!
 

i have not set any configuration bits any where. and what should i set.
 

ok sir and for device is there any file which needs to be include?
and how to set __CONFIG bits.
 

CONFIG bits can be set in IDE or Code. If in code see device document file in docs sub folder of compiler folder. delay(100) is too less for led blinking. See how much delay your delay() function gives if 1 is passed as parameter.
 

sir i have commented this part because i have assign 0x55 to portb then also it is not working as per assignment.
 

first of all u simulate your code step by step putting breakpoint on PORTB = 0x55 line and also try with high delay .
 

yes in simulation it shows at portb = 0x55;
and i have posted circuit diagram and same i have implemented so if fault in circuit diagram plz check.
 

in your circuit diagram there is ok and put led on port b and give me a result. what happening .
 

but sir voltage at all pins are same then what should be result.
and i have updated some correction as given as
Code:
#include<xc.h>
#include <stdio.h>
#include <stdlib.h>

__CONFIG(WDTEN & XT & DPROT);
void delay(unsigned char del);

int main(void)
{
    TRISB = 0x00;
    while(1)
    {
        PORTB = 0x55;
        delay(100);
          PORTB = 0;
       delay(100);
    }
    return 0;
}

void delay(unsigned char del)
{
unsigned char i;
    for(;del>0;del--)
        for(i=0;i<120;i++);
}
 

now try this
Code:
#include <xc.h>
// CONFIG1
#pragma config WDTEN = OFF
#pragma config STVREN = ON
#pragma config XINST = OFF
#pragma config CP0 = OFF
// CONFIG2
#pragma config FOSC = HSPLL
#pragma config FCMEN = ON
#pragma config IESO = ON
#pragma config WDTPS = 32768
// CONFIG3
#pragma config EASHFT = ON
#pragma config MODE = XM16
#pragma config BW = 16
#pragma config WAIT = OFF
#pragma config CCP2MX = DEFAULT
#pragma config ECCPMX = DEFAULT
#pragma config PMPMX = DEFAULT
#pragma config MSSPMSK = MSK7
int main(void)
{
TRISB = 0x00;
    while(1)
    {
        PORTB = 0x55;
        delay(1000);
          PORTB = 0;
       delay(1000);
    }
return 0;
}
void delay(unsigned char del)
{
unsigned char i;
    for(;del>0;del--)
        for(i=0;i<120;i++);
}
 

it gives errors as

Code:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `E:/etc/TASKK/PICCCC/T1/Test.X'
make  -f nbproject/Makefile-default.mk dist/default/production/Test.X.production.hex
make[2]: Entering directory `E:/etc/TASKK/PICCCC/T1/Test.X'
"C:\Program Files (x86)\Microchip\xc8\v1.21\bin\xc8.exe" --pass1  --chip=16F876A -Q -G  --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"    -obuild/default/production/newfile.p1  newfile.c 
newfile.c:3: error: unknown configuration setting/register (WDTEN = OFF) used
newfile.c:4: error: unknown configuration setting/register (STVREN = ON) used
newfile.c:5: error: unknown configuration setting/register (XINST = OFF) used
newfile.c:6: error: unknown configuration setting/register (CP0 = OFF) used
newfile.c:8: error: unknown configuration setting/register (FOSC = HSPLL) used
newfile.c:9: error: unknown configuration setting/register (FCMEN = ON) used
newfile.c:10: error: unknown configuration setting/register (IESO = ON) used
newfile.c:11: error: unknown configuration setting/register (WDTPS = 32768) used
newfile.c:13: error: unknown configuration setting/register (EASHFT = ON) used
newfile.c:14: error: unknown configuration setting/register (MODE = XM16) used
newfile.c:15: error: unknown configuration setting/register (BW = 16) used
newfile.c:16: error: unknown configuration setting/register (WAIT = OFF) used
newfile.c:17: error: unknown configuration setting/register (CCP2MX = DEFAULT) used
newfile.c:18: error: unknown configuration setting/register (ECCPMX = DEFAULT) used
newfile.c:19: error: unknown configuration setting/register (PMPMX = DEFAULT) used
newfile.c:20: error: unknown configuration setting/register (MSSPMSK = MSK7) used
newfile.c:27: warning: function declared implicit int
newfile.c:34: error: type redeclared
newfile.c:34: error: conflicting declarations for variable "delay" (newfile.c:27)
make[2]: Leaving directory `E:/etc/TASKK/PICCCC/T1/Test.X'
make[1]: Leaving directory `E:/etc/TASKK/PICCCC/T1/Test.X'
(908) exit status = 1
make[2]: *** [build/default/production/newfile.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)
 

Hi-Tech C Code


Code C - [expand]
1
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & BOREN_ON & LVP_ON & CPD_OFF & WRT_OFF & DEBUG_OFF & CP_OFF)




XC8


Code C - [expand]
1
2
3
4
5
6
7
8
9
#pragma config BOREN = ON
#pragma config CPD = OFF
#pragma config DEBUG = OFF
#pragma config WRT = OFF
#pragma config FOSC = XT
#pragma config WDTE = OFF
#pragma config CP = OFF
#pragma config LVP = ON
#pragma config PWRTE = OFF

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top