1 / 14

Peripherals & I/O lines

Peripherals & I/O lines. All the on-chip peripherals are configured and controlled through Special Function Registers (SFR) Many of the SFR’s are bit addressable The 111 I/O lines are arranged into Ports

Download Presentation

Peripherals & I/O lines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Peripherals & I/O lines • All the on-chip peripherals are configured and controlled through Special Function Registers (SFR) • Many of the SFR’s are bit addressable • The 111 I/O lines are arranged into Ports • Some port lines have multiple functions which must be configured for correct operation of the required function.

  2. Infineon 167 I/O Ports • 111 I/O lines with individual bit addressability • Tri-stated in input mode • Selectable input thresholds (not on all pins) • Push/pull or open drain output mode • Programmable port driver control

  3. M167CS Functional Block Diagram

  4. Digital I/O Ports • Port is where data enters/leaves the system • Digital I/O lines are normally grouped into 8-bit ports or possibly 16-bit ports • Ports must be configured for input or output before they are used • Most ports allow a mixture of inputs and outputs on the same port • Some microcontrollers have instructions that access individual bits of a port

  5. M167 digital I/O ports • Associated with a port is a DIRECTION register and on some a Port output control • Port direction - '0' = input, '1' = output • Output control – '0' = Push/pull, '1' = open-drain • In Keil 'C' all the SFR's are defined in the header file "c167cs.h" with the Infineon standard names • Px – is Port x • DPx – is the Direction for Port x • ODPx = Open Drain Control for Port x

  6. Typical Port Structure

  7. Output Driver Types Push/Pull Output Driver Open-Drain Output Driver

  8. Parallel Ports in u-Vision 2

  9. Using all bits of ports • Outputs • DP4 = 0xff; // Direction all outputs • P4 = value8; // output value to all 8-bits • DP2 = 0xffff; • P2 = value16; • Inputs • DP6 = 0x00; //Direction all inputs • x = P6; // Read all 8-bits into variable x • x would normally be an unsigned char but could be unsigned int

  10. Bit Manipulation in 'C' • 'C' bit operators (binary operators) OP symbol Description & AND | OR ^ XOR >> n shift bits right n places << n shift bits left n places • y = y OP z; can be written as y OP= z; E.g.'s y = y & 0x80; y = y >> 4; y &= 0x80; y >>= 4; • unary operator ~ complements (invert all bits) e.g. y = ~y;

  11. Masking to achieve bit manipulations • Masking uses AND and OR operators • Use OR ('|') to set bits to '1' • Use AND ('&') to set bits to 0

  12. Controlling output bits – Output Masking • Setting bits to 1 using OR (|) • General format: Port = Port | mask; • Mask has '1' to set a bit, '0' to leave bit unchanged. Example: Set bit 3 to '1' P4 = P4 | 0x08; // 0x08 = 00001000 binary • Setting bits to 0 using AND (&) • General format: Port = Port & mask; • Mask has '0' to clear a bit, and '1' to leave bit unchanged. Example: Set bit 3 to '0' P4 = P4 & 0xf7; // 0xf7 = 11110111 binary

  13. Input Masking • Use AND (&) and a mask to isolate a selected bit • Used in input Polling to test an individual input bit • Loop until a bit becomes logic '1' while( (P4 & 0x08) == 0) { ; } • Two possible results 00000000 or 00001000 • I.e. zero or non-zero • Loop until a bit becomes logic '0' while( (P4 & 0x08) != 0) { ; } • Often written as while( P4 & 0x80); // in 'C' zero is FALSE, non-zero is TRUE

  14. bit variables • The Keil C compiler supports the bit addressable features of Infineon microcontrollers • General declaration format sbit bitname = Portx^y; // port x bit y E.g. sbit motor_dir = DP2^10; sbit motor = P2^10; • MUST declare sbit's before 'C' main() function • Using sbit's motor_dir = 1; // Set bit to output motor = 1; //turn on motor

More Related