/* =============================================================================== Name : lcd_display.c Author : $(author) Version : Copyright : $(copyright) Description : main definition =============================================================================== */ #include "LPC8xx.h" #define SYSAHBCLKCTRL(*(unsigned long *)0x40048080) #define DIR0(*(unsigned long *)0xA0002000) #define PIN0(*(unsigned long *)0xA0002100) #define SET0(*(unsigned long *)0xA0002200) int main(void) { /* Enable GPIO peripheral clock */ SYSAHBCLKCTRL=(1<<6); DIR0=0xffffffff; PIN0=0xa5a5a5a5; while(1) { } return 0 ; } |
/* Enable GPIO peripheral clock */ SYSAHBCLKCTRL=(1<<6); |
/* Enable GPIO peripheral clock */ SYSAHBCLKCTRL|=(1<<6); |
/* =============================================================================== Name : gpio.c Author : Karthik Description : This program does the following: 1. Configures all the GPIO pins as output 2. Makes alternate pins HIGH The objective of this code is to show how to control the GPIOs in LPC812. Library : No Libraries are used. Test setup : LPC812 Cerebro EVK =============================================================================== */ /* * Registers to be accessed: * SYSAHBCLKCTRL->System Clock Control Register->Address 0x40048080 * DIR0->GPIO Direction control register->Address 0xA0002000 * SET0->GPIO pin setting register-> Address 0xA0002200 * PINENABLE0->Switch Matrix Register to ->Address 0x4000C1C0 * Disable SWD function on PIO0_2 * & 3 pins */ //Maps the Register at address 0x40048080 (which is SYSAHBCLKCTRL) to the variable SYSAHBCLKCTRL; //SYSAHBCLKCTRL is defined as the pointer variable of type "volatile unsigned long" which points //to the address 0x40048080; //(*(volatile unsigned long *)0x40048080) points to the content of register at address 0x40048080; //This applies to all other register mapping in #define; #define SYSAHBCLKCTRL(*(volatile unsigned long *)0x40048080) #define DIR0(*(volatile unsigned long *)0xA0002000) #define SET0(*(volatile unsigned long *)0xA0002200) #define PINENABLE0(*(volatile unsigned long *)0x4000C1C0) int main(void) { /* * The SYSAHBCLKCTRL register enables the clocks to individual system and peripheral blocks. * Making the bit 6 as '1' enables the clock to GPIO block. * By default, all the pins except PIO0_2 & 3, are GPIO pins upon power_on. * In order to access the GPIOs, we need to enable the clock for GPIO block. * Upon reset, GPIO clock is enabled. But to be on safer side we are enabling * the GPIO clock in SYSAHBCLKCTRL register as below. */ SYSAHBCLKCTRL|=(1<<6); /* * DIR0 register is used to set the direction of the GPIO pins. * 1 makes it output; 0 makes it input. */ DIR0|=0xffffffff; /* * Here PINENABLE0 register is accessed in order to disable SWD function in * PIO0_2 and 3 pins. Only then we can access them as any other GPIO. */ PINENABLE0|=(1<<2); PINENABLE0|=(1<<3); /* * SET0 register is used to make the GPIO pins HIGH or LOW. */ SET0= 0xaaaaaaaa; //Continuous loop to keep the program running infinitely. while(1); return 0; } |
#include "LPC8xx.h" #define SYSAHBCLKCTRL(*(volatile unsigned long *)0x40048080) #define DIR0(*(volatile unsigned long *)0xA0002000) #define PIN0(*(volatile unsigned long *)0xA0002100) #define SET0(*(volatile unsigned long *)0xA0002200) int main(void) { /* Enable GPIO peripheral clock */ SYSAHBCLKCTRL=(1<<6); DIR0=0xffffffff; PIN0=0xa5a5a5a5; while(1) { } return 0 ; } |