Peripherals - PowerPoint PPT Presentation

About This Presentation
Title:

Peripherals

Description:

Example: Set bit 3 to '0' P4 = P4 & 0xf7; // 0xf7 = 11110111 binary. 3-13. Input Masking ... Using sbit's. motor_dir = 1; // Set bit to output. motor = 1; ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 15
Provided by: alang66
Category:

less

Transcript and Presenter's Notes

Title: Peripherals


1
Peripherals I/O lines
  • All the on-chip peripherals are configured and
    controlled through Special Function Registers
    (SFR)
  • Many of the SFRs 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
  • gtgt n shift bits right n places
  • ltlt 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 gtgt 4 y
    0x80 y gtgt 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

OR OR OR
A B Output
0 0 0
0 1 1
1 0 1
1 1 1
AND AND AND
A B Output
0 0 0
0 1 0
1 0 0
1 1 1
XOR XOR XOR
A B Output
0 0 0
0 1 1
1 0 1
1 1 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 Portxy // port x bit y
  • E.g. sbit motor_dir DP210
  • sbit motor P210
  • MUST declare sbit's before 'C' main() function
  • Using sbit's
  • motor_dir 1 // Set bit to output
  • motor 1 //turn on motor
Write a Comment
User Comments (0)
About PowerShow.com