System Installation
WADE-8016 User’s Manual
3-9
3.6 GPIO
#define EFER 0x2e //Address for Extended Function Enable Register
#define DEVICE_NUM_REG 0x07 //Address for Logic Device Number Register
#define GPIO_LOGIC_NUM 0x08 //Logic device number for GPIO
#define GPIO_BASE_REG 0x30 //Set GPIO
#define GPIO_IO_REG 0xe0 //Address for GPIO I/O Register
#define GPIO_MODE_OUT 0
#define GPIO_DATA_REG 0xe1 //Address for GPIO Data Register
#define MAX_GPIO_NUM 8
int main(){
int pin_num = 5; //select pin number
(pin 5)
int mode = 0;
//select I/O mode
(output)
int value = 1;
//set GPO value
(high)
int tmp = 1 << pin_num;
if(pin_num < 0 || pin_num > MAX_GPIO_NUM || mode < 0 || mode > 1 ||
value < 0 || value > 1){
printf("GPIO_Pin_Set:Invalid
parameter\n");
return
-1;
}
//Enter the Extended Function Mode
outp(EFER,
0x87);
outp(EFER,
0x87);
//Now set the configuration register
outp(EFER, DEVICE_NUM_REG); //Select Logic Device Number
Register
outp(EFER + 1, GPIO_LOGIC_NUM); //device number for GPIO2,3,4,5
is 9
outp(EFER,
GPIO_BASE_REG);
outp(EFER + 1, 0x07);
outp(EFER, GPIO_IO_REG); //Select GPIO3 I/O Register
outp(EFER + 1,(inp(EFER + 1) & ~tmp) | (tmp * mode));//Set I/O
mode, 0:output 1:input
//If mode is GPO, set value
if(mode == GPIO_MODE_OUT){
outp(EFER, GPIO_DATA_REG); //Select GPIO3 Data Register
outp(EFER + 1,(inp(EFER + 1) & ~tmp) | (tmp * value));//Set GPO
value, 0:low 1:high
printf("GPIO_Pin_Set: Set GPIO(%d) to GPO, Value = %d\n", pin_num,
value);
}