Embedded Systems UNIT 3. Pin Details of 8051 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: The positive voltage.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
Chapter Microcontroller Objectives  Understand the 8051 Architecture  Use SFR in C  Use I/O ports in C.
The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
8051 Core Specification.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
Chapter 6 Interrupts (I. Scott Mackenzie).
Architecture of the 8051 INTERNAL DATA BUS Oscillator & Timing Programmable I/O (32 Pins) 80C51 CPU 64K byte Expansion Control Serial I/O 4K Program Memory.
Microcontroller 8051.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
The 8051 Microcontroller architecture
Microcontroller 8051.
UNIT V INTERFACING MICROCONTROLLER
The 8051 Microcontroller and Embedded Systems
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Lecture Set 9 MCS-51 Serial Port.
Serial Communication Lec note 9.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
Example. SBUF Register SCON Register(1) SCON Register(2)
MCS51 - lecture 4. Lecture 3 1/27 Serial ports MCS51 Standard SIO Some extensions and modifications.
8051 Timer/Counter Lec note 7.
8051 Micro controller. Architecture of 8051 Features of 8051.
Microcontrollers Class : 4th Semister E&C and EEE Subject Code: 06ES42
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Jump, Loop, and Call Instructions
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Chapter Microcontroller
Timer Programming in Assembly and C Prepared By:
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Serial I/O Port.
8051 Microcontroller Thanks to Prof. P.Suresh, RCET.
Source: Serial Port Source:
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timer Source: under
SERIAL PORT PROGRAMMING
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
* * * * * * * 8051 Interrupts Programming.
EMT 348: Microcontroller Timer/counter
Source: Serial Port Source:
8051 Timers Prof. Rajiv R Bhandari.
Interrupt.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
Timer.
The 8051 Microcontroller (8 bit )
Timer Source: under
Interrupt Source: under
Interrupt.
UNIT-VIII 8051 Microcontroller Architecture Register set of 8051
JANAKIRAMAN E G S PILLAY ARTS AND SCIENCE COLLAGE NAGAPATTINAM DEPARTMENT OF PHYSICS.
Interrupt Source: under
INTRODUCTION TO 8051, A 8-BIT MICROCONTROLLER
8051 Micro Controller.
The 8051 Microcontroller (8 bit )
Source: Serial Port Source:
Timer Source: under
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
Source: Serial Port Source:
Presentation transcript:

Embedded Systems UNIT 3

Pin Details of 8051 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: The positive voltage on this pin resets the microcontroller. It should be high for 24 osc periods.

Reset response

PD.. Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides, all of them have alternative functions: Pin 10: RXD Serial communication input. Pin 11: TXD Serial communication output.

PD.. Pin 12: INT0(low) Interrupt 0 input. Pin 13: INT1(low) Interrupt 1 input. Pin 14: T0 Counter 0 clock input. Pin 15: T1 Counter 1 clock input. Pin 16: WR(low) Write to external (additional) RAM. Pin 17: RD(low) Read from external RAM.

PD.. Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Pin 20: GND Ground.

PD.. Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port.

PD.. Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every time the microcontroller reads a byte from memory.

PD.. Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both data and address transmission.

PD.. Pin 31: EA(low) By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. By applying logic one to the EA pin, the microcontroller will use both memories, first internal then external (if exists).

PD.. Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0). Pin 40: VCC +5V power supply.

Port 0

P0 is open drain To use the pins of P0, each pin must be connected externally to a 10k –ohm pull up resistor.

Port 2

Port 1

Internal RAM –Part 1

Internal RamPart 2

Program Status Word (PSW) Register

Timers/Counters The 8051 microcontroller has 2 timers/counters called T0 and T1 Besides, they can be used for generating clock pulses to be used in serial communication, so called Baud Rate. T0 consists of two registers – TH0 and TL0

TMOD Register (Timer Mode)

GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3): – 1 - Timer 1 operates only if the INT1 bit is set. – 0 - Timer 1 operates regardless of the logic state of the INT1 bit. C/T1 selects pulses to be counted up by the timer/counter 1: – 1 - Timer counts pulses brought to the T1 pin (P3.5). – 0 - Timer counts pulses from internal oscillator. T1M1,T1M0 These two bits select the operational mode of the Timer 1

Timer Control (TCON) Register

TF1 bit is automatically set on the Timer 1 overflow. TR1 bit enables the Timer 1. – 1 - Timer 1 is enabled. – 0 - Timer 1 is disabled. TF0 bit is automatically set on the Timer 0 overflow. TR0 bit enables the timer 0. – 1 - Timer 0 is enabled. – 0 - Timer 0 is disabled.

M1M0ModeDescription bit timer bit timer 1028-bit auto-reload 113Split mode Mode selection

Mode 0 org 00h mov sp,#00h mov tmod,#01h mov tcon,#00h mov th1,#0feh mov tl1,#00h setb tr1 here: jnb tf1,here clr tr1 clr tf1 sjmp $ end

Timer mode1

Mode 1 org 00h mov sp,#00h mov tmod,#10h mov tcon,#00h mov th1,#0ffh mov tl1,#0fah setb tr1 here: jnb tf1,here clr tr1 clr tf1 sjmp $ end

Mode 2 org 00h mov sp,#00h mov tmod,#20h mov tcon,#00h mov th1,#0f0h mov tl1,#0f0h again: setb tr1 here: jnb tf1,here clr tr1 clr tf1 sjmp again end

