managing the I/O ports of the 16F84A


Closed Thread
Results 1 to 8 of 8
  1. #1
    skyler_91600's Avatar
    skyler_91600 Guest

    Default managing the I/O ports of the 16F84A

    I'm trying to write a program to have port A and Port B light up seven segment displays at the same time. The question I had was how does the compiler distinguish between a port A I/O or a port B I/O? I'm including some of my code to demonstrate what I'm talking about.

    loop1: if bit0 = 1 then loopx 'if true program ends
    if 7 = 1 then loop1 'if beam isn't broken endless loop

    what's happening here is I have a seperate counter set-up and when the counter equals 0, it will send out a logic 1 to PortA bit 0 in the shown code. this in turn will end this program. then the second line is if bit 7 of portB is a logic 1 then this will create an endless loop until the pin turns low. At the of a low state the program will continue execution.

    Now onto the question: How does the compiler distinguish between a portA command (line 1) and a portB command (line2)? when compiling I receive a "variable expected (token '7') error. and this is probably due to my lack in knowledge in managing the I/O ports of the 16F84A. Any help would be greatly appreciated.

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


    Did you find this post helpful? Yes | No

    Default

    PIC16F84A.. great PIC choice

    if you want to acces to a specific PORT pin you must use the according PIC PIN name.

    something like

    read a pin
    IF PORTA.0=1 then DoSomething

    write to a pin
    HIGH PORTA.0

    or

    PORTA.0=1


    Write to a whole PORT

    PORTB=%11100110


    don't forget to set the according TRIS register.
    Steve

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

  3. #3
    skyler_91600's Avatar
    skyler_91600 Guest


    Did you find this post helpful? Yes | No

    Default

    thanks for the reply. I tried doing what you said but I get an illegal character error. It doesn't like the period in between the A and the 0 (PortA.0).

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


    Did you find this post helpful? Yes | No

    Default

    DOH, just notice we are in the PBC section. You have to use POKE and PEEK with the according RAM address.

    something like

    POKE $86,0 ' set PORTB as output
    POKE $06,255 ' set all PORTB pins to 1

    try this and post your results...
    Steve

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

  5. #5
    skyler_91600's Avatar
    skyler_91600 Guest


    Did you find this post helpful? Yes | No

    Default

    Here's what I'm trying to accomplish: I have a loop set-up where the only time the program can come out of the loop is when Port A bit 0 OR RA0 goes low. It then makes other pins go high and/or low to make a certain number out of a seven segment dieplay. What I thought is that I could just make the PIC do this on the fly where when RA0 goes low the program will instantly come out of the loop and continue on with the code. What you're describing is that when the pin goes low you would have to store that informaiton into ram and then retrive the data so that the PIC can compare the two results, as in the IF...Than statement. I"m assuming that you're correct since you're all over this forum! I'm just trying to learn how to do certain things rather than being told how to do it, and not learning anything! I really appreicate you helping me out.

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


    Did you find this post helpful? Yes | No

    Default

    IN PBP we will write something like this...
    Code:
    TRISB=0 ' set PORTB as output 
    TRISA=%11111101 ' set PORTA as input except PORTA.1
    
    a VAR BYTE
    a=1
    
    
    Loop:
         Toggle PORTA.1
         IF PORTA.0=0 then Gosub DoSomething ' testing PORTA.0 status
         goto Loop
    
    DoSomething:
         PORTB=a       ' send to PORTB
         if a<255 then
              a=a+1
         else
              a=1
         endif
         return
    IN PBC, IMO it will look something like.. please correct me someone if i'm wrong

    Code:
    POKE $86,0 ' set PORTB as output
    POKE $85,253 ' set PORTA.1 as output other as input
    b0=0
    
    loop:
         toggle 0
         PEEK $05,b1 ' read PORTA status
         b1=b1 & 1 ' keep only bit 0 of PORTA
                   ' well i don't know if you can use something like
                   ' if b1.0=0 then gosub DoSomething... worth to give a try
         if b1=0 then gosub DoSomething
         goto loop
    
    DoSomething:
         POKE $06,b0       ' send to PORTB
         if b0<255 then
              b0=b0+1
         else
              b0=1
         endif
         return
    this will toggle the PORTA.1 pin untill PORTA.0 go low, once it go to low, it will send the value of b0 var to PORTB.... well it's suppose to
    Steve

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

  7. #7
    skyler_91600's Avatar
    skyler_91600 Guest


    Did you find this post helpful? Yes | No

    Default

    I guess I just don't understand the principals of the IF..Then statement. IN the manual there are some examples for the statement, but when I tried to mimic the example it didn't work.

    The example is:

    If Pin0 = 0 Then pushd

    now does Pin0 need to be equated to something? IN the beginning of the code do I need something like this?

    Pin0 VAR PortA.0?
    or
    Pin0 = PortA.0?

    when I type in PortA.0, the compiler gives me an illegal character error because of the period but I do not know how to otherwise specify any pin of either portA or PortB (RA0,RA1.....RB0, RB1.....)

    I really appreciate all your help, the problem is that I don't have much programming knowledge, and when I try to understand your replies it goes over my head.

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


    Did you find this post helpful? Yes | No

    Default

    well unfortunately you don't have PicBasic PRO where everything is so much simple.

    your example IF PORTA.0= will work in PBP.

    Can you try this and post your results

    Code:
         ' alias definition
         ' ================
         '
         Symbol  PORTA = 5
         Symbol  TRISA = $85                     
         Symbol  PORTB = 6
         Symbol  TRISB = $86
    
         ' I/O setting
         ' ==========
         '
         POKE TRISA=255 ' set input to all PORTA pins
         POKE TRISB=0   ' set output to all PORTB pins
    
         ' Main Loop
         ' =========
         '
    START:
         PEEK PORTA,B0  ' read the whole PORTA and place result into B0
         IF B0.0=1 THEN ' read bit 0 of B0 wich is the PORTA status 
              '
              ' If PORTA.0 is 1 then place all PORTB pins to 1
              '
              POKE PORTB,255
              '
         ELSE
              '
              ' If PORTA.0 is 0 then place all PORTB pins to 0
              '
              POKE PORTB,0
              '
         ENDIF
         GOTO START
    Steve

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

Similar Threads

  1. Replies: 4
    Last Post: - 17th April 2009, 08:56
  2. Question on IO ports
    By studysession in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th February 2009, 18:10
  3. Setting I/O ports on 16f629
    By Optech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2008, 21:51
  4. Replies: 1
    Last Post: - 29th September 2007, 18:05
  5. making ports outputs on a 12F629
    By bartman in forum mel PIC BASIC
    Replies: 2
    Last Post: - 14th November 2004, 17: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