PDA

View Full Version : How toggle pins on and off


kwabena
02-19-08, 08:08 AM
Please

how do toggle port five pin 2 on and off,
leaving the state of the other pins unchanged.

RMDumse
02-19-08, 10:04 AM
Generally, changing one pin in a group of pins requires an operation called read-modify-write.

Done by hand, or in a high level language, you read the whole port, or perhaps even a register of what was written into the port last, in case some bits written are too loaded down to be read back in the same state. Then you use booleans to OR in a bit or AND out a bit, then store the result back into the output port.

Trying to look at previous posts, I think you are using an 8051, but am not sure. I have no idea what language you are using. The 8051 has bit-manipulation instructions built in, in assembly. These do the read-modify-write in a single instruction. Look up information on the processor instruction set if you want to use these.

nmitech
02-19-08, 10:33 AM
#include clib\common51.c
#include clib\syslib51.c
#include clib\IOSFR.c

#define P5 0xF8

unsigned int d;

main()
{
while(1)
{
OUTSFR(P5, INSFR(P5) | 0x04); /* Toggle bit 2 on, other bits unchanged */
delay();
OUTSFR(P5, INSFR(P5) & 0xFB); /* Toggle bit 2 off, other bits unchanged */
delay();
}
}

delay()
{
for(d=0; d < 0x8000; d++);
}

Davechika
08-29-09, 08:34 AM
pls,can someone help me with how to toggle a pin on 89s52 on each press on a push button.

RMDumse
08-31-09, 02:23 PM
You should look in the data sheet for the part:
http://www.atmel.com/dyn/resources/prod_documents/doc1919.pdf
and look at the register set for the address of that port.

Since we don't sell products with 89C52's on them, that'a about the best we can say for you,