16f84A with hi-tech C compilier help

Thread Starter

derajali

Joined Mar 16, 2009
3
Hey could someone please tell what I am doing wrong in this code

#include <pic.h>
#include <htc.h>
__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT);
void main(void)
{
TRISA=0b00000000;
TRISB=0b00000000;

while(1){
PORTA = 0b11111111;
PORTB = 0b11111111;
}

}


I have tried many variations of this such as TRISA=0 a "for" loop instead of a while loop. I cant see 5 volts on any of the ports. I am pretty sure I have the crystal and caps connect properly.

I have googled for a while now and can't seem to find anything to solve my problem
 

AlexR

Joined Jan 16, 2008
732
The code looks OK to me.

Do you have have:
The MCLR pin pulled high?
Voltage and earth on the supply pins?
Crystal going to the correct pins with the correct capacitors?
Bypass capacitor across the supply pins?
Dead PIC?
 

Thread Starter

derajali

Joined Mar 16, 2009
3
I dont think the PIC is dead......Programmer can read and write to it.

I dont have anything connected to the MCLR pin.

Voltage and ground are connected to the correct pins according to the data sheet.

I am using a 20 Mhz crystal with the correct caps as far as i know (16pF). and I hooked it up using the configuration shown in the data sheet for a HS oscillator.

Today i used an oscilloscope and hooked up a lead to the oscillator pin and saw a sine wave. Isn't it suppose to be square wave? could this mean my caps are bad?
 

AlexR

Joined Jan 16, 2008
732
The MCLR pin must be pulled high (to Vdd) via a pull-up resistor (10K) for the chip to work.
Its difficult to know what goes on with the oscillator since the scope probe tends to load it down. You could try increasing the capacitors to 22pF to give the crystal more drive but the first thing to do is the pull-up on MCLR. Without that the chip will not work.
 

Thread Starter

derajali

Joined Mar 16, 2009
3
Had no idea what a pull-up resistor is... anyway i connected Vdd to a 10k then to the MCLR PIN........and the pic worked!!!.........thanks a lot.
 
Top