PKP
VS1000 P
ROGRAMMER
’
S
G
UIDE
VSMPG
7.2
Making the LEDs blink
The example code below will blink the two LEDs that are connected to VS1000’s SI and
SO pins on the Developer Board and the Demonstration Board. Controlling the pins
directly requires switching the pin modes from Peripheral control to General Purpose IO
control and setting their Output Enable bits to “1”.
#include <vs1000.h>
/// Busy wait i hundreths of second at 12 MHz clock
auto void BusyWaitHundreths(u_int16 i) {
while(i){
BusyWait10(); // Rom function, busy loop 10ms at 12MHz
}
}
void main(void) {
PERIP(GPIO1_MODE) = 0x30; /* UART=peripheral(1) , SPI=GPIO(0) */
PERIP(GPIO1_DDR) = 0x0c; /* SI and SO pins (GPIO1[3:2]) are output(1) */
while(1){
PERIP(GPIO1_ODATA) = 0x04; /* GPIO1[2] (LQFP pin 24) = 1 */
BusyWaitHundreths(50);
PERIP(GPIO1_ODATA) = 0x08; /* GPIO1[3] (LQFP pin 25) = 1 */
BusyWaitHundreths(50);
}
}
The SPI port pins and UART port pins are controlled by the same I/O controller, I/O
controller 1. When disabling peripheral control of the SPI pins, the UART pins (RX, TX)
must remain under peripheral control. Otherwise, the connection with vs3emu is lost.
For reference, here are the GPIO1 pin mappings of VS1000:
VS1000 I/O Controller 1 pins and peripheral functions
GPIO
Ident
LQFP
Pin
Function
GPIO1[0]
XCS
22
SPI XCS / General-Purpose I/O Port 1, bit 0
GPIO1[1]
SCLK
23
SPI CLK / General-Purpose I/O Port 1, bit 1
GPIO1[2]
SI
24
SPI MISO / General-Purpose I/O Port 1, bit 2
GPIO1[3]
SO
25
SPI MOSI / General-Purpose I/O Port 1, bit 3
GPIO1[4]
TX
26
UART TX / General-Purpose I/O Port 1, bit 4
GPIO1[5]
RX
27
UART RX / General-Purpose I/O Port 1, bit 5
Rev. 0.20
2011-10-04
Page