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.

Port Confussion

Status
Not open for further replies.

striker2509

New Member
If i configure 4 pins as an output and 4 pins as an input. and i need to use the 4 input pins. how can i read the 4 less significant bits in order to do something else?

Hope u help me.....thanks
 
striker2509 said:
If i configure 4 pins as an output and 4 pins as an input. and i need to use the 4 input pins. how can i read the 4 less significant bits in order to do something else?

Hope u help me.....thanks
Easy, just use MOVF PORTB,w instruction and then ANDLW b'00001111' to filter out the result...
 
Jay.slovak said:
striker2509 said:
If i configure 4 pins as an output and 4 pins as an input. and i need to use the 4 input pins. how can i read the 4 less significant bits in order to do something else?

Hope u help me.....thanks
Easy, just use MOVF PORTB,w instruction and then ANDLW b'00001111' to filter out the result...


ok, got it, and if i want to put it on port B, in the less significant bits, non-affecting the most significant bits, could i do the same???
 
striker2509 said:
Jay.slovak said:
striker2509 said:
If i configure 4 pins as an output and 4 pins as an input. and i need to use the 4 input pins. how can i read the 4 less significant bits in order to do something else?

Hope u help me.....thanks
Easy, just use MOVF PORTB,w instruction and then ANDLW b'00001111' to filter out the result...


ok, got it, and if i want to put it on port B, in the less significant bits, non-affecting the most significant bits, could i do the same???
Yes, but because other pins are inputs, it is not necessary. :D
 
striker2509 said:
Jay.slovak said:
striker2509 said:
If i configure 4 pins as an output and 4 pins as an input. and i need to use the 4 input pins. how can i read the 4 less significant bits in order to do something else?

Hope u help me.....thanks
Easy, just use MOVF PORTB,w instruction and then ANDLW b'00001111' to filter out the result...


ok, got it, and if i want to put it on port B, in the less significant bits, non-affecting the most significant bits, could i do the same???

If you want to write to a port you just do that, write to the entire port - any pins set as inputs aren't affected - they aren't write enabled. If you want to only write to some pins, and not others (which are also outputs), the easiest way is probably to use the bitwise commands BSF and BCF, and write to each individual pin. A LOT depends on exactly what you are doing, and why?.

If you want to fully write to just some pins on a port, with some others set as outputs which must not be affected, you can read the port, modify the contents (using AND, OR, or a combination of both) and write the contents back to the port. This is the only way to do it on many processors, and is a VERY!, VERY! standard programming technique - in fact I use it in WinPicProg to write to the ports, Intel processors don't have handy bitwise operators like the PIC does!.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top