UART (Universal Asynchronous Receiver and Transmitter) full-duplex port simply select serial port mode and baud rate microcontroller takes care of not making any error during data transmission SBUF & SCON are belongs to UART

SCON register SM0 - Serial port mode bit 0 is used for serial port mode selection. SM1 - Serial port mode bit 1. SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit. When set, it enables multiprocessor communication in mode 2 and 3, and eventually mode 1. It should be cleared in mode 0.

REN - Reception Enable bit enables serial reception when set. When cleared, serial reception is disabled. TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of transmiting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit. RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.

TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent. It's a signal to the processor that the line is available for a new byte transmite. It must be cleared from within the software. RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte is received and should be read quickly prior to being replaced by a new data. This bit is also cleared from within the software

SM0SM1ModeDescriptionBaud Rate 0008-bit Shift Register1/12 the quartz frequency 0118-bit UARTDetermined by the timer bit UART1/32 the quartz frequency (1/64 the quartz frequency) 1139-bit UARTDetermined by the timer 1

MODE 0

When all 8 bits have been sent, the TI bit of the SCON register is automatically set Data receive through the RXD pin starts upon the two following conditions are met: bit REN=1 and RI=0

Program to transmit and receive CLR TI ;Be sure the bit is initially clear MOV SBUF,#A ;Send the letter A to the serial port JNB TI,$ ;Pause until the TI bit is set JNB RI,$ ;Wait for the 8051 to set the RI flag MOV A,SBUF ;Read the character from the serial port

MODE 1 In mode 1, 10 bits are transmitted through the TXD pin or received through the RXD pin in the following manner: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1). The START bit is only used to initiate data receive, while the STOP bit is automatically written to the RB8 bit of the SCON register.

Data transmit is initiated by writing data to the SBUF register. End of data transmission is indicated by setting the TI bit of the SCON register The START bit (logic zero (0)) on the RXD pin initiates data receive. The following two conditions must be met: bit REN=1 and bit RI=0. Both of them are stored in the SCON register. The RI bit is automatically set upon data reception is complete.

Let suppose we want to calculate the value to be loaded in TH1 for the baud rate of 9600 bauds. Solution: TH1 = 256 – ((Crystal / 384) / Baud) TH1 = 256 – (( / 384) / 9600 ) TH1 = 256 – ((28,800) / 9600) TH1 = 256 – 3 = 253 TH1= FD (Hex Value)

CLR SM0 SETB SM1 ;clear SM0 and set SM1 to put the serial port in mode 1 MOV TMOD, #20H ;put timer 1 in mode 2 interval timing MOV TH1, #230 ;put the reload value in TH1 - this results in a baud rate of 1200 SETB TR1 ;start timer 1 MOV SBUF, A ;send data in the accumulator down the serial line

Interrupts 8051 can recognize 5 different events that can interrupt regular program execution – External interrupt INT0 – Timer 0 interrupt – External Interrupt INT1 – Timer 1 interrupt – Serial Communication Interrupt

EA - global interrupt enable/disable: – 0 - disables all interrupt requests. – 1 - enables all individual interrupt requests. ES - enables or disables serial interrupt: – 0 - UART system cannot generate an interrupt. – 1 - UART system enables an interrupt. ET1 - bit enables or disables Timer 1 interrupt: – 0 - Timer 1 cannot generate an interrupt. – 1 - Timer 1 enables an interrupt. EX1 - bit enables or disables external 1 interrupt: – 0 - change of the pin INT0 logic state cannot generate an interrupt. – 1 - enables an external interrupt on the pin INT0 state change. ET0 - bit enables or disables timer 0 interrupt: – 0 - Timer 0 cannot generate an interrupt. – 1 - enables timer 0 interrupt. EX0 - bit enables or disables external 0 interrupt: – 0 - change of the INT1 pin logic state cannot generate an interrupt. 1 - enables an external interrupt on the pin INT1 state change.

Interrupt SourceVector (address) IE03 h IE1 TF0 13h B h TF11B h RI, TI23 h All addresses are in hexadecimal format Vector Address

pulse train of 10KHz on port 1 pin 0 MOV TMOD, #02H ;initialize timer 0 as 8-bit auto-reload timer MOV TH0, #0CEH ;set timer 0 high-byte to produce 50us delay (assuming system clock frequency of 12MHz) SETB TR0 ;start timer 0 waitForOverflow: JNB TF0, waitForOverflow ;if timer 0 overflow bit is not set, repeat this instruction CLR TF0 ;reset timer 0 overflow bit CPL P1.0 ;invert (complement) port 1 pin 0 JMP waitForOverflow

With Interrupt ORG 0 ; reset vector JMP main ; jump above interrupt vectors ORG 000BH ; timer 0 interrupt vector CPL P1.0 ; invert port 1 pin 0 RETI ; return from interrupt ORG 0030H ; main program entry point main: MOV TMOD, #02H ; timer 0 in 8-bit auto-reload timer mode MOV TH0, 0CEH ; put 206 decimal into TH0 SETB TR0 ; start timer 0 SETB EA ; global interrupt enable SETB ET0 ; enable timer 0 interrupt JMP $ ; do nothing but wait for interrupt