220 likes | 383 Views
بسم الله الرحمن الرحيم. The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department. Microprocessor and Microcontroller Based Systems. EELE 4315 — Fall 2010. Instructor: Eng.Moayed N. EL Mobaied. Lecture 9.
E N D
بسم الله الرحمن الرحيم The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Microprocessor and Microcontroller Based Systems EELE 4315 — Fall 2010 Instructor: Eng.Moayed N. EL Mobaied Lecture 9
Digital Input/Output and the 16F84A Why Digital Input/Output? Almost any embedded system needs to transfer digital data between its CPU and the outside world. This transfer falls into a number of categories, which can be summarised as: Direct user interface, including switches, keypads, light emitting diodes (leds) and displays; Input measurement information, from external sensors, possibly being acquired through an analog to digital converter; Output control information, for example to motors or other actuators; Bulk data transfer to or from other systems or sub-systems, moving in serial or parallel form, for example sending serial data to an external memory. How can we provide the required interface between the microcontroller core and the outside world? More precisely, how do we get the data onto or off the data bus at the right moment?
Digital Input/Output and the 16F84A Parallel Output We could apply a circuit like this for output. Here a pulse on the Port Select line captures data on the bus at that instant, and transfers it to the external pin. Two lines of Data Bus D Q Read/Write External Pin Port Select Flip-flop latches data bus value onto external pin, when memory location high whenever is selected, AND Write is active port address is selected D Q External Pin
Digital Input/Output and the 16F84A Parallel Input Or we could apply a circuit like this for input. Here a pulse on the Port Select line transfers data on the external pin at that instant to the data bus. Two lines of Data Bus Read/Write External Pin buffer transfers logic value on external pin Port Select onto data bus line, when memory location is selected, AND Read is active External Pin
Digital Input/Output and the 16F84A A Bi-Directional Port Pin Driver Circuit Or, we could combine both circuits into one multi-function circuit, like this. You don’t need to grasp all the detail of this circuit, although it’s neat if you can. There is now an extra flip-flop, labelled “Direction”. The state of this decides in which direction data will flow. The two flip-flops shown can each form one bit in an SFR, which can be controlled from the CPU. A group of these bits, each driven by a circuit like this, is called a “port Read/Write Read/Write Read Port Read Port Data Bus Data Bus (bit n) (bit n) Input Buffer Input Buffer I/O Pin I/O Pin "Data" "Data" (bit n of an (bit n of an Output Buffer Output Buffer Write Write D D Q Q 8 8 - - bit port) bit port) Port Port Port Select Port Select holds bit holds bit output value output value 8 of these 8 of these buffer, enabled buffer, enabled flip-flops form flip - - flops form when pin is output when pin is output the "Data" SFR the "Data" SFR "Direction" "Direction" Write Write D D Q Q DDR DDR determines whether port determines whether port Direction Select Direction Select bit is input or output bit is input or output Alternate Input Alternate Input Function Function "Data" SFR "Data" SFR 8 of these flip 8 of these flip - - flops form flops form the "Data Direction" SFR the "Data Direction" SFR "Direction" SFR "Direction" SFR
Holds output data From Option Register Output buffer Value held determines data direction 0 on this line enables output buffer Digital Input/Output and the 16F84A Decoded address lines
Digital Input/Output and the 16F84A Port Input Characteristics When designing with microcontroller digital I/O one needs to have an understanding of their electrical characteristics. 16F84A Input Characteristics The input of a logic gate or port pin requires the voltage to be below a certain maximum in order to be recognised as a logic 0, or above a certain minimum to be recognised as a logic 1. • Minimum Input High Voltage, VIH 2.4V (TTL buffer inputs) • Maximum Input Low Voltage, VIL 0.8V (TTL buffer inputs) • Input Leakage Current, IIL+1mA • PIC 16F84A Port Input Characteristics (5V power supply)
Digital Input/Output and the 16F84A Simple Digital Interfacing – connecting to switches
Digital Input/Output and the 16F84A Light Emitting Diodes (leds) - Review High Efficiency Red Yellow
Digital Input/Output and the 16F84A Driving LEDs from Logic Gates (and hence Port Bit Outputs) V S current flows out of the gate and lights led when output is at logic 1 I R D R current flows into gate V and lights led when D output is at logic 0 I V D D a) Gate Output Sourcing b) Gate Output Sinking Current to LED Current from LED
PIC Microcontrollers Families PIC controllers are roughly classified by Microchip into three groups: baseline, mid-range, and high performance. Within each of the groups the PICs are classified based on the first two digits of the PIC’s family type. However, the sub classification is not very strict, since there is some overlap. For this reason we find PICs with 16X designations that belong to the baseline family and others that belong to the mid-range group.
Baseline PIC Family This group includes members of the PIC10, PIC12, and PIC16 families. The devices in the Baseline group have 12-bit program words and are supplied in 6- to 28-pin packages. The microcontrollers in the baseline group are described as being suited for battery-operated applications since they have low power requirements. The typical member of the Baseline group has a low pin count, flash program memory, and low power requirements.
Mid-range PIC Family The mid-range PIC family includes members of the PIC12 and PIC16 groups. According to Microchip, the mid-range PICs all have 14-bit program words with either flash or OTP program memory. Those with flash program memory have EEPROM data memory and support interrupts. Some members of the mid-range group have USB, I2C, and converters A/D.
Mid-range PIC Family Implementations range from 8 to 64 pins. This is by far the most extensive PIC family. Currently, over 80 versions of the PIC16 are listed in production by Microchip. The Microchip website has more detailed information on these devices.
High-Performance PIC Family The high-performance PICs belong to the PIC18 group. They have 16-bit program words, flash program memory, a linear memory space of up to two Mbytes, and protocol-based communications facilities. They all support internal and external interrupts and have a much larger instruction set than members of the baseline and mid-range families.
High-Performance PIC Family The PIC18 family is also a large one, with over 70 different variations currently in production. The PIC18 family uses 16-bit program words and are furnished in 18 to 80 pin packages. Microchip describes the PICs in this family as high-performance with integrated A/D converters. They have 32-level stacks and support interrupts. The instruction set is much larger and starts at 79 instructions. The PICs in this family have flash program memory, a linear memory space of up to 2 Mbytes, 8-by-8 bit hardware multiplier, and communications peripherals and protocols.