PIC 16F877 assembly code

Discussion in 'Embedded Systems and Microcontrollers' started by chilly, Sep 16, 2008.

  1. chilly

    Thread Starter New Member

    Sep 16, 2008
    7
    0
    I'm working with a PIC 16F877
    My PIC program is reading input from portA then show output in portB
    My problem is when portA is 10001 then it will make RB0=1, when portA is 10011 it will make RB1=1
    but when portA is 10011 is will make both RB0, RB1=1
    How can I solve this problem? I want when portA is 10011 is make RB1=1 only
    Thanks for any suggestion.
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Check for both cases then, truth table will give you clearer idea on how to implement the program.

    Code ( (Unknown Language)):
    1.  
    2. 00 -> 00
    3. 01 -> 01
    4. 10 -> 10
    5. 11 -> 10
     
  3. chilly

    Thread Starter New Member

    Sep 16, 2008
    7
    0
    Could you explain clearer? Note that I'm using assembly language to program the PIC
    Thnaks.
     
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    You need to handle all the cases in the truth table above. In pseudocode, the first entry in truth table will translate to something like:

    if RA0 is 0 and RA1 is 0, set RB0 to 0 and RB1 to 0

    You have to do all entries, and then write the corresponding assembly program.
     
  5. geko

    New Member

    Sep 18, 2008
    9
    4
    Something like this should work

    Code ( (Unknown Language)):
    1.  
    2. RB0 equ 0
    3. RB1 equ 1
    4.  
    5.               clrf          copyPORTB  
    6.               movfw         PORTA
    7.               sublw         b'00010001'
    8.               skpnz
    9.               bsf           copyPORTB,RB0
    10.               sublw         b'11111110'
    11.               skpnz        
    12.               bsf           copyPORTB,RB1
    13.               movfw         copyPORTB
    14.               movwf         PORTB
    15.  
     
  6. chilly

    Thread Starter New Member

    Sep 16, 2008
    7
    0
    Thanks for your supports. I got the solution already.
     
  7. Prasanna K Routray

    New Member

    Sep 17, 2015
    8
    0
    @ Chilly how? will you please let me know?
     
  8. dannyf

    Well-Known Member

    Sep 13, 2015
    1,775
    360
    What exactly do you want to happen when PORTA is 10011?
     
  9. dannyf

    Well-Known Member

    Sep 13, 2015
    1,775
    360
    Couldn't have been simpler:

    Code (Text):
    1.  
    2.   switch (PORTA) {
    3.     case 0b10001: set/clear RB0/1; break;
    4.     case 0b10011: set/clear RB0/1; break;
    5.   }
    6.  
     
  10. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    See the thread here.

    This thread is 7 years old. The mod will be coming to close it.

    Allen
     
Loading...