PIC16F62X outputs


Closed Thread
Results 1 to 7 of 7
  1. #1
    Deadeye's Avatar
    Deadeye Guest

    Question PIC16F62X outputs

    All,

    Im programming a PIC16F628 pic.
    I have a problem where I need a lot of outputs and I don’t know how to stop some ports from performing there alternate function.

    Ports in question are
    RA4
    RB6
    RB7

    Although I am specifying

    CMCON = 7 ' PortA = digital I/O
    VRCON = 0 ' A/D Voltage reference disabled
    TRISA=%00000000 ' Or TRISA = 0 sets all the PORTA pins to outputs
    TRISB=%01000000

    They are still randomly setting the pins to be there other function.

    Anyone know the command or how I can just make them OUTPUT pins.

    Thanks

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    What about the whole code?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Deadeye's Avatar
    Deadeye Guest


    Did you find this post helpful? Yes | No

    Default

    this is very roufe. Im still debugging and playing.


    '
    ' PIC Defines
    ' -----------
    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' System Clock Options Saves A6, A7
    @ DEVICE pic16F628, WDT_ON ' Watchdog Timer
    @ DEVICE pic16F628, PWRT_ON ' Power-On Timer
    @ DEVICE pic16F628, MCLR_OFF ' Master Clear Options (Internal) Saves A5
    @ DEVICE pic16F628, BOD_ON ' Brown-Out Detect
    @ DEVICE pic16F628, LVP_OFF ' Low-Voltage Programming
    @ DEVICE pic16F628, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F628, PROTECT_OFF ' Program Code Protection

    VRCON = 0 ' A/D Voltage reference disabled
    CMCON = 7 ' disable analog comparators on almost any PIC so equipped


    TRISA=%00000000 ' Or TRISA = 0 sets all the PORTA pins to outputs
    TRISB=%01000000

    Include "modedefs.bas" ' Include serial modes

    ' Ports
    pLcd_dat var PORTA ' LCD 8 bit data bus
    pRS Var PORTB.0 ' RS
    pE VAR PORTB.4 ' E
    pCs1 VAR PORTB.7 ' Cable Select 1
    pLed Var PORTB.3 ' Status LED

    GoTo init '****** jump past the routines below ******



    send:

    pCs1 = 0 ' TODO Change
    'pause 1
    pRS = gRS
    pause 2
    'pause 42
    pLcd_dat = glcd_dat
    PORTB.6 = glcd_dat.4
    PORTB.5 = glcd_dat.5

    'pause 1
    pE = 1
    'pauseUS 10
    'pause 100

    pause 2
    'pause 60

    pE = 0
    'pause 1
    pRS = 0
    pCs1 = 1
    'pCs2 = 1
    'pCs3 = 1
    pause 7
    'pause 140
    Return




    init: 'Initialization


    ' H
    for i=0 to 4
    LOOKUP2 i,[$7F,$08,$08,$08,$7F],glcd_dat
    GoSub send
    Next

    goto init

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm what about if you use HIGH/LOW instead of Myvar=0, Myvar=1???
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Don't forget port A.5 is always an input port. It is not possible to get it as an output port even if you say trisa = %00000000

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >> Ports in question are
    >> RA4
    >> RB6
    >> RB7

    ---
    RA4 is multiplexed with T0CKI and CMP2. You've already taken care of CMP2 with the CMCON = 7. The T0CKI input is controlled by the T0CS bit in the OPTION_REG which defaults to 1 (Timer0 input is T0CKI). You can turn this off by setting OPTION_REG.5 = 0. However This will not affect the operation of RA4 as an output, which appears to be the problem.

    RA4 is an open collector type output. It requires a Pull-Up resistor on the output to be used as a normal digital output.

    ---
    RB6 is multiplexed with T1OSO, T1CKI and PGC. T1OSO and T1CKI are controlled by T1CON bits 1 (TMR1CS) and 3 (T1OSCEN). Both of these bits default to 0, which means that the multiplexed functions are disabled. PGC is only used during programming, but if you leave a programmer connected during operation, you may have problems.

    However, in your program you have ...

    TRISB=%01000000

    With a 1 in the bit 6 position, RB6 is set to INPUT. As we found out in your other thread, you want RB6 to be an output.

    ---
    RB7 is multiplexed with T1OSO and PGD. Again, T1OSO is disabled by default (T1OSCEN). and the previous mention of the programmer applies here too.

    It may be that you grabbed an old file for this post. But the correction from the "other" thread is incorrect in this listing.

    pLcd_dat = glcd_dat
    PORTB.6 = glcd_dat.4
    PORTB.5 = glcd_dat.5

    change to

    pLcd_dat = glcd_dat
    PORTB.6 = glcd_dat.6
    PORTB.5 = glcd_dat.7

    ---
    Also, like mat says, RA5 is input only, so it will have to be moved to a different pin.

    HTH,
       Darrel

  7. #7
    Deadeye's Avatar
    Deadeye Guest


    Did you find this post helpful? Yes | No

    Default

    thanks so much for your help.

    I found a sample that had a pull up on A5. This i tested and it fixed the problem.

    The TRISB=%01000000 was a mistake on my part. I thought it was %01234567 and i your saying that it should be 76543210
    I need B1 as a input so i chnaged to TRISB=%00000010

    Oviously i have much to learn.

Similar Threads

  1. DMX512 Reception + 3 * 8-Bit PWM Outputs
    By JEC in forum Code Examples
    Replies: 5
    Last Post: - 16th February 2015, 16:21
  2. 30 PWM outputs on one chip?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th September 2009, 17:32
  3. help with multiple outputs...
    By rickvan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th November 2007, 18:34
  4. Setting up analogue outputs with picbasic pro
    By Jhdgkss in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 30th September 2005, 00:36
  5. making ports outputs on a 12F629
    By bartman in forum mel PIC BASIC
    Replies: 2
    Last Post: - 14th November 2004, 18:47

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