0% found this document useful (0 votes)
315 views4 pages

MCB1700 Hardware

This document provides information about programming GPIO pins on the MCB1700 board using the LPC1768 microcontroller. It describes the board components, hardware block diagram, and steps for configuring GPIO pins as inputs or outputs and reading from or writing to them. The key steps are 1) configuring pin modes using PINSEL registers, 2) setting pin directions using FIODIR registers, and 3) setting pin values using FIOSET/FIOCLR for outputs or reading FIOPIN for inputs.

Uploaded by

Adip Chy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
315 views4 pages

MCB1700 Hardware

This document provides information about programming GPIO pins on the MCB1700 board using the LPC1768 microcontroller. It describes the board components, hardware block diagram, and steps for configuring GPIO pins as inputs or outputs and reading from or writing to them. The key steps are 1) configuring pin modes using PINSEL registers, 2) setting pin directions using FIODIR registers, and 3) setting pin values using FIOSET/FIOCLR for outputs or reading FIOPIN for inputs.

Uploaded by

Adip Chy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ECE254 Keil MCB1700 Hardware Programming Notes

1. MCB1700 Board Components


Figure 1 shows the important interface and hardware components of the MCB1700 board. The board in our lab is populated with NXP 1768 microcontroller.

Figure 1 MCB1700 Board Component (image courtesy of Keil)

2. MCB1700 Hardware Block Diagram


The MCB1700 hardware block diagram in Figure 2 displays input, configuration, power system, and User I/O on the board. This visual presentation helps you to understand the MCB1700 board components. In particular to our lab environment, the CPU is LPC1768.

Figure 2 MCB1700 Hardware Block Diagram (image courtesy of Keil)

3. LPC1768 GPIO(General Purpose I/O) Programming


The peripheral complement of the LPC1768 includes 70 (100 pin package) general purpose I/O pins with configurable pull-up resistors (default), pull-down resistors, open drain mode, and repeater mode. All GPIOs are located on an AHB bus for fast access, and support Cortex-M3 bit-banding. GPIOs can be accessed by the General Purpose DMA Controller. Pins on LPC1768 are divided into 5 ports starting from 0 to 4. Pin naming convention is Px.y where x is the port number and y is the pin number. For example P1.23 means Port 1, Pin 23. Each pin has four operating modes: GPIO (default), first alternate function, second alternate function, and third alternate function. Any pin of ports 0 and 2 can be used to generate an interrupt. 1. The first step to program the GPIO is to specify the pin operating mode through configuration of PINSEL registers in the Pin Connect Block(LPC_PINCON macro defined in LPC17xx.h). There are eleven PINSEL registers and they are PINSEL0, PINSEL1, , PINSEL10, which are defined as member variables inside the LPC_PINCON_TypeDef C struct. Each one of these eleven registers controls a specific set of pins on a certain port. When the processor powers up or resets, the pins that are connected to the LEDs and joysticks are automatically configured as GPIO (default). However, it is a good practice to configure these pins before using them. Please refer to Section 8.1 of LPC17xx users manual to see which set of pins are controlled by which PINSEL register.

For example, the five button joystick is connected to pins P1.20, P1.23, P1.24, P1.25 and P1.26. To configure these pins as GPIO normally is not required since they are by default are set to GPIO. However it is a good programming practice to configure it. Please refer page 109, Section 8.5.4, Table 82 in LPC17xx Users Manual for more detailed information. LPC_PINCON->PINSEL3 &= ~((3<< 8)|(3<<14)|(3<<16)|(3<<18)|(3<<20)); /* P1.20, P1.23..26 is GPIO (Joystick) */
2. The second step of programming GPIO pin is to set the I/O direction (i.e. Is the

pin for input or output?) through FIODIR register (page 122 of LPC17xx Uers Manual). There are five LPC_GPIOx, where x=0,1,2,3,4, macros defined in LPC17xx.h file. The FIODIR is a member variable in LPC_GPIO_TypeDef C struct in LPC17xx.h. To set a pin as input, set the corresponding bit in FIODIR to 0. All I/Os default to input (i.e. all bits in FIODIR are default to 0s). To set a pin as output, set the corresponding bit in FIODIR to 1. For example, to set pins connected to the joystick as input, we write the following C code: LPC_GPIO1->FIODIR &= ~((1<<20)|(1<<23)|(1<<24)|(1<<25)|(1<<26)); /* P1.20, P1.23..26 is input (Joystick) */ To set pins connected to the LEDs as output, we write the following C code: LPC_GPIO1->FIODIR |= 0xB0000000; // P1.28..29,P1.31 is output LPC_GPIO2->FIODIR |= 0x0000007C; // P2.2..6 is output

3. The third step of programming GPIO depends on the pin direction setting. (1) The pin is set to output. We turn a pin to HIGH (i.e. digital 1) by setting the corresponding bit in FIOSET register. We turn a pin to LOW (i.e. digital 0) by setting the corresponding bit in FIOCLR register. Both FIOSET and FIOCLR are member variables defined in the LPC_GPIO_TypeDef C struct. To set a pin to digital 1, set the corresponding bit of LPC_GPIOx->FIOSET to 1. To turn a pin to digital 0, set the corresponding bit of LPC_GPIOx->FIOCLR to 1. . See sections 9.5.2 and 9.5.3 of LPC17xx Users manual for details. For example, to turn on a particular LED, the following code is used const U8 led_pos[8] = { 28, 29, 31, 2, 3, 4, 5, 6 }; mask = 1 << led_pos[led]; if (led < 3) { // P1.28..29 and P1.31 are at Port1 LPC_GPIO1->FIOSET = mask; } else { // P2.2..6 are at Port2 LPC_GPIO2->FIOSET = mask; }

To turn off a particular LED, the following code can be used. const U8 led_pos[8] = { 28, 29, 31, 2, 3, 4, 5, 6 }; mask = 1 << led_pos[led]; if (led < 3) { // P1.28..29 and P1.31 are at Port1 LPC_GPIO1->FIOCLR = mask; } else { // P2.2..6 are at Port2 LPC_GPIO2->FIOCLR = mask; }

Note: The eight LEDs are split over two separate GPIO ports, with the first three on GPIO port 1 and the remaining five on GPIO port 2. (2) The pin is set to input. We read the current pin state from FIOPIN register. The corresponding bit being 1 indicates that the pin is driven high. The corresponding bit being 0 indicates that the pin is driven low. The FIOPIN is a member variable defined in LPC_GPIO_TypeDef C struct. One normally uses bit shift operations to shift the LPC_GPIOx->FIOPIN value to obtain pin value(s). Please refer to Section 9.5.4 in the LPC17xx Users manual for details. For example, to read the joystick position, the following code can be used #define KBD_MASK 0x79 uint32_t kbd_val; kbd_val = (LPC_GPIO1->FIOPIN >> 20) & KBD_MASK; When the joystick buttons are inactive, the bits at P1.23..26 are 1s. When one of the joystick buttons is active, the bit corresponding to that pin is 0. Note: Writing to the FIOPIN register stores the value in the port output register, bypassing the need to use both the FIOSET and FIOCLR registers to obtain the entire written value. This feature should be used carefully in an application since it affects the entire port. 4. GPIO Interrupts on Port 0 and Port2 (Not required in lab3)

You might also like