PIC 16F877 assembly code

Thread Starter

chilly

Joined Sep 16, 2008
7
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.
 

n9352527

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

Rich (BB code):
00 -> 00
01 -> 01
10 -> 10
11 -> 10
 

n9352527

Joined Oct 14, 2005
1,198
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.
 

geko

Joined Sep 18, 2008
9
Something like this should work

Rich (BB code):
RB0 equ 0
RB1 equ 1
 
              clrf          copyPORTB   
              movfw         PORTA
              sublw         b'00010001'
              skpnz
              bsf           copyPORTB,RB0
              sublw         b'11111110'
              skpnz         
              bsf           copyPORTB,RB1
              movfw         copyPORTB
              movwf         PORTB
 

dannyf

Joined Sep 13, 2015
2,197
when portA is 10011 it will make RB1=1
but when portA is 10011 is will make both RB0, RB1=1
I want when portA is 10011 is make RB1=1 only
What exactly do you want to happen when PORTA is 10011?
 
Top