• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Micro controller-8051
 

Micro controller-8051

on

  • 11,086 views

Tutorial of 8051

Tutorial of 8051

Statistics

Views

Total Views
11,086
Views on SlideShare
11,086
Embed Views
0

Actions

Likes
2
Downloads
585
Comments
5

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

15 of 5 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Program is to read data from P0 and then send data to P1

Micro controller-8051 Micro controller-8051 Presentation Transcript

  • Microcontroller 8051
  • CONTENTS:
    • Introduction
    • Block Diagram and Pin Description of the 8051
    • Registers
    • Memory mapping in 8051
    • Stack in the 8051
    • I/O Port Programming
    • Timer
    • meeting the computing needs of the task efficiently and cost effectively
      • speed, the amount of ROM and RAM, the number of I/O ports and timers, size, packaging, power consumption
      • easy to upgrade
      • cost per unit
    • availability of software development tools
      • assemblers, 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 :
  • Development process Fall 2004 Embedded Systems Planning of tasks & interactions edit taskcode1.A51 taskcode2.c Assembler C-compiler misc.LIB Linker/Locator Burn in EPROM Download to board Revise ! Debugging ???
  • 8051 Microcontroller Kit Layout
  • General Purpose Microprocessor v/s Microcontroller
  • Block Diagram : 8051
  • Block Diagram CPU On-chip RAM On-chip ROM for program code 4 I/O Ports Timer 0 Serial Port OSC Interrupt Control External interrupts Timer 1 Timer/Counter Bus Control TxD RxD P0 P1 P2 P3 Address/Data Counter Inputs PC Interface Lab. Stepper motor etc. Lab Delay Generation Labs
  • ROMLike Brain OscillatorLike Heart Data flow Like BloodFlow Ports like Hands/Legs Internal Data Bus Prepares the sequence of operations
  • 8051 Block Diagram
  • ROMLike Brain OscillatorLike Heart Data flow Like BloodFlow Ports like Hands/Legs Internal Data Bus Prepares the sequence of operations
  • Signal Pins Figure 8051 pinouts & Functions
  • 8051 Block Diagram
  • Fetch Cycle
  • 8051 Family State Sequence
  • 8051 Architecture: Salient features
    • 8 bit CPU with registers A and B
    • 16 bit Program Counter and data pointer DPTR
    • 8 bit Program Status Word
    • 8 bit Stack Pointer
    • Internal RAM 128 bytes
    • 4 Registers banks, each containing 8 Registers
    • 16 bytes, may be addressed at the bit level
    • 8 bytes of General Purpose memory
    • Internal ROM 4K
    • 32 I/O pins as 4 eight bit ports: P0-P3
    • 2 sixteen bit timer/counters: T0 and T1
    • Full duplex serial data receiver/transmitter: SBUF
    • Control registers: TCON, TMOD, SCON, PCON, IP AND IE
    • 2 external and 3 internal interrupt sources
    • Oscillator and clock circuits.
  • Pin Description of the 8051 
  • 8051 Hardware Connections : Crystal Connection to 8051
    • Using a quartz crystal oscillator ( Frequency 11.0592 MHz)
    • We can observe the frequency on the XTAL2 pin.
    Pin 18 Pin 20 Pin 19 C2 30pF C1 30pF XTAL2 XTAL1 GND
  • Pins of 8051
    • Vcc ( pin 40 ):
      • Vcc provides supply voltage to the chip.
      • The voltage source is +5V.
    • GND ( pin 20 ): ground
    • XTAL1 and XTAL2 ( pins 19,18 )
    • RST ( pin 9 ): reset
      • It is an input pin and is active high ( normally 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
    • / EA ( pin 31 ): external access
      • There 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.
    • /PSEN ( pin 29 ): program store enable
      • This is an output pin and is connected to the OE pin of the ROM.
  • Pins of 8051
    • ALE ( pin 30 ): address latch enable
      • It 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 pins
      • The four ports P0, P1, P2, and P3.
      • Each port uses 8 pins.
      • All I/O pins are bi-directional .
  • Pins of I/O Port
    • The 8051 has four I/O ports
      • Port 0 ( pins 32-39 ): P0 ( P0.0 ~ P0.7 )
      • Port 1 ( pins 1-8 ) : P1 ( P1.0 ~ P1.7 )
      • Port 2 ( pins 21-28 ): P2 ( P2.0 ~ P2.7 )
      • Port 3 ( pins 10-17 ): P3 ( P3.0 ~ P3.7 )
      • Each port has 8 pins.
        • Named P0.X ( X=0,1,...,7 ) , P1.X, P2.X, P3.X
        • Ex : P0.0 is the bit 0 ( LSB ) of P0
        • Ex : P0.7 is the bit 7 ( MSB ) of P0
        • These 8 bits form a byte.
    • Each port can be used as input or output (bi-direction).
  • Power-On RESET Circuit 30 pF 30 pF 8.2 K 10 uF + Vcc 11.0592 MHz EA/VPP X1 X2 RST 31 19 18 9
  • Hardware Structure of I/O Pin
    • Each pin of I/O ports
      • Internal CPU bus : communicate with CPU
      • A D latch store the value of this pin
        • D latch is controlled by “Write to latch”
          • Write to latch = 1 : write data into the D latch
      • 2 Tri-state buffer :
        • TB1: controlled by “Read pin”
          • Read pin = 1 : really read the data present at the pin
        • TB2: controlled by “Read latch”
          • Read latch = 1 : read value from internal latch
      • A transistor M1 gate
        • Gate=0: open
        • Gate=1: close
  • P89V51 RD2 : Electrical Specs.( Threshold Voltages)
  • P89V51RD2 : Timing Specs.
  • A Pin of Port 1 8051 IC  P0.x D Q Clk Q Vcc Load(L1) Read latch Read pin Write to latch Internal CPU bus M1 P1.X pin P1.X TB1 TB2
  • Writing “1” to Output Pin P1.X 8051 IC 2. output pin is Vcc 1. write a 1 to the pin 1 0 output 1 TB1 TB2 D Q Clk Q Vcc Load(L1) Read latch Read pin Write to latch Internal CPU bus M1 P1.X pin P1.X
  • Writing “0” to Output Pin P1.X 8051 IC 2. output pin is ground 1. write a 0 to the pin 0 1 output 0 TB1 TB2 D Q Clk Q Vcc Load(L1) Read latch Read pin Write to latch Internal CPU bus M1 P1.X pin P1.X
  • Reading “High” at Input Pin 8051 IC 2. MOV A,P1 external pin=High
    • write a 1 to the pin MOV P1,#0FFH
    1 0 3. Read pin=1 Read latch=0 Write to latch=1 1 TB1 TB2 D Q Clk Q Vcc Load(L1) Read latch Read pin Write to latch Internal CPU bus M1 P1.X pin P1.X
  • Reading “Low” at Input Pin 8051 IC 2. MOV A,P1 external pin=Low
    • write a 1 to the pin
    • MOV P1,#0FFH
    1 0 3 . Read pin=1 Read latch=0 Write to latch=1 0 TB1 TB2 D Q Clk Q Vcc Load(L1) Read latch Read pin Write to latch Internal CPU bus M1 P1.X pin P1.X
  • You can not Get Logic 1 with Heavy Load and Weak Pull-up
  • Is it too much? - it’s the beginning - LOAD LOADING EFFECT ( SOURCE IS IN PROBLEM
  • A Pin of Port 0 8051 IC  P1.x D Q Clk Q Read latch Read pin Write to latch Internal CPU bus M1 P0.X pin P1.X TB1 TB2
  • Port 0 with Pull-Up Resistors P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 DS5000 8751 8951 Vcc 10 K Port 0
  • Address Lines Bi-Directional Data Lines
  • Instruction: MOV A,# 3CH 74 3C Data 5Ch is in Flash Memory
  • Instruction: MOV A,3CH Data is 7F hex At RAM Address 3C hex - - ACC data will be 7F h E5 3C
  • 85 80 A0 Instruction: MOV p2,p0 Mov address, address 85
  • Port 3 Alternate Functions 
  • 8051 PROG. MEMORY
  • 8051 DATA MEMORY
  • Registers of 8051
    • RAM memory space allocation in the 8051
    7FH 30H 2FH 20H 1FH 17H 10H 0FH 07H 08H 18H 00H Register Bank 0 (Stack) Register Bank 1 Register Bank 2 Register Bank 3 Bit-Addressable RAM Scratch pad RAM
  • Address Modes
    • Bit-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 accumulator
    • RAM 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
    Prof. Cherrice Traver EE/CS-152: Microprocessors and Microcontrollers
  • Bit addressable Area of RAM
    • mov R5,0fah
    • ANL A,#08H
    • mov 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. ; 23H
    • Mov p0.1 , c ; Carry bit is transferred to Port 0 bit .1
    • End
    • ( NOTE : RAM Loactions 20 hex to 2f hex are Bit Addressable Area ).
  • Bit Addressable Memory Prof. Cherrice Traver EE/CS-152: Microprocessors and Microcontrollers 20h – 2Fh (16 locations X 8-bits = 128 bits) 27 26 25 24 23 22 21 20 2F 2E 2D 2C 2B 2A 29 28 Bit addressing: mov C, 1Ah or mov C, 23h.2 7F 78 1A 10 0F 08 07 06 05 04 03 02 01 00
  • Stack in the 8051
    • The 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.
    7FH 30H 2FH 20H 1FH 17H 10H 0FH 07H 08H 18H 00H Register Bank 0 (Stack) Register Bank 1 Register Bank 2 Register Bank 3 Bit-Addressable RAM Scratch pad RAM
  • Stacks Prof. Cherrice Traver EE/CS-152: Microprocessors and Microcontrollers push pop stack stack pointer Go do the stack exercise…..
  • Timers
    • There are TWO general purpose 16 bit timers
    • TIMER MODES:
    • MODE 0
    • MODE 1
    • MODE 2
    • MODE 3
  • TIMER MODE 0
    • Setting 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 1
    • SIMILAR TO MODE 0 EXCEPT tlx IS CONFIGURED AS A FULL 8 BIT COUNTER
  • TIMER MODE 2
    • The 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 3
    • Timer 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 0
    • TR1: 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 0
    • TR0: 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 3 Port 1 Port 2 Port 0 ATMEL 89c51 Microcontroller
  • PCB: 89c51 Microcontroller Card Resistor Array (10K) Micro- controller Crystal 11.0592 MHz Burge Strip Header Capacitors 30 pF Port 3 Port 1 Port 2 Port 0 ATMEL 89c51 Microcontroller
  • PCB: 89c51 Microcontroller Card Resistor Array (10K) Micro- controller Crystal 11.0592 MHz Burge Strip Header Capacitors 30 pF Port 3 Port 1 Port 2 Port 0 ATMEL 89c51 Microcontroller
  • PCB: 89c51 Microcontroller Card Pin 1 of 89c51 Pin 20 Of 89c51 Pin 21 Of 89c51 Pin 40 of 89c51 ATMEL 89c51 Microcontroller
  • Where is Clock Circuitry ? Clock Circuitry section ATMEL 89c51 Microcontroller
  • Clock circuitry components Crystal 11.0592 MHz Two Capacitors 33 pF ATMEL 89c51 Microcontroller
  • LED Array Card : To Port 0 LED Array card to PORT 0 ATMEL 89c51 Microcontroller
  • Interfacing DIP Switch & LED Array PORT 0 DIP Switch PORT 1 LED Array ATMEL Microcontroller 89c51
  • Stepper Motor Interfacing Stepper Motor Interfacing P1.0 to P1.3 PORT 1 thru’ ULN 2003 Driver Stepper Motor ATMEL 89c51 Microcontroller
  • P.C. Serial(RS-232) Interfacing with uC 89c51 Pin 10,11 to MAX232 RS232 port of P.C. ATMEL 89c51 Microcontroller
  • Embedded system-Spiral Model
  • What is Embedded System?
    • Microcontroller W/S
    • LAB. EXPERIMENTS
  • OVERVIEW DATA TRANSFERS Sunday, January 8, 2012 Mahdi Hassanpour Instruction SOURCE OF DATA DESTINATION OF DATA ADDRESSING MODE MOV A,#56H FLASH MEMORY ACCUMULATOR IMMEDIATE MOV A,56H RAM LOCATION 56H ACCUMULATOR DIRECT MOV A,R1 RAM REGISTER R1 ACCUMULATOR REGISTER MOV A,@ 56H RAM LOCATION WHOSE ADDRESS IS STORED AT LOCATION 56H ACCUMULATOR REGISTER INDIRECT
  • Infinite Loops
    • Start: mov C, p3.7
    • mov p1.6, C
    • sjmp Start
    Prof. Cherrice Traver EE/CS-152: Microprocessors and Microcontrollers Microcontroller application programs are almost always infinite loops!
  • Program for Blinking LEDs on PORT 0
    • Include 89c51.mc
    • Loop:
    • Mov a,#55h
    • Mov p0,a
    • Jmp loop
  • LED In Sinking & Sourcing Mode
  • Lab. Experiment: Alternately Blink LEDs at PORT 1 considering Delay
    • MOV A,#55H
    • MOV P1,A
    • LOOP: MOV R5,#0FFH
    • REPEAT3:
    • MOV R3,#0FFH
    • REPEAT2: Delay Loop
    • DJNZ R3,REPEAT2
    • DJNZ R5,REPEAT3
    • CPL A
    • MOV P1,A
    • JMP LOOP
  • Lab. Experiment: Connect LED Array to PORT 1. Scroll LEDs one by one , in sinking mode
    • MOV A,#80H
    • MOV P1,A
    • LOOP: MOV R5,#0FFH
    • REPEAT3:
    • MOV R3,#0FFH
    • REPEAT2: Delay Loop
    • DJNZ R3,REPEAT2
    • DJNZ R5,REPEAT3
    • RR A
    • MOV P1,A
    • JMP LOOP
  • Experiment 2 : DIP Switch & LED array Interfacing
    • Assumption : DIP Switch interfaced to PORT 0 & LED Array interfaced to PORT 1.
    • MOV A,#0FFH
    • AGAIN:
    • MOV A,P0
    • MOV P1,A
    • JMP AGAIN
  • Lab. Experiment : Generation of Square Wave
    • LOOP:
    • SETB P1.0
    • MOV R5,#3FH
    • CALL DELAY
    • CLR P1.0
    • MOV R5,#0FFH
    • CALL DELAY
    • JMP LOOP
    DELAY: NOP DJNZ R5,AGAIN RET
  • ULN 2003 DRIVER : For Driving Stepper Motor
  • Lab. Experiment : Stepper Motor Controller
    • C1 EQU P1.0
    • C2 EQU P1.1
    • C3 EQU P1.2
    • C4 EQU P1.3
    • DATA EQU P1
    • MOV DATA , #00H
    • MOV A,#88H
    • ENDLESS:
    • RR A
    • MOV DATA,A
    • CALL DELAY
    • JMP ENDLESS
    DELAY: MOV R7,#0FFH AGAIN: NOP NOP DJNZ R7,AGAIN RET
  • A simple project using AT89C51
  • Bit addressable Area of RAM
    • mov R5,0fah
    • ANL A,#08H
    • mov 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
    • Mov p0.1 , c ; Carry bit is transferred to Port 0 bit .1
    • End
    • ( NOTE : RAM Loactions 20 hex to 2f hex are Bit Addressable Area ).
  • Microcontrollers
  • 8051 Pin-out
    • RST – Reset
    • HIGH for 2 clock cycles
    • Resets registers and
    • program counter (to 0000h)
    • for an orderly startup.
  • Program Status Word (PSW)
  •  
  • Pulse width modulator
    • Generates pulses with specific high/low times
    • Duty cycle: % time high
      • Square wave: 50% duty cycle
    • Common use: control average voltage to electric device
      • Simpler than DC-DC converter or digital-analog converter
      • DC motor speed, dimmer lights
    • Another use: encode commands, receiver uses timer to decode
    clk pwm_o 25% duty cycle – average pwm_o is 1.25V clk pwm_o 50% duty cycle – average pwm_o is 2.5V.
  • Stepper motor controller
    • Stepper motor: rotates fixed number of degrees when given a “step” signal
      • In contrast, DC motor just rotates when power applied, coasts to stop
    • Rotation achieved by applying specific voltage sequence to coils
    • Controller greatly simplifies this
    Fall 2004 Red A White A’ Yellow B Black B’ MC3479P 1 5 4 3 2 7 8 6 16 15 14 13 12 11 10 9 Vd A’ A GND Bias’/Set Clk O|C Vm B B’ GND Phase A’ CW’/CCW Full’/Half Step
  • Stepper motor with controller (driver) Fall 2004 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<1000; i++) for ( j=0; j<50; j++) i = i + 0; } 2 A’ 3 A 10 7 B 15 B’ 14 MC3479P Stepper Motor Driver 8051 P1.0 P1.1 Stepper Motor CLK CW’/CCW The output pins on the stepper motor driver do not provide enough current to drive the stepper motor. To amplify the current, a buffer is needed. One possible implementation of the buffers is pictured to the left. Q1 is an MJE3055T NPN transistor and Q2 is an MJE2955T PNP transistor. A is connected to the 8051 microcontroller and B is connected to the stepper motor.
  • Stepper motor without controller (driver) Fall 2004 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<5000; a++) for(b=0; b<10000; b++) a=a+0; } void move(int dir, int steps) { int y, z; /* clockwise movement */ if(dir == 1){ for(y=0; y<=steps; y++){ for(z=0; z<=19; z+4){ isA=lookup[z]; isB=lookup[z+1]; notA=lookup[z+2]; notB=lookup[z+3]; delay(); } } } /* counter clockwise movement */ if(dir==0){ for(y=0; y<=step; y++){ for(z=19; z>=0; z - 4){ isA=lookup[z]; isB=lookup[z-1]; notA=lookup[z -2]; notB=lookup[z-3]; delay( ); } } } } void main( ){ int z; int lookup[20] = { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0 }; while(1){ /*move forward, 15 degrees (2 steps) */ move(1, 2); /* move backwards, 7.5 degrees (1step)*/ move(0, 1); } } Stepper Motor 8051 GND/ +V P2.4 P2.3 P2.2 P2.1 P2.0 Q2 +V 1K Q1 1K +V A B 330
    • 4 register banks
    • General user RAM
    • Special Function Registers (SFR)
    Intel 8051 RAM
  • 8051 SFRs
    • Blue: 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 RAM
    • mov R5,0fah
    • ANL A,#08H
    • mov 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
    • Mov p0.1 , c ; Carry bit is transferred to Port 0 bit .1
    • End
    • ( 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 T A N K 2 C.O. / DPDT Relay DC Motor REED Sensor
  • Assembly Code for Sensing Position
    • MOV P1,#FFh ; port1 as a input port
    • MOV A,P1
    • LOOP:
    • MOV R1,P1
    • IF R1 = # FEh then ; 1111 1110
    • SETB P2.0
    • END IF
    • MOV R2,P1
    • IF R2=#FDh then ; 1111 1101
    • CLR P2.0
    • END IF
    • JMP LOOP
    Micro- Controller 89c51 Pin 1 P1.0 Pin 2 P1.1 P 2.0 From sensor 1 st From sensor 2 nd