ptr = 0x0020;will set the pointer to address 0x0020.
The statement
x = *ptr;will read the value from the address and store it in the variable x.
The statement
*ptr = x;will write the value of x to the address of the pointer.
When you refer to a pointer, how does the compiler know whether you want to access an 8-bit signed number or a 16-bit unsigned number? You tell the compiler this when you declare the pointer. For example, if you declare the pointer with this statement:
unsigned int *ptr1;the compiler will know that when you refer to *ptr1 you are refering to an unsigned 16-bit number. If you declare the pointer with:
char *ptr2;the compiler will know that when you refer to *ptr2 you are refering to a signed 8-bit number.
When using the HC11 you often want to refer to one of its registers, which is either an 8-bit number of a 16-bit number at a fixed address. For example, PORTB is an 8-bit unsigned number at address 0x1004 and TCNT is a 16-bit unsigned number at address 0x100E. You can access these ports through the following defines:
#define PORTB (*(unsigned char *) 0x1004) #define TCNT (*(unsigned int *) 0x100E)The *(unsigned char*) and *(unsigned int *) are called type casts in C.
The necessary defines for all of the ports of the HC11 are defined in the header file hc11.h. When you put this statement in your C program:
#include <hc11.h>you can refer to the name PORTB and the compiler will know that you are refering to an unsigned 8-bit number.