Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Combining Input from 2 PORTs

Status
Not open for further replies.

ssnickson

New Member
Hi All,
I m using PIC16F676 .I have 6 Pins From port A and 2 Pins from PortC as my input. I want to know how to combine input from these 2 port as 1 8-bit binary input so that i can use the whole data as 1 8 bit data
 
A simple way to do it is to clear the value in memory and then do btfsc PORTA,x then bsf Variable,n and repeat for other 7 bits. The other way is to shift left/right then AND with a mask and finally OR them together.

Mike.
 
A simple way to do it is to clear the value in memory and then do btfsc PORTA,x then bsf Variable,n and repeat for other 7 bits. The other way is to shift left/right then AND with a mask and finally OR them together.

Mike.

I got your 1st point
Can u elaborate ur 2nd way. I m just a begineer sry for the troublee
 
Well, if you are using porta bits 0-5 and portb bits 0-1 then you would read porta and AND it with 0x3f to keep the bottom 6 bits. You would store that in the memory location. Then take portb and shift it left 6 times (rlf) so the bits are in position 6 & 7. Then AND that value with 0xc0 and OR with the memory value.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top