Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F876A led problem

Status
Not open for further replies.

santhosh

New Member
Hi all,
I am very new to microcontroller. I try to write my first program using PIC16F876A to trigger led 3 second interval. Code is
#include <pic.h>
#include "delay.h"
#include "delay.c"
main()
{
TRISB = 0x00;
PORTB = 0x00;
while (1)
{
PORTB=0x80;
DelayS(3);
PORTB=0x00;
DelayS(3);
}
}
And i compiled the code using Hi-TECH lite version
picc --chip=16F876A port.c

I programmed PIC16F876A using icprog(using JMD programmer option). Finally i connected power supply and LED(see the attached file), but nothing happen. Please help me.

Regards,
santhosh
 

Attachments

  • led.png
    led.png
    4.4 KB · Views: 781
Assuming you have the crystal caps and power correct.

You have the LED on RB7 which is used by the ICD interface. To make like easy move the LED and resistor to RB0 and alternate RB0 between 0x00 and 0xFF.

If it blinks on RB0 check the other 7 pins. If it works on all by RB6 and RB7 you have compiled the code in debug mode which does not allow the use of RB6 and RB7 as IO.

HTH
 
Hi santhosh :)

is the header file (delay.h) is the one that come with hi tech pic c
if so there is no such a term called dealyS() (unless u modify)

if your use that header file

DelayUs(x) Delay specified number of microseconds
DelayMs(x) Delay specified number of milliseconds
are only available functions with that header

and where is your configuration word ?:rolleyes:

__CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT);

and there is no need to add "#delay.c " directive


and u have to copy delay.h to the working folder

the pre-processor directive and config word should like this

# include<pic.h>
# include"delay.h"
#define XTAL FREQ 4MHZ
__CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT);

and one thing u have to specify your crystal frequency
above it is 4MHz

read the header file carefully you may find the solution
 
Last edited:
I been reading for months and no where have i read that thanks thats good to no
you have compiled the code in debug mode which does not allow the use of RB6 and RB7 as IO
now I no. I have readed where it not a good ideal to use RB6 and RB7 I'm putting that in my book of tricks
 
Last edited:
Don't forget to connected MCLR [pin1] to +VDD

You mean to connect MCLR (pin1) to +5V right...
I could`t get 12pF capacitors and 20MHz crystal here. I got 10pF capacitors and 6MHz crystal only :(. I successfully connected all components as mentioned page, and changed the code to assign PORTB=0xFF (thanks 3v0). But still microcontroller not running what i expected, RB0 to RB7 was always ON(I was thinking crystal looks like old, the shop person cheated me:(). I will try to get 12pF capacitors and 20MHz crystal and update status to here. Thanks to all...
 
You no I have made most all of Nigels boards The board 2 I put a jumper on mclr to vdd
because I use a pickit2 with that board and if I use the pickit2 to power it with the jumper set it will not come on. I added the isp header to the board . You can find a good 20 mhz
crystal in a lot of old sound cards if you have a old 1 laying around.
 
You no I have made most all of Nigels boards The board 2 I put a jumper on mclr to vdd
because I use a pickit2 with that board and if I use the pickit2 to power it with the jumper set it will not come on. I added the isp header to the board . You can find a good 20 mhz
crystal in a lot of old sound cards if you have a old 1 laying around.

I've also modified my Board 2 to add an ICSP socket, I posted the layout here somewhere a while back. I added a diode and resistor to MCLR, no jumpers needed.
 
I've also modified my Board 2 to add an ICSP socket, I posted the layout here somewhere a while back. I added a diode and resistor to MCLR, no jumpers needed.
__________________
PIC programmer software, and PIC Tutorials at:
WinPicProg Page

Like this would work
 

Attachments

  • mclr.PNG
    mclr.PNG
    4.6 KB · Views: 346
Last edited:
Hi santhosh :)

is the header file (delay.h) is the one that come with hi tech pic c
if so there is no such a term called dealyS() (unless u modify)

if your use that header file

DelayUs(x) Delay specified number of microseconds
DelayMs(x) Delay specified number of milliseconds
are only available functions with that header

and where is your configuration word ?:rolleyes:

__CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT);

and there is no need to add "#delay.c " directive


and u have to copy delay.h to the working folder

the pre-processor directive and config word should like this

# include<pic.h>
# include"delay.h"
#define XTAL FREQ 4MHZ
__CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT);

and one thing u have to specify your crystal frequency
above it is 4MHz

read the header file carefully you may find the solution

hi there, not sure if someone could help, does "__CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT)" applies even if i'm compiling my code in assembly? i did not include the configuration word in my code. and i'm using a 4MHz crystal. is __CONFIG( PWRTDIS & LVPDIS & WDTDIS &XT & UNPROTECT); sufficient?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top