Skip to main content

4 posts tagged with "arduino"

View All Tags

· One min read

To read a memory address on an ARM controller using C language, you can use a pointer variable to access the address and read its contents. Here's an example code snippet:

// declare a pointer variable of the appropriate data type
volatile uint32_t* memory_address;

// set the pointer to the desired memory address
memory_address = (uint32_t*) 0x1FFFF7B0;

// read the contents of the memory address
uint32_t data = *memory_address;

In this example, we're declaring a volatile pointer variable memory_address of type uint32_t*, which is a pointer to a 32-bit unsigned integer. We then set the pointer to the desired memory address 0x1FFF F7B0. Finally, we read the contents of the memory address by dereferencing the pointer using the * operator and storing the data in a variable data.

Note that it's important to use the volatile keyword in the pointer declaration when accessing memory-mapped registers or other memory locations that can change unexpectedly, as it informs the compiler that the value can change at any time and should not be optimized away. Also, the exact syntax may vary depending on the specific ARM controller and the C compiler being used.

· One min read
// Read the datasheet https://www.youtube.com/watch?v=cXpeTxC3_A4

#define DELEAY 2
#define EN 1
#define DATAMODE 0b0010 // 4 bit data mode
#define CLEAR_1 0b0000
#define CLEAR_2 0b0001
#define RET_1 0b0000
#define RET_2 0b0010
#define ON_1 0b0000
#define ON_2 0b1100

#define H_1 0b0100
#define H_2 0b1000

#define I_1 0b0100
#define I_2 0b1001


void setup()
{
DDRD = B11111111; // set PORTD (digital 7~0) to outputs
DDRB = B11111111; // set PORTD (digital 7~0) to outputs
DDRC = B11111111; // set PORTD (digital 7~0) to outputs
}

void loop()
{
command(DATAMODE);

command(ON_1);
command(ON_2);
while(1)
{
command(CLEAR_1);
command(CLEAR_2);

ch(H_1);
ch(H_2);

ch(I_1);
ch(I_2);
}

}

void command(int command)
{
PORTC = B0;
PORTD = command;
PORTB = B1;
delay(DELEAY);
PORTB = B0;
}

void ch(int ch)
{
PORTD = ch;
PORTC = B1;
PORTB = B1;
delay(DELEAY);
PORTB = B0;
}