GPIO WDT BKL Programming
Abstract
Abstract
In this document, code examples based on C programming language are provided for
customer interest. Inportb, Outportb, Inportl and Outportl are basic functions used for
access IO ports and defined as following.
Inportb: Read a single 8‐bit I/O port.
Outportb: Write a single byte to an 8‐bit port.
Inportl: Reads a single 32‐bit I/O port.
Outportl: Write a single long to a 32‐bit port.
General Purposed IO - GPIO/DIO
1. General Purposed IO – GPIO/DIO
The GPIO port configuration addresses are listed in the following table:
Name
N_GPI0
N_GPI1
N_GPI2
N_GPI3
1.1
Set output value of GPO
1. Read the value from GPO port.
2. Set the value of GPO address.
3. Write the value back to GPO port.
Example: Set N_GPO0 output "high"
val = Inportb (0xA02);
val = val | (1<<4);
Outportb (0xA02, val);
Example: Set N_GPO1 output "low"
val = Inportb (0xA02);
val = val & (~(1<<5));
Outportb (0xA02, val);
1.2
Read input value from GPI
1.
Read the value from GPI port.
2.
Get the value of GPI address.
Example: Get N_GPI2 input value.
val = Inportb (0xA02);
val = val & (1<<2);
if (val)
else
A-2
IO Port
IO address
0xA02
Bit 0
0xA02
Bit 1
0xA02
Bit 2
0xA02
Bit 3
// Read value from N_GPO0 port.
// Set N_GPO0 address (bit 4) to 1 (output "high").
// Write back to N_GPO0 port.
// Read value from N_GPO1 port.
// Set N_GPO1 address (bit 5) to 0 (output "low").
// Write back to N_GPO1 port.
// Read value from N_GPI2 port.
// Read N_GPI2 address (bit 2).
printf ("Input of N_GPI2 is High");
printf ("Input of N_GPI2 is Low");
Name
IO Port
IO address
N_GPO0
0xA02
N_GPO1
0xA02
N_GPO2
0xA02
N_GPO3
0xA02
Bit 4
Bit 5
Bit 6
Bit 7