PDA

View Full Version : 16f876a



DanS.
- 14th October 2006, 03:19
Hi,
New to the forum in terms of posting, but I find many of you good folks very helpful in your ideas. Thanks!
I am having problems with the 16f876a. Stripped my code to simply read a pin and drive another pin based on state.

Seems like my boot LED does it's count OK and then the processor just runs out into the weeds! Is there anything outstanding about the 876A?

BobK
- 14th October 2006, 04:27
Hi Dan,

If you've read this forum enough you should see that guessing at how a program works or doesn't work doesn't do you or us any good and you are just wasting time. How about giving us something to work with like a listing of the code you are trying to run for starters. Also perhaps a schematic of how you have hooked up your test circuits to the PIC. Maybe then we can help you.

BobK

DanS.
- 14th October 2006, 04:42
Bob,
Thanks for the responce. I was starting out with a curiosity about possible known issues with the 876A and PBP / U2 programmer? Sorry for the vague question.

The source shown here is a stripped out version to test basic function of the circuit and compiler.

10meg osc is doing it's job. Power is clean @ 5V. Been over the hardware and PCB layout and is error free.

I can flash the LED if I remove the if tpin test. With the IF Then, the thing seems dead!

'''''''''''''hardware setup''''''''''''''''''''''
@ device pic16f876a, debug_off, hs_osc, wdt_off, pwrt_on, bod_off, protect_off
CMCON = 7 'disable adcs, porta = digital
define osc 10 'external clock 20 mhz '''

'''''''''''''''''''''''port setup''''''''''''''''''''''
TRISA.0 = 1
TRISA.1 = 1
TRISA.2 = 1
TRISB.0 = 0
TRISB.1 = 0
TRISB.2 = 0
TRISB.3 = 0
TRISB.4 = 0
TRISB.5 = 0
TRISB.6 = 1
TRISB.7 = 1
TRISC.0 = 1
TRISC.1 = 1
TRISC.2 = 1
TRISC.3 = 1
TRISC.4 = 1

'''''''''''''''''define''''''''''''''''''''''''
z1_relay VAR PORTB.0
z2_relay VAR PORTB.1
z3_relay VAR PORTB.2
z4_relay VAR PORTB.3
z5_relay VAR PORTB.4
z6_relay VAR PORTB.5
z1_read VAR PORTB.6
z2_read VAR PORTB.7
z3_read VAR PORTC.3
z4_read VAR PORTC.2
z5_read VAR PORTC.1
z6_read VAR PORTC.0
stat_led VAR PORTC.4
'conn40 var PORTA.0
conn41 var PORTA.1
conn42 var PORTA.2
lcd_tx var PORTC.6
serial_rx var PORTC.7
tpin var PORTA.0
'''''''''''''''reg defines''''''''''''''''''''''''
i var byte
therm_status var byte
'therm_calc1 var byte
'therm_calc2 var byte
'water_temp var byte
'cyc_count var word
'ondelay_1 var BYTE
'ondelay_2 var word
'therm_result var byte
'suspend var Byte
'''''''''''''''''''''''''''''''''''''''''''''''''' '

main:
if tpin = 0 then main
low stat_led
pause 500
high stat_led
pause 500
goto main
end

paul borgmeier
- 14th October 2006, 05:12
... then the processor just runs out into the weeds! ...
1) What is connected to pin 1?

2) consider adding ADCON1 = 7

BobK
- 14th October 2006, 13:47
Hi,

Paul's reply is very important. Also do you have pull up or pull down resistors on your inputs?

You can save some typing by setting up your ports like this:
TRISA = %00000111 '1 = input 0 = output
TRISB = %11000000
TRISC = %00000000

Just looking at your Main program, "If tpin = 0 then main" says if the input pin is grounded or low just loop here until it's high. If it's high then pulse the LED on and off until the tpin is low again. Without plugging this program into a board here it should seem it would work BUT as Paul said what have you done with pin 1 and did you set ADCON1 to 7.

In your "hardware setup" you have CMCON = 7 'disable adcs, porta = digital.

All "CMCON = 7" does is disable the comparators.

"ADCON1 = 7" disables the analog ports making them digital.

Pin 1 is the MCLR input and needs to be made high through at least a 1K resistor. You should also have .01uF capacitors across the + and - power pins as close as possible and also one between the MCLR pin and ground.

I'm going to work now so try these things out and see if your PIC doesn't work better.

You're only learning now!

Have a nice day!

BobK