PDA

View Full Version : PIC16F877A not working



The Master
- 15th November 2007, 11:31
Hi. ive just connected a PIC16F877A up and programmed it with some test code but its not working properly. I have set picbasic and my programmer to the correct chip this time :P

Heres the test code



trisa=%00000000
trisb=%00000000
trisc=%00000000
trisd=%00000000

high portb.0
loop:
high porta.0
pause 500
low porta.0
pause 500
goto loop


This should see 1 LED on constantly and one flashing. Both LEDs come on but thats it. They just stay on. What could cause this to happen? Im doing everything in the same way i would with any other chip

Melanie
- 15th November 2007, 12:12
> "That which seems simple is often overlooked" (Usually by me)

You've overlooked the DATASHEET...

Change PortA to one of the other pins on PortB and you're in business...

Then... when you're ready to play with BIG features instead of just the noddy ones...

1. Grab a Beer (Gingerbeer/Rootbeer if you're a weenie)...
2. Look in the Datasheet and discover how to DISABLE the Comparators on PortA
3. Look in the Datasheet and discover how to DISABLE the A/D Convertors on PortA
4. Look in the Datasheet and discover how to set PortA in DIGITAL mode
5. Reporgram back to PortA and watch LED's blink
6. Sit back and feel good at how useful the Adobe pdf reader is...

The Master
- 15th November 2007, 12:25
Oh, I did look at the datasheet so i knew which pins were on which port but ive used these chips before and only ever had a problem with 1 pin. I only need 1 pin eventually for a serial connection but this is the biggest chip i have laying around and i need a lot of space on the chip.

I changed porta.0 to portb.1 but its still doing the same thing. I have a feeling its still something simple but i dont know what. Im gonna go get that beer ;)

mister_e
- 15th November 2007, 15:41
Lucky guy, i feel generous today ;)


asm
ifdef PM_USED
device pic16F877A, xt_osc, wdt_on, lvp_off, protect_off
else
__config _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
endif
endasm

PORTA = 0
PORTB = 0
TRISA = 0
TRISB = 0
ADCON1 = 7
CMCON = 7

CounterA VAR BYTE

Start:
for CounterA = 0 to 5
PORTA = DCD CounterA
PAUSE 250
NEXT
PORTA = 0

FOR CounterA = 0 TO 7
PORTB = DCD CounterA
PAUSE 250
NEXT
PORTB = 0

GOTO Start


make sure you properly filter the PSU line and the PIC is powered ;), make sure MCLR line is tied to Vdd, make sure PGM pin is loaded to GND while programming, and also make sure you have a crystal + caps attached to the PIC. The above assume a 4MHz crystal/resonator.

The Master
- 15th November 2007, 16:16
I have the circuit setup in the normal way. 10K resistor between VDD and MCLR. 4MHz resonator. 100uf capacitor plus 3 smaller ones. I dont know what PGM is. My programmer supports this type of chip so i would assume it sets that for me. I have never had trouble with these kind of chips before. I have tested 2 chips to be sure.

I dont quite understand all of your code but i will try it anyway. How come you only set ports A and B? If im not using the others then dont i need to put anything in about them? Not even trisc/trisd?

mister_e
- 16th November 2007, 07:36
Well yes and no. Here it's an example, and i don't use the other PORTs, they're just tied to GND with some pull-down resistors... if not defined, TRISC, TRISD should have their own POR value. Usually set to $FF, have a look at the datasheet, you should find a section about the Power-On Reset values (POR)

don't worry, it works.

Make sure you have connected ALL Vss and ALL Vdd, unless it may not work as expected.

If it's still don't work, program your PIC with the code above, then read it back, save the .HEX file to another FileName and post it here.. maybe there's a strange issue somewhere. Who knows.

The Master
- 16th November 2007, 11:32
I have connected all 4 power pins but ive not grounded the outputs. I know your supposed to but ive never had a problem with it before. Ill give it a test maby tomoz, got a bit of a party goin off today