Suppose that IO-part is memory mapped to address 0x32 and the directive defines
#define portx 0x32
How to construct C language macro which writes the port by storing a value to corresponding register?
Suppose that IO-part is memory mapped to address 0x32 and the directive defines
#define portx 0x32
How to construct C language macro which writes the port by storing a value to corresponding register?
If you must use a macro then typically it would be something like this:
#define WRITE_PORT(port, val) *((volatile uint8_t *)(port)) = (val)
and you might then invoke this as, e.g.
WRITE_PORT(portx, 0xff); // write 0xff to portx
Note that this assumes an 8 bit port.
Note also the use of volatile
, to prevent I/O reads/writes from being optimised away by the compiler.