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.

Quick stupid question (PORTB)

Status
Not open for further replies.

pingouin

New Member
If I create a variable foo such that

foo VAR PORTB.6

what is the range of values it can possible read off PORTB.6? I could swear it was something like [0,255] but I am not sure anymore (would it be only binary?).
 

pingouin

New Member
Could you clear something up for me then? I thought before that if you picked up, say, PORTB in the chip, you would have some 8 pins associated with it. I thought before that each pin would be able to read 8bit values. From what you are saying, each pin is a bit and all together makes up the 8bit resolution provided by portB. Am I correct?[/quote]
 

Nigel Goodwin

Super Moderator
Most Helpful Member
pingouin said:
Could you clear something up for me then? I thought before that if you picked up, say, PORTB in the chip, you would have some 8 pins associated with it. I thought before that each pin would be able to read 8bit values. From what you are saying, each pin is a bit and all together makes up the 8bit resolution provided by portB. Am I correct?
[/quote]

Yes you are.

If you treat the port as a byte, reading it with 'movf PORTB, w' that transfers the individual 8 bits as a single byte into the w register. Likewise, 'movwf PORTB' transfers the 8 bit value in the w register to PORTB. These both obviously depend on how the port is configured, you can't output to a pin configured as an input, nor can you read a pin configured as an output (at least not to get a sensible reading!).

You can also access individual pins using 'bitwise operators', using 'bsf PORTB, 1' to set bit 1 of PORTB, or 'bcf' to clear it. To test individual bits you use 'btfsc PORTB, 1' or 'btfss PORTB, 1'.
 
Status
Not open for further replies.

Latest threads

Top