top of page

Accessing A Memory location using Pointers in Embedded C

In microcontroller programming we have to write or read certain registers. The questions is how to access these registers ?.

The register or a memory location can easily be accessed using pointers if we know the required address. But, From where we can get theses addresses ?

The reference manual of the microcontroller contains all the details regarding address of different register or required memory locations. Let's consider we have a 32 bit microcontroller and the objective is to write data to a register having address : 0x00040002 (32 bit address)


# define addr 0x0004002



unsigned long *p; /* As the pointer needs to store 32 bit address */

p = (unsigned long *) addr; /* Assigning Address to the pointer*/

*p = data; /* Writing data to the memory location specified by the pointer*/

return 0;


13 views0 comments

Recent Posts

See All

In this blog I will explain use of bitwise operators for performing some operations which are often required for microcontrollers programming. Bitwise operators: & (AND), | (OR) , ~ (NOT) , ^ (XOR)

Post: Blog2_Post
bottom of page