AduC7000 GPIO

There are five 8-pin GPIO blocks on microcontrollers ADuC7019/AduC7020/AduC7021/
AduC7022/AduC7024/AduC7025/AduC7026/AduC7027/AduC7028. This gives a total of
40 GPIO pins (depending on an IC package - some of pins may not be available).
Pins are 5V tolerant (in GPIO mode). Functions are ilustrated in following table.
Note: some of GPIO lines have no external connection to pin.

Pin Function Availability on ADuC
Func.. 00 Func.. 01 Func.. 10 Func.. 11 7019/20 7021 7022 7024/25 7026/27
P0.0 GPIO CMP MS0 PLAI[7] Y Y Y Y Y
P0.1 GPIO PWM2H BLE(NEG)   - - - - Y
P0.2 GPIO PWM2L BHE(NEG)   - - - - Y
P0.3 GPIO TRST A16 ADCBUSY Y Y Y Y Y
P0.4 GPIO/IRQ0 PWMTRIP MS1 PLAO[1] Y Y Y Y Y
P0.5 GPIO/IRQ1 ADCBUSY MS2 PLAO[2] Y Y Y Y Y
P0.6 GPIO/T1 MRST   PLAO[3] Y Y Y Y Y
P0.7 GPIO ECLK/XCLK SIN PLAO[4] Y Y Y Y Y
P1.0 GPIO/T1 SIN SCL0 PLAI[0] Y Y Y Y Y
P1.1 GPIO SOUT SDA0 PLAI[1] Y Y Y Y Y
P1.2 GPIO RTS SCL1 PLAI[2] Y Y Y Y Y
P1.3 GPIO CTS SDA1 PLAI[3] Y Y Y Y Y
P1.4 GPIO/IRQ2 RI CLK PLAI[4] Y Y Y Y Y
P1.5 GPIO/IRQ3 DCD MISO PLAI[5] Y Y Y Y Y
P1.6 GPIO DSR MOSI PLAI[6] Y Y Y Y Y
P1.7 GPIO DTR CSL PLAO[0] Y Y Y Y Y
P2.0 GPIO CONVSTART SOUT PLAO[5] Y Y Y Y Y
P2.1 GPIO PWM0H WS PLAO[6] - - - - Y
P2.2 GPIO PWM0L RS PLAO[7] - - - - Y
P2.3 GPIO   AE   - - - - Y
P2.4 GPIO PWM0H MS0   - - - - Y
P2.5 GPIO PWM0L MS1   - - - - Y
P2.6 GPIO PWM1H MS2   - - - - Y
P2.7 GPIO PWM1L MS3   - - - - Y
P3.0 GPIO PWM0H AD0 PLAI[8] - - - Y Y
P3.1 GPIO PWM0L AD1 PLAI[9] - - - Y Y
P3.2 GPIO PWM1H AD2 PLAI[10] - - - Y Y
P3.3 GPIO PWM1L AD3 PLAI[11] - - - Y Y
P3.4 GPIO PWM2H AD4 PLAI[12] - - - Y Y
P3.5 GPIO PWM2L AD5 PLAI[13] - - - Y Y
P3.6 GPIO PWMTRIP AD6 PLAI[14] - - - Y Y
P3.7 GPIO PWMSYNC AD7 PLAI[15] - - - Y Y
P4.0 GPIO   AD8 PLAO[8] - - - Y Y
P4.1 GPIO   AD9 PLAO[9] - - - Y Y
P4.2 GPIO   AD10 PLAO[10] Y - - Y Y
P4.3 GPIO   AD11 PLAO[11] - - - Y Y
P4.4 GPIO   AD12 PLAO[12] - - - Y Y
P4.5 GPIO   AD13 PLAO[13] - - - Y Y
P4.6 GPIO   AD14 PLAO[14] - - - Y Y
P4.7 GPIO   AD15 PLAO[15] - - - Y Y

All pins are configured as GPIO by default. Each GPIO pin has an internal
pull-up that can be configured with GPxPAR register. They can source up to
1.6mA current.

An input value on a GPIO can be read from the MMR (Memory Mapped regiser)
register GPxDAT, even when the pin is configured in a mode other than GPIO.
After entering the power-save mode, GPIO pins remain in the same unchanged
state.
Each port is controlled by the following MMRs registers:

Register Function
GPxCON pin function configuration
GPxPAR enables/disables internal 100kOhm pull-up
GPxDAT data direction: input / output; reading back and setting pin value
GPxSET setting high value on chosen pin. Each bit maps single pin/bit in GPxDAT. Writing 0 to particular bit causes no change; writing 1 to a particular bit causes setting high respective bit in
GPxDAT.
GPxCLR clearing value on chosen pin; Each bit maps single pin/bit in GPxDAT. Writing 0 to particular bit causes no change; writing 1 to a particular bit
causes clearing value of respective pin/bit in GPxDAT.

Pin configuration register GPxCON:

---
Pull-up configuration GPxPAR:

---
Data register GPxPAR:

---
Data register GPxSET:


---

Data register GPxCLR:


Simple example of GPIO (blinking diode connected to P4.2):

#include <ADuC7024.H>
 
void gpio_led_on(void)
{
  GP4DAT = 0x04040000;
}
 
void gpio_led_off(void)
{
  GP4DAT = 0x04000000;
}
 
void gpio_led_toggle(void)
{
  GP4DAT ^= 0x00040000;
}
 
int main(void)
{
	int i;
	GP4DAT = 0x04000000;  /* define as an oUtput */
	while (1) {
		gpio_led_toggle();		
 		for (i = 0; i < 50000; i++); // waiting loop;
  	}
 
}

Another example - reading back value of button connected to P0.4.

#include <ADuC7024.H>
 
void gpio_led_on(void)
{
  GP4DAT = 0x04040000;
}
 
void gpio_led_off(void)
{
  GP4DAT = 0x04000000;
}
 
void gpio_led_toggle(void)
{
  GP4DAT ^= 0x00040000;
}
 
int read_button(void)
{
	return GP0DAT & 0x00000010;
}
 
int main(void)
{
 
	GP0DAT = 0x00000000;  /* define as an output */
	GP4DAT = 0x04000000;  /* define as an output */
	while (1) {
		if (read_button())
			gpio_led_on();		
		else
			gpio_led_off();
  	}
}

GPxCON are set after reset to default value of 0x00000000. Therefore in above
examples there is no need for setting these registers.