subroutine for picbasic


Closed Thread
Results 1 to 5 of 5
  1. #1
    jojokatada's Avatar
    jojokatada Guest

    Default subroutine for picbasic

    hi i want to make a subroutine for checking the status of each bit of portb and set a high on corresponding to porta.

    here is the assembly code

    checking portb

    btfsc portb, 0
    bsf porta, 0
    btfsc portb, 1
    bsf porta, 1
    btfsc portb, 2
    bsf porta, 2
    btfsc portb, 3
    bsf porta, 3

    return


    please help me to translate this code into picbasic pro
    appreciate for any help

  2. #2
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, let me get this straight. You want your program to do the following:

    check if portb.0 is high, if so set porta.0 high and so on?

    If that's the case, then it's pretty easy,

    IF PORTB.0 = 1
    THEN PORTA.0 = 1
    ELSE PORTA.0 = 0
    IF PORTB.1 = 1
    THEN PORTA.1 = 1
    ELSE PORTA.1 = 0
    IF PORTB.2 = 1
    THEN PORTA.2 = 1
    ELSE PORTA.2 = 0
    IF PORTB.3 = 1
    THEN PORTA.3 = 1
    ELSE PORTA.3 = 0

    That is the bulk of what I think you are trying to do. You will have to set the TRISB registers to outputs. In addition, I don't know how fast you would want these changes to occur, so I would see if you could get something like this up and running and check to see if the speed meets your requirements.

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


    Did you find this post helpful? Yes | No

    Default

    more easy than if then stuff...
    Code:
    TRISA=0    'output on all PORTA pin
    TRISB=255 'Input on all PORTB pin
    '
    '
    
    '
    '
    
    '
    '
    '
    CheckingPORTA:
         PORTA=PORTB
         Return
    1 line do everything
    Steve

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

  4. #4
    jojokatada's Avatar
    jojokatada Guest


    Did you find this post helpful? Yes | No

    Default

    hi Turbols

    appreciate your help i am trying to use in pic16f877a by checking each bit and send a high to porta to activate a relay.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    MyInput  var Byte   
    TestLoop var byte
    
    Start:
        MyInput = PORTA
        For testloop = 0 to 7
            PORTB.0[testloop]=Myinput.0[TestLoop] ' send the state of the bit to
                                                  ' the according PORTB bit
        next
        goto start
    Steve

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

Similar Threads

  1. Using "END" in a subroutine?
    By Byte_Butcher in forum General
    Replies: 6
    Last Post: - 13th February 2010, 16:32
  2. Multiple RETURNS within a single subroutine
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st June 2009, 16:43
  3. Pulsin within subroutine
    By Wesley in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th January 2009, 23:05
  4. subroutine with hserin
    By volcane in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 19th December 2007, 02:56
  5. Replies: 0
    Last Post: - 28th May 2004, 17:25

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