Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] congratulations

2005-01-15 by microbit

Hi Thomas,

Welcome !

> Assuming that pins P0.8 to P0.15 are configured as output, write to IO0PIN:
> IO0PIN = 0x0000 C700
> will produce the same output as following sequence of writes:

> IO0SET = 0x0000 C700
> IO0CLR = 0x0000 3800

No, IOSET and IOCLR avoid a so called "Read-Modify-Write" instruction. (RMW)
Normally on most MCUs, you will eg. do this :

Port |=    0x10;        /* Set Bit 4 on <Port>

This Reads the output latches (or actual outputs) on <Port>, ORs it with 0x10 and then
writes it back, resulting in Bit 4 being SET.

This operation can be done with JUST writing to IOSET :

IOSET = 0x10;        /* Set Bit 4 */

Same goes for Clearing bits.

Now, direct writes to IOPIN _effectively_ write the whole Port , thus :

> IO0PIN = 0x0000 C700

Will write "0x0000 C700" to the WHOLE Port 0.
This means that will produce the same output as following sequence of writes:

IO0SET = 0x0000 C700;        /* Bits 8 & 15 are set to "1"  */
IO0CLR = 0xFFFF 38FF;        /* All other bits are cleared */

Your sequence of writes :

> IO0SET = 0x0000 C700
> IO0CLR = 0x0000 3800

doesn't achieve anything : First Bits 8 & 15 are SET, then on next line they are CleaRed !!!

Some MCUs are "true" RMW, some not.

This used to be a huge problem on eg. PIC.
The early PIC16C71 had a TRISA (direction PortA) and PORTA (I/O Port A).
Now, when you used BSET and BCLR instruction, things would go haywire on Port A...
(TrisA wasn't disabling the PA3)

PA3, bit 3 (IIRC) was an open collector output, and when you eg. did this :

SETB    PortA , 0x01        /* Set Bit 1 on Port A */

AND PA3 was an input (there was no "direction" for PortA), the following would happen :

Port A is read, OR with 0x01, write back.
So, if you were using PA3 as an INPUT, and it happened to have a LOW level on that pin,
The SETB instruction would pull down the PA3 pin, disbling its ability to read the actual input... !!!

Hope that clears it all up..

B rgds
Kris



[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.