118

micro8051-120108065855-phpapp01

Embed Size (px)

DESCRIPTION

micro8051-120108065855-phpapp01.ppt

Citation preview

  • *CONTENTS:IntroductionBlock Diagram and Pin Description of the 8051RegistersMemory mapping in 8051 Stack in the 8051I/O Port ProgrammingTimer

  • *meeting the computing needs of the task efficiently and cost effectivelyspeed, the amount of ROM and RAM, the number of I/O ports and timers, size, packaging, power consumptioneasy to upgradecost per unit

    availability of software development toolsassemblers, debuggers, C compilers, emulator, simulator, technical support

    wide availability and reliable sources of the microcontrollers.Introduction : Three criteria in Choosing a Microcontroller:

  • 8 bit controllers more requirements*

  • Embedded System :*

  • Fall 2004 Embedded SystemsDevelopment process

    Planning of tasks & interactionsedittaskcode1.A51taskcode2.cAssemblerC-compilermisc.LIBLinker/LocatorBurn in EPROMDownload to boardRevise !Debugging ???

    Embedded Systems

  • 8051 Microcontroller Kit Layout*

  • General Purpose Microprocessor v/s Microcontroller*

  • Block Diagram : 8051 *

  • *Block DiagramCPUOn-chip RAMOn-chip ROM for program code4 I/O PortsTimer 0Serial PortOSCInterrupt ControlExternal interruptsTimer 1Timer/CounterBus ControlTxD RxDP0 P1 P2 P3Address/DataCounter InputsPC Interface Lab.Stepper motor etc. LabDelay Generation Labs

  • *ROMLike BrainOscillatorLike HeartData flow Like BloodFlowPorts likeHands/LegsInternalDataBusPrepares the sequence of operations

  • 8051 Block Diagram*

  • *

  • *

  • *ROMLike BrainOscillatorLike HeartData flow Like BloodFlowPorts likeHands/LegsInternalDataBusPrepares the sequence of operations

  • SignalPins Figure8051 pinouts & Functions

  • 8051 Block Diagram

  • Fetch Cycle*

  • 8051 Family State Sequence*

  • *8051 Architecture: Salient features8 bit CPU with registers A and B16 bit Program Counter and data pointer DPTR8 bit Program Status Word8 bit Stack PointerInternal RAM 128 bytes4 Registers banks, each containing 8 Registers16 bytes, may be addressed at the bit level8 bytes of General Purpose memoryInternal ROM 4K32 I/O pins as 4 eight bit ports: P0-P32 sixteen bit timer/counters: T0 and T1Full duplex serial data receiver/transmitter: SBUFControl registers: TCON, TMOD, SCON, PCON, IP AND IE2 external and 3 internal interrupt sourcesOscillator and clock circuits.

  • *Pin Description of the 8051

  • *8051 Hardware Connections : Crystal Connection to 8051Using a quartz crystal oscillator ( Frequency 11.0592 MHz)We can observe the frequency on the XTAL2 pin. Pin 18Pin 20Pin 19

  • *Pins of 8051Vccpin 40Vcc provides supply voltage to the chip. The voltage source is +5V.GNDpin 20groundXTAL1 and XTAL2pins 19,18RSTpin 9resetIt is an input pin and is active highnormally low.The high pulse must be high at least 2 machine cycles.It is a power-on reset.Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost.

  • *Pins of 8051/EApin 31external accessThere is no on-chip ROM in 8031 and 8032 .The /EA pin is connected to GND to indicate the code is stored externally./PSEN ALE are used for external ROM.For 8051, /EA pin is connected to Vcc./ means active low./PSENpin 29program store enableThis is an output pin and is connected to the OE pin of the ROM.

  • *Pins of 8051ALEpin 30address latch enableIt is an output pin and is active high.8051 port 0 provides both address and data.The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch.I/O port pinsThe four ports P0, P1, P2, and P3.Each port uses 8 pins.All I/O pins are bi-directional.

  • *Pins of I/O PortThe 8051 has four I/O portsPort 0 pins 32-39P0P0.0P0.7Port 1pins 1-8 P1P1.0P1.7Port 2pins 21-28P2P2.0P2.7Port 3pins 10-17P3P3.0P3.7Each port has 8 pins.Named P0.X X=0,1,...,7, P1.X, P2.X, P3.XExP0.0 is the bit 0LSBof P0 ExP0.7 is the bit 7MSBof P0These 8 bits form a byte.Each port can be used as input or output (bi-direction).

  • *Power-On RESET Circuit30 pF30 pF8.2 K10 uF+Vcc11.0592 MHzEA/VPPX1X2RST3119189

  • *Hardware Structure of I/O Pin Each pin of I/O portsInternal CPU buscommunicate with CPUA D latch store the value of this pinD latch is controlled by Write to latchWrite to latch1write data into the D latch2 Tri-state bufferTB1: controlled by Read pinRead pin1really read the data present at the pinTB2: controlled by Read latchRead latch1read value from internal latchA transistor M1 gateGate=0: openGate=1: close

  • P89V51 RD2 : Electrical Specs.( Threshold Voltages)*

  • *

  • P89V51RD2 : Timing Specs.*

  • *A Pin of Port 1 8051 ICP0.x

  • *Writing 1 to Output Pin P1.X8051 IC2. output pin is Vcc1. write a 1 to the pin10output 1TB1TB2

  • *Writing 0 to Output Pin P1.X8051 IC2. output pin is ground1. write a 0 to the pin01output 0TB1TB2

  • *Reading High at Input Pin8051 IC2. MOV A,P1 external pin=Highwrite a 1 to the pin MOV P1,#0FFH103. Read pin=1 Read latch=0 Write to latch=11TB1TB2

  • *Reading Low at Input Pin8051 IC2. MOV A,P1external pin=Lowwrite a 1 to the pinMOV P1,#0FFH103. Read pin=1 Read latch=0 Write to latch=10TB1TB2

  • You can not Get Logic 1 withHeavy Load and Weak Pull-up*

  • Is it too much?- its the beginning -*LOADLOADINGEFFECT( SOURCE IS INPROBLEM

  • *A Pin of Port 0 8051 IC P1.x

  • *Port 0 with Pull-Up Resistors

  • *AddressLinesBi-DirectionalData Lines

  • *Instruction:MOV A,# 3CH743C

    Data 5Chis in FlashMemory

  • *Instruction:MOV A,3CHData is 7F hex

    At RAM Address3C hex - - ACC data will be 7F hE53C

  • *8580A0Instruction: MOV p2,p0Mov address, address85

  • *Port 3 Alternate Functions

  • 8051 PROG. MEMORY*

  • 8051 DATA MEMORY*

  • *Registers of 8051

  • *RAM memory space allocation in the 8051

  • Prof. Cherrice TraverEE/CS-152: Microprocessors and MicrocontrollersAddress ModesBit-Oriented Data Transfer transfers between individual bits.SFRs with addresses ending in 0 or 8 are bit-addressable. (80, 88, 90, 98, etc)Carry flag (C) (bit 7 in the PSW) is used as a single-bit accumulatorRAM bits in addresses 20-2F are bit addressable

    Examples of bit transfers of special function register bits:mov C, P0.0; C bit 0 of P0

    EE/CS-152: Microprocessors and Microcontrollers

  • Bit addressable Area of RAMmov R5,0fahANL A,#08Hmov c,23h.2 ; Data from RAM location ; 23hex bit .2 is transferred to carry

    mov 35.7,c; Data from Carry Flag bit is transferred ; to RAM location 35 decimal bit .7 i.e. ; 23HMov p0.1 , c ; Carry bit is transferred to Port 0 bit .1End( NOTE : RAM Loactions 20 hex to 2f hex are Bit Addressable Area ).*

  • Prof. Cherrice TraverEE/CS-152: Microprocessors and MicrocontrollersBit Addressable Memory20h 2Fh (16 locations X 8-bits = 128 bits)27262524232221202F2E2D2C2B2A2928Bit addressing:mov C, 1Ahormov C, 23h.2

    7F78

    1A100F080706050403020100

    EE/CS-152: Microprocessors and Microcontrollers

  • *Stack in the 8051The register used to access the stack is called SP (stack pointer) register.

    The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH. When 8051 powered up, the SP register contains value 07.

  • Prof. Cherrice TraverEE/CS-152: Microprocessors and MicrocontrollersStackspushpopstackstack pointerGo do the stack exercise..

    EE/CS-152: Microprocessors and Microcontrollers

  • *TimersThere are TWO general purpose 16 bit timers

    TIMER MODES:MODE 0

    MODE 1

    MODE 2

    MODE 3

  • *TIMER MODE 0Setting timer X mode bits to 00 in the TMOD registers results in using THX register as an 8 bit counter and TLX as a 5 bit counter; pulse input is divided by 32d in TL so that TH counts the original oscillator frequency by a total 384d.

  • *TIMER MODE 1SIMILAR TO MODE 0 EXCEPT tlx IS CONFIGURED AS A FULL 8 BIT COUNTER

  • *TIMER MODE 2The TLX is used as an 8 bit counter and THX is used to hold a value that is loaded into TLX every time TLX overflows from FFH to 00H.

  • *TIMER MODE 3Timer 0 in mode 3 becomes two completely separate 8 bit counters. Time 1 may work in Mode 0, 1 and 2.

  • *

  • *TMOD Register: Gate : When set, timer only runs while INT(0,1) is high.C/T : Counter/Timer select bit.M1 : Mode bit 1.M0 : Mode bit 0.

  • *The Timer Control (TCON), Special Function Register:TF1: Timer 1 overflow flag. Set when timer rolls from all 1 s to 0TR1: Timer 1 run control bit. Set to 1 by program to enable count.TF0: Timer 0 overflag. Set when timer rolls from all 1 s to 0TR0: Timer 0 run control bit. Set to 1 by program to enable count.

  • *IE1: External interrupt 1 edge flag. Set to 1 when H to L edge signal is received on port 3 pin 3.3 ( INT1)

    IT1: External interrupt 1 signal type control bit. Set to 1 by program to enable external interrupt 1 to be triggered by a falling edge signal. Set to 0 by by program to enable a low level signal on external interrupt 1 to generate and interrupt.

    IE0: External interrupt 0 edge flag. External interrupt 1 edge flag. Set to 1 when H to L edge signal is received on port 3 pin 3.2(INT0)

    IT0: External interrupt 0 signal type control bit

    TCON

  • PCB: 89c51 Microcontroller Ports*Port 3Port 1Port 2Port 0

    ATMEL 89c51 Microcontroller

  • PCB: 89c51 Microcontroller Card*ResistorArray (10K)Micro-controllerCrystal 11.0592 MHzBurge StripHeaderCapacitors30 pFPort 3Port 1Port 2Port 0

    ATMEL 89c51 Microcontroller

  • PCB: 89c51 Microcontroller Card*ResistorArray (10K)Micro-controllerCrystal 11.0592 MHzBurge StripHeaderCapacitors30 pFPort 3Port 1Port 2Port 0

    ATMEL 89c51 Microcontroller

  • *PCB: 89c51 Microcontroller CardPin 1 of 89c51Pin 20 Of 89c51Pin 21Of89c51Pin 40 of 89c51ATMEL 89c51 Microcontroller

  • Where is Clock Circuitry ?*Clock CircuitrysectionATMEL 89c51 Microcontroller

  • Clock circuitry components*Crystal 11.0592 MHzTwo Capacitors33 pF

    ATMEL 89c51 Microcontroller

  • LED Array Card : To Port 0*LED Array card to PORT 0ATMEL 89c51 Microcontroller

  • Interfacing DIP Switch & LED Array*PORT 0DIP SwitchPORT 1LED ArrayATMEL Microcontroller 89c51

  • Stepper Motor Interfacing*Stepper Motor InterfacingP1.0 to P1.3PORT 1 thruULN 2003 DriverStepperMotor

    ATMEL 89c51 Microcontroller

  • P.C. Serial(RS-232) Interfacing with uC 89c51*Pin 10,11 to MAX232RS232 port of P.C.ATMEL 89c51 Microcontroller

  • Embedded system-Spiral Model*

  • *

  • What is Embedded System?*

  • Microcontroller W/S

    LAB. EXPERIMENTS*

  • OVERVIEW DATA TRANSFERS*Mahdi Hassanpour

    InstructionSOURCE OF DATADESTINATIONOF DATAADDRESSING MODEMOV A,#56HFLASH MEMORYACCUMULATORIMMEDIATEMOV A,56HRAM LOCATION56HACCUMULATORDIRECTMOV A,R1RAM REGISTER R1ACCUMULATORREGISTER MOV A,@ 56HRAM LOCATION WHOSEADDRESS IS STORED AT LOCATION 56HACCUMULATORREGISTER INDIRECT

    Mahdi Hassanpour

  • Prof. Cherrice TraverEE/CS-152: Microprocessors and MicrocontrollersInfinite Loops

    Start: mov C, p3.7 mov p1.6, C sjmp Start

    Microcontroller application programs are almost always infinite loops!

    EE/CS-152: Microprocessors and Microcontrollers

  • Program for Blinking LEDs on PORT 0

    Include 89c51.mcLoop:Mov a,#55hMov p0,aJmp loop

    *

  • LED In Sinking & Sourcing Mode*

  • Lab. Experiment:Alternately Blink LEDs at PORT 1 considering DelayMOV A,#55HMOV P1,ALOOP: MOV R5,#0FFHREPEAT3: MOV R3,#0FFHREPEAT2:Delay LoopDJNZ R3,REPEAT2DJNZ R5,REPEAT3CPL AMOV P1,AJMP LOOP

    *

  • Lab. Experiment: Connect LED Array to PORT 1. Scroll LEDs one by one , in sinking mode MOV A,#80HMOV P1,ALOOP: MOV R5,#0FFHREPEAT3: MOV R3,#0FFHREPEAT2:Delay LoopDJNZ R3,REPEAT2DJNZ R5,REPEAT3RR AMOV P1,AJMP LOOP

    *

  • Experiment 2 : DIP Switch & LED array InterfacingAssumption : DIP Switch interfaced to PORT 0 & LED Array interfaced to PORT 1.

    MOV A,#0FFHAGAIN: MOV A,P0MOV P1,AJMP AGAIN

    *

  • Lab. Experiment : Generation of Square Wave LOOP:SETB P1.0MOV R5,#3FHCALL DELAYCLR P1.0MOV R5,#0FFHCALL DELAYJMP LOOP

    *DELAY:NOPDJNZ R5,AGAINRET

  • ULN 2003 DRIVER : For Driving Stepper Motor*

  • Lab. Experiment : Stepper Motor ControllerC1 EQU P1.0C2 EQU P1.1C3 EQU P1.2C4 EQU P1.3DATA EQU P1

    MOV DATA , #00HMOV A,#88HENDLESS:RR AMOV DATA,ACALL DELAYJMP ENDLESS*

    DELAY:MOV R7,#0FFHAGAIN:NOPNOP

    DJNZ R7,AGAIN

    RET

  • *

  • A simple project using AT89C51*

  • *

  • Bit addressable Area of RAMmov R5,0fahANL A,#08Hmov c,23h.2 ; Data from RAM location ; 23hex bit .2 is transferred to carry

    mov 35.7,c; Data from Carry Flag bit is transferred ; to RAM location 35 decimal bit .7Mov p0.1 , c ; Carry bit is transferred to Port 0 bit .1End( NOTE : RAM Loactions 20 hex to 2f hex are Bit Addressable Area ).*

  • Microcontrollers*

  • 8051 Pin-out*

    RST ResetHIGH for 2 clock cyclesResets registers and program counter (to 0000h) for an orderly startup.

  • Program Status Word (PSW)

  • Pulse width modulatorGenerates pulses with specific high/low timesDuty cycle: % time highSquare wave: 50% duty cycleCommon use: control average voltage to electric deviceSimpler than DC-DC converter or digital-analog converterDC motor speed, dimmer lightsAnother use: encode commands, receiver uses timer to decode

    *

  • Fall 2004Stepper motor controllerStepper motor: rotates fixed number of degrees when given a step signalIn contrast, DC motor just rotates when power applied, coasts to stopRotation achieved by applying specific voltage sequence to coilsController greatly simplifies this

    Sequence

    A

    B

    A

    B

    1

    +

    +

    -

    -

    2

    -

    +

    +

    -

    3

    -

    -

    +

    +

    4

    +

    -

    -

    +

    5

    +

    +

    -

    -

  • Fall 2004Stepper motor with controller (driver)

    void main(void){

    */turn the motor forward */ cw=0; /* set direction */ clk=0; /* pulse clock */ delay(); clk=1;

    /*turn the motor backwards */ cw=1; /* set direction */ clk=0; /* pulse clock */ delay(); clk=1;

    }/* main.c */

    sbit clk=P1^1;sbit cw=P1^0;

    void delay(void){ int i, j; for (i=0; i

  • Fall 2004Stepper motor without controller (driver) A possible way to implement the buffers is located below. The 8051 alone cannot drive the stepper motor, so several transistors were added to increase the current going to the stepper motor. Q1 are MJE3055T NPN transistors and Q3 is an MJE2955T PNP transistor. A is connected to the 8051 microcontroller and B is connected to the stepper motor./*main.c*/sbit notA=P2^0;sbit isA=P2^1;sbit notB=P2^2;sbit isB=P2^3;sbit dir=P2^4;

    void delay(){ int a, b; for(a=0; a

  • 4 register banks

    General user RAM

    Special Function Registers (SFR)*Intel 8051 RAM

  • 8051 SFRsBlue: related to the I/O ports

    Yellow: control the configuration of 8051

    Green: auxiliary SFRs

    *

  • *

  • *

  • Block Diagram of 8051 Microcontroller*

  • Schematic for Microcontroller Board*

  • *

  • 8051 Block Diagram*

  • 8051 Family State Sequence*

  • RAM *

  • *

  • *

  • Using 7 Segment Display*

  • *

  • *

  • *

  • Bit addressable Area of RAMmov R5,0fahANL A,#08Hmov c,23h.2 ; Data from RAM location ; 23hex bit .2 is transferred to carry

    mov 35.7,c; Data from Carry Flag bit is transferred ; to RAM location 35 decimal bit .7Mov p0.1 , c ; Carry bit is transferred to Port 0 bit .1End( NOTE : RAM Loactions 20 hex to 2f hex are Bit Addressable Area ).*

  • Rotating Universal /DC Motor in Clockwise & Anticlockwise using Microcontroller by Sensing position*Micro-Con-troller

    89c51 TANK2 C.O. /

    DPDT RelayDC MotorREEDSensor

  • Assembly Code for Sensing PositionMOV P1,#FFh ; port1 as a input portMOV A,P1LOOP:MOV R1,P1

    IF R1 = # FEh then ; 1111 1110SETB P2.0END IFMOV R2,P1

    IF R2=#FDh then ; 1111 1101CLR P2.0END IF

    JMP LOOP*Micro-Controller89c51

    Pin 1P1.0

    Pin 2P1.1

    P 2.0

    From sensor 1st From sensor 2nd

    ****Program is to read data from P0 and then send data to P1****