managing the I/O ports of the 16F84A


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    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.

  2. #2
    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.

  3. #3
    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 : 0

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