pic micro sep 10 day1 - copy - guceee.guc.edu.eg/courses/electronics/elct706 microelectronics...
TRANSCRIPT
bb
PIC Microcontroller
Prepared by:Ahmed Usama
References
Group Formation
• Group of 4 persons.• Nominate a representative.
MICROCONTROLLERS1st DAY
MICROCONTROLLERS1st DAY
ReviewWhat is the embedded systemMicroprocessor , Microcontroller and FPGA.Why a microcontroller is needed?Variety of microcontrollers.Why PIC microcontrollers?Specificiations of PIC 16F877.Programming PIC 16F877.PIC 16F877 in circuit.Application.
Review• Digital System:
– A system that works with discrete elements of information rather than with continuous signals as in an analog system.
– This discrete information is represented in binary form. – Data processing is carried out by means of binary logic
elements using binary signals. – Quantities are stored in binary storage elements (memory).
8
There are two primary classifications of logic circuits(System):1. Combinational logic circuits
• Circuits of this type have outputs that are functions of the inputs (illustrated below)
• The order in which the inputs are applied is not important.• Combinational logic circuits have no capability for memory
Combinational Logic Inputs Outputs = f(Inputs)
Combinational Logic Circuit
9
2. Sequential logic circuits• Circuits of this type have outputs that are functions of both inputs
and previous outputs (illustrated below)• Sequential circuits contain some type of memory elements. As an
example, a counter must “remember” that its previous output was 6 in order to produce its new output 7.
CombinationalLogic
Inputs Outputs = f(inputs + past outputs)
Memory
Sequential Logic Circuit
Embedded System• An embedded system is a computer system designed
to perform one or a few dedicated functions(often real-time).
• Hardware and Software expected to function without human intervention.
• Respond, monitor, control external environment using sensor and actuators.
• In contrast a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs.
Why Embedded systems
• Low cost. Small packaging.• Low power consumption.• Programmable, re-programmable.• Easy integration with circuit.• For application in which cost, power and space are
critical• Single-purpose• Real-time operation.(ex: ABS (WSS) ; ECU(FI))• Application dependent processor.• Automation
Automation
• Control• Electronic circuits• Power Electronics• Mechanics
• A microcontroller is a specialized form of microprocessor that is designed to be self-sufficient and cost-effective, where a microprocessor is typically designed to be general purpose (the kind used in a PC). Microcontrollers are frequently found in automobiles, office machines, toys, and appliances.
• Microcontroller combines onto the same chip: The CPU core (microprocessor),Memory (both ROM and RAM) ,Some parallel digital I/O …
• A microcontroller is part of an embedded system, which is essentially the (Microcontroller + whole circuit board) to perform dedicated task.
• Microcontroller incorporates features of microprocessor(CPU,ALU,Register) along with the presence of added features like RAM, ROM, I\O ports, counter etc.
• A microcontroller controls the operation of machine using fixed program stored in Rom that doesn't change with lifetime
What is the difference?
• Microprocessor• Microcontrollers• FPGA
SO• Microcontrollers are intelligent
electronic devices used to control and monitor devices in the real world
• Microcontrollers are programmed devices.
• A program is a sequence of instructions that tell the microcontroller what to do.
Why a microcontroller is needed?
Sensors Controllers Actuators
PowerSupply
MicrocontrollerKeypad
Level Switch
Temp. Sensor
Heater
Input Valve
Output Valve
LCD
Alarm
Sensors Microcontrollers Actuators
Sensors Microcontrollers Actuators
Variety of microcontrollers
• Von Neumann Architecture where programs and data share a single memory area that is accessed over a common bus. This scheme works well for general use computers.
Harvard Architecture Vs PIC microcontroller uses Harvard architecture. This architecture design uses separate memory areas and buses for data and programs.
Architecture for computers:
Generally there are two types of architecture for computers
• CISC vs RISC – In the early days work was done in assembly language.
Therefore CPU designers tried to make instructions that would do as much work as possible. This design philosophy was named Complex Instruction Set Computer (CISC).
– With the advent of higher level languages, led to Reduced Instruction Set Computer (RISC) (Simple compiler to RISC) (simpler assembly coding).
– PIC microcontroller use RISC because there is a perception that RISC is faster than CISC:
– Ex: A processor with MUL and other one with only ADD.A processor with (ADD X(i),B,C) and other (ADD,Store).
Instruction Set
PIC Peripheral Interface Controller
Microchip Technology (www.microchip.com)Harvard ArchitectureRISC
Microchip Technology (www.microchip.com)Harvard ArchitectureRISC
• PIC Microcontrollers are small computer on a chip with some special properties:– CPU, code memory, data memory and IO Ports all included on a single
chip.– Dedicated to one task.– Small and low cost.– Embedded in many consumer devices.
• Easy to program.• Better online documentation.• Low cost.
What is PIC microcontrollers?
Which PIC microcontrollers?
• PIC SPEED
– Can use crystals, clock oscillators, or even an RC circuit.– Some PICs have a built in 4MHz RC clock.– 16F877 and 16F877A
Specificiations of PIC
Specificiations of PIC
40MHz
4MHz
10MHz
20MHz
33MHz
Max. Speed
PIC 16F877
• 8 kbytes of FLASH Program Memory• 368 bytes of Data Memory (RAM)• 256 bytes of EEPROM Data Memory• 20 MHz operating speed(200 ns instruction cycle)• Max. 25 mA current from an output pin• Low-power consumption• Wide Operating Voltage: 2.0 – 5.0 V• Timers
– Timer0: 8-bit timer/counter with 8-bit prescaler– Timer1: 16-bit timer/counter with prescaler, can be incremented during sleep via external crystal/clock– Timer2: 8-bit timer/counter with 8-bit period register,prescaler and postscaler
• Capture, Compare, PWM modules– Capture is 16-bit, max. resolution is 12.5 ns– Compare is 16-bit, max. resolution is 200 ns– PWM max. resolution is 10-bit
• 10-bit multi-channel A-to-D Converter• I2C (Inter IC)Bus• USART for Serial Communication• 5 I/O Ports: A, B, C, D, and E (33 input or output pins)
Specificiations PIC 16F877
Languages•Assembly•BASIC•C•Code Flow
Parallel portSerial portUSB port
Programming PIC 16F877
As a result of a successful compilation and assembling of a PIC BASIC program the following files will be created.- BLINK.ASM - assembly file- BLINK.LST - program listing- BLINK.HEX - executable file which is written into the programming memory
Pic Basic Pro
IDE(Integrated Development Environment)
• ISE Pack (FPGA)• MikroC• MpLab• Proton• PICsimulator
Programming Languages
• C-Language• Assembly• BASIC
Minimum circuitry for PIC16F877
• Power Supply• Clock generation• Reset
PIC 16F877
PIC 16F877
PIC 16F877
Minimum circuitry for PIC16F877
TRISB("TRI-State Enable" registers for port bOne register used to define if the B is set input or output
mode of each bit (1 for an input; 0 for an output).
In this example, TRISB value may be set as:TRISB=%01110100 binary or TRISB=$74 hex or TRISB=116 decimal
Exercise (PicSimulator)
PIC 16F877
Button and Leds
Methods of Isolation
• Transistors• Optocoupler• Relay driver
Optocoupler
Relay driver board
Motor Direction Control
SPDT Relay (H-Bridge)
Circuit Schematic
Thank you