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.

PIC headache

Status
Not open for further replies.

lusk

New Member
Hi, ive been trying to run a very simple routine on a PIC 16f877A together with a PICDEM 2 plus demoboard. the program is a simple blinking LED type routine. the program compiles fine and i can debug it using the sim in MPLAB, however when i run it on the demo board nothing happens at all. thinking that this could relate to the oscillator ive tryed using the different oscillators on the board (RC and canned oscillator, remembering to change the config word accordingly). no luck though. ive tryed replacing the device to check if it was a bad chip. still no luck. ive never used external oscillators before and ive been unable to find a thread that deals with this particular setup. IM using MPLAB PICC (hi-tech lite) with an ICD 3 programmer. I havent got a scope so im unable to check the oscillators but since ive tryed them both oscillator sources on the board it seem unlikely to be the issue.


i hope somone can give me an idea to fix this as im slowly loosing my mind over this :)


Code:
#include <HTC.h>
/*
#########################
# Program to blink LEDs #
#########################
*/
__CONFIG(FOSC_XT & WDTE_OFF & LVP_OFF & CPD_OFF & CP_OFF);

/*We need to include the header file “pic.h” which contains all the device related information*/

#include <pic.h> 

/*_XTAL_FREQ is used in delay functions, im using a 4 MHZ canned oscillator*/
#define _XTAL_FREQ 4000000

void main(void)
{
/*PORT B is given an initial value of all high, i.e. now all the LEDs will glow*/

PORTB = 0b00001111;

   /*TRISB is used to set the direction of PORT B, 0 means PORT B will function as Output Port and 1 means Input Port*/

   TRISB = 0b00000000;

   /*Infinite loop is used to keep the LEDs blinking*/

   while(1)
      {
      /*The __delay_ms(1000) is used to create a delay of 1000ms. This is a special function defined in “pic.h”. Alternatively one could write a empty loop to create a delay.*/

      __delay_ms(1000);
      PORTB = 0b00000000; //All LEDs Off
      __delay_ms(1000);
      PORTB = 0b00001111; //All LEDs On

      }
   }
/*---END---*/
 
Last edited by a moderator:
#include <p16f877A.h> would this work any better then #include <pic.h>?
I also clr the TRIS before I set the PORTS, They may be all inputs at startup???
 
Last edited:
Hi,

Have you got Jumper J6 closed to enable the leds ?

Are you using J7 correctly when switching between the crystal and RC

Have you tried running any of the ready made .hex files from the PD2 software examples ?
 
#include <p16f877A.h> would this work any better then #include <pic.h>?

The "p16f877a.h" is called from "pic.h",which in turn is called from the "htc.h"... So it matters not which one is used...

Some times the __delay_ms() routine throws a wobbler with constants higher than 180...

try
Code:
void delay1s()
   {
   int x = 10;
   while(x--)
     __delay_ms(100);
   }

to see if it works...
 
Last edited:
Hi everybody thanks for the replies

well i checked the jumpes again.. J7 on when using RC and off when using the crystal but still no luck. also tried the alternative delay code but sadly not the problem either. .

Is the config word im using adequate when using external oscillators or am i missing something perhaps??
 
Not sure if it's the problem, but I've had an issue that was resolved in the past with this same PIC from other modules turned on upon power-up that needed to be initially shut off/disabled to utilize a port. (PORTA/ ADconverter)

Also, and I know it sounds simple, but do you have a multimeter? Perhaps check the board to see if you've got power/gnd on the device. At the very least I thought I'd throw it out there. Based upon given info I'm not really sure what else it could be.
 
[MODNOTE]Sorry burt.... Spam we missed...[/MODNOTE]

What that have to do with this
 
Last edited by a moderator:
Yep what a waste of time 3v0 LOl I was thinking he didn't no google

Well maybe the op got this OSC working.
 
Status
Not open for further replies.

Latest threads

Back
Top