pic micro sep 10 day1 - copy - guceee.guc.edu.eg/courses/electronics/elct706 microelectronics...

57

Upload: dinhkiet

Post on 12-Mar-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

bb

Page 2: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC Microcontroller

Prepared by:Ahmed Usama

Page 3: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

References

Page 4: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Group Formation

• Group of 4 persons.• Nominate a representative.

Page 5: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

MICROCONTROLLERS1st DAY

Page 6: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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.

Page 7: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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).

Page 8: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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

Page 9: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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

Page 10: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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.

Page 11: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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

Page 12: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Automation

• Control• Electronic circuits• Power Electronics• Mechanics

Page 13: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 14: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 15: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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

Page 16: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

What is the difference?

• Microprocessor• Microcontrollers• FPGA

Page 17: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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.

Page 18: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Why a microcontroller is needed?

Sensors Controllers Actuators

Page 19: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PowerSupply

MicrocontrollerKeypad

Level Switch

Temp. Sensor

Heater

Input Valve

Output Valve

LCD

Alarm

Sensors Microcontrollers Actuators

Page 20: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Sensors Microcontrollers Actuators

Page 21: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Variety of microcontrollers

Page 22: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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

Page 23: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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

Page 24: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC Peripheral Interface Controller

Microchip Technology (www.microchip.com)Harvard ArchitectureRISC

Microchip Technology (www.microchip.com)Harvard ArchitectureRISC

Page 25: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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?

Page 26: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Which PIC microcontrollers?

Page 27: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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

Page 28: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Specificiations of PIC

40MHz

4MHz

10MHz

20MHz

33MHz

Max. Speed

Page 29: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC 16F877

Page 30: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

• 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

Page 31: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Languages•Assembly•BASIC•C•Code Flow

Parallel portSerial portUSB port

Programming PIC 16F877

Page 32: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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

Page 33: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

IDE(Integrated Development Environment)

• ISE Pack (FPGA)• MikroC• MpLab• Proton• PICsimulator

Page 34: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Programming Languages

• C-Language• Assembly• BASIC

Page 35: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 36: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Minimum circuitry for PIC16F877

• Power Supply• Clock generation• Reset

Page 37: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC 16F877

Page 38: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 39: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC 16F877

Page 40: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 41: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC 16F877

Page 42: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 43: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Minimum circuitry for PIC16F877

Page 44: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 45: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

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

Page 46: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Exercise (PicSimulator)

Page 47: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

PIC 16F877

Page 48: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Button and Leds

Page 49: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Methods of Isolation

• Transistors• Optocoupler• Relay driver

Page 50: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Optocoupler

Page 51: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Relay driver board

Page 52: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 53: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,
Page 54: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Motor Direction Control

Page 55: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

SPDT Relay (H-Bridge)

Page 56: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Circuit Schematic

Page 57: pic micro sep 10 day1 - Copy - GUCeee.guc.edu.eg/Courses/Electronics/ELCT706 Microelectronics Lab/pic... · parallel digital I/O … • A microcontroller is part of an embedded system,

Thank you