PDA

View Full Version : Problems using 16f84A code on 16f628



Darrenmac
- 15th May 2004, 10:24
I have started to work on a basic telemetry project to control radio repeaters. I have got it working fine on a 16f84A, and for several reasons have decided to switch to using a 16f628. When the pic sends its initial string it appears to be way to fast. My thoughts were that p16pro would make any changes required when I select the correct micro. If someone has any ideas I would appreciate them. Thanks in advannce.

INCLUDE "modedefs.bas" ' Include serial modes
DEFINE OSC 4
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 3
DEFINE DEBUG_BAUD 1200
DEFINE DEBUG_MODE 0
DEFINE DEBUGIN_REG PORTA
DEFINE DEBUGIN_BIT 2
DEFINE DEBUG_BAUD 1200
DEFINE DEBUG_MODE 0
outstate VAR BYTE

B0 VAR BYTE
b1 VAR BYTE
b2 VAR BYTE
b3 VAR BYTE
id VAR BYTE
id=01

High PORTB.3
Debug "repeater controler v0.1",13
High PORTB.2

loop:




DebugIn [wait("rep"),b0,b1,b2]
IF b2 ="f" Then outstateoff


IF b2 = "n" Then outstateon

Button PORTB.2,0,0,0,b3,1,testout



GoTo loop ' Forever

outstateoff:

Low PORTB.5
High PORTB.4 'Tx on
High PORTB.3 ' ctcss enc on
Pause 1000 'lead in delay or LET

Debug 13," repeater ",b0," is OFF ",13

Pause 300 'lead out delay
Low PORTB.3 'turn off ctcss
Pause 300 ' wait to give quiet dekey
Low PORTB.4 ' turn off TX


GoTo loop


outstateon:

High PORTB.5
High PORTB.4 'Tx on
High PORTB.3 ' ctcss enc on
Pause 1000 'lead in delay or LET

Debug 13," repeater ",b0," is ON ",13

Pause 300 'lead out delay
Low PORTB.3 'turn off ctcss
Pause 300 ' wait to give quiet dekey
Low PORTB.4 ' turn off TX


GoTo loop


testout:
Debug 13,"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ",13

GoTo LOOP

Melanie
- 15th May 2004, 10:48
There's only ONE difference between porting code from a 16F84 to a 16F628, and that's by default the 16F628 assigns pins from PortA to the Analog Comparators.

At the start of your code along where you have your TRIS statements (which I can't find in your code) add...

CMCON=7

(see the 16F628's Datasheet in the Comparators section to find out what that setting does).

It's worth while to have a Pause before your main loop (just after your ID=01) to allow external Hardware to settle. Something like Pause 500 should suffice.

Please also define your I/O's with TRISA and TRISB. It's bad practice to leave them out and assume the rest of your code will automatically set them for you... that omission will bite you one day.

Melanie

Darrenmac
- 16th May 2004, 01:08
Thanks Melanie.

Although I dont fully understand the info on the datasheet, it would appear that the setting that you suggest would efectivly turn off the comparators and allow port a to work as standard I/O, ie RA0- RA3. The data sheet show the CMCON command as having a binary value but the examlpe you have given is in decimal, or am I reading the datasheet wrong.
Also your suggestion on using the TRISA would this be to avoid a case of using a command that does not automaticly set the port to be an input or an output, therefore the port could be in the wrong state for the command?

Darrenmac
- 16th May 2004, 07:00
Hi Melanie,
Have just tried cmcon = 7 near the start of the program an when I try and compile PBP gives the following error
undefined symbol 'cmcon'

any ideas?

Darrenmac
- 16th May 2004, 07:18
Its ok now. I forgot to set the micro to 16f628 in code designer lite. Silly mistake

Melanie
- 16th May 2004, 10:32
You're absolutely correct in both cases...

CMCON=7 is the same as CMCON=%00000111 which is the same as CMCON=$07...

now all you do is compare the setting of each bit against what it does in the CMCON register, which you're already done and discovered it turns the Comparators OFF and sets the relevant pins to Digital.

With regard to TRIS, never assume anything is going to set things for you automatically. It's so easy to go round and just set In or Out usage accordingly.

Well done... looks like you're in business.