Problems using 16f84A code on 16f628


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    74

    Default Problems using 16f84A code on 16f628

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    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?

  5. #5
    Join Date
    Mar 2004
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Its ok now. I forgot to set the micro to 16f628 in code designer lite. Silly mistake

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Problems with HSERIN HSEROUT
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2005, 17:24
  4. Writing code for battery operated projects
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th June 2005, 03:39
  5. Problems with 16F877A code
    By NightHawk2 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th August 2003, 01:36

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts