Look Here First

Curious why I created this blog? The following two posts explain it all. Click on the titles below to read more.

What this Blog is about.

Project Description.

Thursday, March 31, 2011

Setting General Purpose Pins

The first thing to consider when setting an General Purpose Input Output (GPIO) pin is whether it will be reading input or writing output.  Like most other microcontrollers, this is done on the LPC2148 by assigning an IO direction to each pin of interest.  When setting up the display driver the student set four pins (22,21,19,17) as outputs.  Setting up the two GPIO pins for analog input/output is likely be more involved.

To set the pins as input pins they need to be added to the IODIR1 register. Below is an example of C code setting the GPIO pins P1 and P2 to inputs and pins P5 and P6 as outputs.  The pins SCLK and MOSI from the serial controller are also set as outputs.

//Begin Example
// The GPIO pins P1 and P2 are pins 30 and 29 respectively)
// P5 and P6 are
#define P1 (1<<30)
#define P2 (1<<29)

#define LCD_RES (1<<22)     // P5
#define LCD_CS (1<<21)  // P6
#define LCD_DIO (1<<19)
#define LCD_SCK (1<<17)


int main(void)
{
IODIR1 |= (P1 | P2);
IODIR0 |= (LCD_DIO | LCD_SCK | LCD_CS | LCD_RES);
        // .....
}
// End Example

Setting the GPIO pins as inputs or outputs is a trivial setup operation.

In examining the LPC2148 documentation the student found the PINSEL0, PINSEL1 and PINSEL2 registers. These registers control the pin connect block, which allows the micro-controller to configure pins for different functions.  The pin control block is described in detail in the 214x Users Manual, pages 75-80.

The student will use the pin select registers to enable the ADC in pin under  Accelerometer Registers, Setup and Use

(1) LPC214x Users Manual

No comments:

Post a Comment