;--------------------------------------------------------------------------- ; ; Programmer : Larry Aamodt ; ; File name : demo_gpio.s ; Class : CPTR-215 ; Language : ARM assembly ; Assembler : Keil ; Target MCU : NXP LPC-2148 on Embedded Artists board ; Date Written: 11/07/12 LDA ; change history: ; ; Description : Example program shows writing to gpio to turn bits on/off ; First it loads four addresses into registers ; Then programs pins 8 to 15 for output ; Inputs : ; ; Outputs : Port zero bits 15 down to bit 8 can be referred to as ; P0.15 down to P0.8 (ordered as they would be left to ; right). Sometimes it seems more natural to refer to ; them in counting order, i.e. P0.8 to P0.15 ; ; Special : This sample code can be run on the simulator. You ; requirements can view the gpio pins, see handout. ; ; ; NOTES: If this code were run on the hardware board, GPIO bits 8 to 15 ; would turn LEDs on and off. Also, recall that for a 32 bit word ; that the left bit is bit 31 and the right bit is bit zero. ; ;--------------------------------------------------------------------------- ; Memory addresses for General Purpose I/O (GPIO) port zero ; IO0PIN 0xE0028000 This is the actual I/O pin, i.e. the actual I/O ; IO0SET 0xE0028004 Used to set one or more I/O pins to logic one ; IO0DIR 0xE0028008 Used to specify signal direction for each pin ; IO0CLR 0xE002800C Used to clear one or more I/O pins to logic zero ; User program code goes here AREA demo_gpio, CODE main LDR r1,=0xE0028000 ; load address of I/O port 0 pins LDR r2,=0xE0028004 ; load addr of I/O port 0 set register LDR r3,=0xE0028008 ; load addr of I/O port 0 direction reg LDR r4,=0xE002800C ; load addr of I/O port 0 clear register LDR r0,=0xFF00 ; bits 15 down to 8 are ones STR r0,[r3] ; program pins 15 down to 8 for output LDR r0,=0x0100 STR r0,[r2] ; set pin 8 to logic 1 (high voltage) LDR r5,[r1] ; read data that is on gpio port zero LDR r0,=0x0200 STR r0,[r2] ; set pin 9 to logic 1 LDR r6,[r1] ; read data on gpio port zero LDR r0,=0x0100 STR r0,[r4] ; clear pin 8, i.e. make it logic zero LDR r7,[r1] ; read data on gpio port zero done B done ; endless loop ; User data area definition follows AREA appdata, DATA, NOINIT, READWRITE END