Presentation is loading. Please wait.

Presentation is loading. Please wait.

3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or.

Similar presentations


Presentation on theme: "3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or."— Presentation transcript:

1 3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or 32-bit ports. A digital I/O port is normally accessed as a single entity through a register. The direction (i.e. input or output) of the digital I/O pins must be configured before they are used. It is possible in most systems to have a mixture of inputs and outputs on a port. Some microcontrollers have instructions that access individual bits of a port rather than the whole port.

2 3-2 LPC23XX Functional Block Diagram The LPC2364/66/67/68 family The LPC2368 has 70 digital I/O pins, most pins have alternate functions. The default on reset is digital I/O

3 3-3 I/O pins and on-chip peripherals Most I/O pins on microcontrollers have multiple functions. The microcontroller must be configured to select the correct function. The PINSEL registers control the functions of the device pins. Function select bits (from the PINSEL register) PIN CONNECT BLOCK GP I/O P2[0]PWM1[1]TRACECLKTXD1 Physical I/O pin 10010011

4 Simple Digital I/O applications Applications of General purpose I/O  Driving simple digital output devices such as LEDs, or other indicators.  Controlling off-chip devices.  Sensing digital input levels, detecting signal transitions.  Bringing the part out of Power Down modes.  Digital inputs can be configured to generate interrupts (the subject of a later lecture). 3-4

5 3-5 LPC2368 General purpose I/O The LPC2368 has five 32-bit Ports (numbered 0 to 4) Not all 32 bits are implemented in each port. LQFP100 Package TFBGA100 Package See lpc23xx_um.pdf onBlackboard site

6 LPC2368 General Purpose I/O 3-6 The PORTS are accessed through specific registers. (These registers are memory locations that are defined in the header file LPC23XX.h) All the ports are accessible through FIO registers - these uses a fast internal bus operation. Each Port has its own set of FIO registers to setup, control and access the port. To maintain backwards compatibility with previous devices PORT0 and PORT1 are also accessible by an alternate set of registers - using a slower internal bus. We should use always use the FIO registers not the slower ones!

7 The FIO Registers Allow direction control of individual bits. An entire port value can be read or written in one instruction. Bit-level set and clear registers allow a single instruction set or clear of any number of bits in one port. Mask registers allow treating sets of port bits as a group, leaving other bits unchanged Remember all I/O pins default to input after reset. 3-7

8 Fast IO registers for PORT Access 3-8 Generic Name DescriptionAccessReset value Port Register name and address FIODIRPort Direction control register. This register individually controls the direction of each port pin. R/W0x0 FIO0DIR - 0x3FFF C000 FIO1DIR - 0x3FFF C020 FIO2DIR - 0x3FFF C040 etc. FIOPINFast Port Pin value register. The current state of digital port pins can be read from this register, regardless of the pin direction or alternate function selection. Values written to this register will be output on those port pins configured as outputs (this is not strictly true and actually depends on another register). R/W0x0 FIO0PIN - 0x3FFF C014 FIO1PIN - 0x3FFF C034 FIO2PIN - 0x3FFFC054 etc. There are three additional registers that also influence access and control of the port ( FIOSET,FIOCLR and FIOMASK) but the above two registers are all we need at present.

9 FIO Registers and Port DIRECTION Setting port direction to OUTPUT  Set bits in FIOxDIR register ( 1 for output, 0 for input)  Examples: FIO2DIR = 0x000000FF; //make PORT2 bits 0 to 7 output FIO2DIR = 0x00000040; // make PORT2 bit 6an output. Note this also makes bits 0-4 and 8-31 inputs (the default anyway) If we want to only affect specific bits we can use masking:-  FIO2DIR |= 0x00000040; // only change bit 6 using OR  FIO2DIR |= (1 << 6); // simpler? 3-9

10 FIO Registers and Port DIRECTION Setting port direction to INPUT  PORTS default to input on reset.  Set Direction using FIOxDIR (No harm in explicitly setting FIOxDIR)  Examples: FIO2DIR = 0x00000000;// make ALL bits inputs (the default after a reset) FIO2DIR &= 0xFFFFFB00;// make bit 10 an input leave rest unchanged! FIO2DIR &= ~0x00000400;// ? FIO2DIR &= ~(1<<10);// 3-10

11 Polling input pins Remember: All 32 bits are read on input Isolate bits using masking e.g. for bit 10  Wait for a bit to change  do { x = FIO2PIN; } while((x & (1<<10)) == 0); //is bit 0?  while( (FIO2PIN & (1<<10)) == 0 ) //is bit 0?  while( (FIO2PIN & (1<<10)) != 0 ) //is bit 1?  test bit  if (FIO2PIN & (1<<10) == 0)  if (FIO2PIN & (1<<10) != 0) 3-11

12 3-12 Using ports in our programs 1. In the 'C' program include the special system header file for the LPC2368 processor which defines ALL the special register locations:- #include 2. Configure the direction for the I/O pins before they are used (this is usually done just once at the beginning of the program). 3. Use the relevant FIOxPIN register to perform the I/O. Note the position in relation to the "=" 4. Output FIO2PIN = expr ; // on LHS of = 5. Input var = FIO2PIN;// on RHS of = Note: For input we usually need a variable to store the inputted value.

13 3-13 #include // LPC23xx definitions int main (void) { Port2Init(); while(1) { FIO2PIN |= 0x000000FF; Delay(); FIO2PIN |= ~0x000000FF; Delay(); } void Port2Init(void) { PINSEL10 = 0; // Disable ETM interface, enable LEDs FIO2DIR = 0x000000FF; // P2.0..7 defined as Outputs FIO2MASK = 0x00000000; // Unmask all port bits } //Delay function not shown. Program fragment


Download ppt "3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or."

Similar presentations


Ads by Google