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.

parallel port

Status
Not open for further replies.

aibelectronics

New Member
here's a little question on parallel port. Many programmers when they want to make bit 2 of control '1' i.e pin 16 write:

outporb(CONTROL, 0X04^0X0b); for example. Why don't they simply write: outportb(CONTROL, 0X0f)? aren't they the same thing?

Let me just explain: 0X04 ^(EXOR) 0x0b is the same thing as (0100 EXOR 1011) which would give us 1111. Now the hardware inverts this to 0100.

If we simply put outportb(CONTROL, 0X0f) it'll mean we're inputting 1111 to CONTROL port and by hardware inversion we have: 0100. Why the obsession with making life difficult? :?
 
It's just for clarity purposes, but may not be recommended simply because an extra step of computation is required.
Asserting the zeroth bit is simply
0x01 ^ 0x0b
Asserting the first bit is simply
0x02 ^ 0x0b
Asserting the second bit is simply
0x04 ^ 0x0b
Asserting the third bit is simply
0x08 ^ 0x0b
 
Probably so the programmer can see at a glance wich bit gets modified?

with the 0x04 in the code you can tell bit2 is beeing modified immediately...
 
checkmate said:
It's just for clarity purposes, but may not be recommended simply because an extra step of computation is required.

Any decent compiler will optimize it out anyway...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top