Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Timer Mode 1 : • Simple 16-bit counter. • -Timer Mode 2 : • 8-bit auto-reload. • Counter in TL0 or TL1. • Reload value in TH0 or TH1. • Provides a periodic flag or interrupt
Timer Mode 3 • Splits timer 0 into two 8-bit counter/timers. • First counter (TLO) acts like mode 0, without prescaler. • Second counter (TH0): • Counts CPU cycles. • Uses TR1 (timer 1 run bit) as enable. • Uses TF1 (timer 1 overflow bit) as flag. • Uses Timer 1 interrupt.
SM2 • - SM2 : • Mode 0 : Not used. • Mode 1 : 1 = Ignore bytes with no stop bit. • Mode 2,3 : 0 = Set receive interrupt (RI) on all bytes. • : 1 = Set RI on bytes where bit 9 = 1.
REN = Enables receiver. • - TB8 = Ninth bit transmitted (in modes 2 and 3). • - RB8 = Ninth bit received: • Mode 0 : Not used. • Mode 1 : Stop bit. • Mode 2,3 : Ninth data bit. • - TI = Transmit interrupt flag. • - RI = Receive interrupt flag.
MODE 1:TX TI = 0 TI=1 STOP BIT 8 BIT DATA PARALLEL TO SERIAL TX 8 BIT DATA DATA SBUF SERIAL DATA TRANSFER START BIT START STOP
MODE 1:TX TI = 0 TI=1 STOP BIT 8 BIT DATA PARALLEL TO SERIAL TX 8 BIT DATA DATA SBUF SERIAL DATA TRANSFER START BIT START STOP
DATA TX SERIALLY: • Load TMOD Register ;timer1 • Load TH1 or TL1 values ; for Baud rate • Load SCON register; serial mode 0,1,2,3 • SET TR1 ;To start the timer • Character byte is written to SBUF; • Check if TI=1; • CLR TI • Reload the value again.
SAMPLE PROGRAM:TX • MOV TMOD,#20H • MOV TH1,#-3 • MOV SCON,#50H • SETB TR1 • AGAIN:MOV SBUF,#’Y’ • JNB TI ,Here • CLR TI • SJMP AGAIN
MODE 1:RX RI=1 RI=0 START BIT 8 BIT DATA PARALLEL TO SERIAL TX DATA RX 8 BIT DATA SBUF SERIAL DATA RECEIVE STOP BIT START STOP
SAMPLE PROGRAM:RX • Load TMOD Value. • Load TH1 value ;baud rate • Load SCON Register • Set TR1 To start timer. • Clear RI • Check the RI each time. • When RI =1,Load the value from SBUF.
Interrupts Programming • An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Interrupts vs. Polling • A single microcontroller can serve several devices. • There are two ways to do that: • interrupts • polling. • The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler.
Steps in executing an interrupt • Finish current instruction and saves the PC on stack. • Jumps to a fixed location in memory depend on type of interrupt • Starts to execute the interrupt service routine until RETI (return from interrupt) • Upon executing the RETI the microcontroller returns to the place where it was interrupted. Getpop PC from stack
PROGRAM COUNTER • It saves the address next insturction going to be executed.
Example • A 10khz square wave with 50% duty cycle ORG 0;Reset entry poit LJMP MAIN;Jump above interrupt ORG 000BH;Timer 0 interrupt vector T0ISR:CPL P1.0;Toggle port bit RETI;Return from ISR to Main program ORG 0030H;Main Program entry point 0030:MAIN: MOV TMOD,#02H;Timer 0, mode 2 0032:MOV TH0,#-50;50 us delay 0034:SETB TR0;Start timer 0036:MOV IE,#82H;Enable timer 0 interrupt 0038:SJMP $;Do nothing just wait END
Interrupt Sources • Original 8051 has 6 sources of interrupts • Reset • Timer 0 overflow • Timer 1 overflow • External Interrupt 0 • External Interrupt 1 • Serial Port events (buffer full, buffer empty, etc) • Enhanced version has 22 sources • More timers, programmable counter array, ADC, more external interrupts, another serial port (UART)
Interrupt Vectors Each interrupt has a specific place in code memory where program execution (interrupt service routine) begins. External Interrupt 0: 0003h Timer 0 overflow: 000Bh External Interrupt 1: 0013h Timer 1 overflow: 001Bh Serial : 0023h Timer 2 overflow(8052+) 002bh Note: that there are only 8 memory locations between vectors.
ISRs and Main Program in 8051 SJMP main ORG 03H ljmp int0sr ORG 0BH ljmp t0sr ORG 13H ljmp int1sr ORG 1BH ljmp t1sr ORG 23H ljmp serialsr ORG 30H main: … END
Enabling and disabling an interrupt • by bit operation • Recommended in the middle of program SETB EA ;Enable All SETB ET0 ;Enable Timer0 ovrf SETB ET1 ;Enable Timer1 ovrf SETB EX0 ;Enable INT0 SETB EX1 ;Enable INT1 SETB ES ;Enable Serial port • by mov instruction • Recommended in the first of program MOV IE, #10010110B SETB IE.7 SETB IE.1 SETB IE.3 SETB IE.0 SETB IE.2SETB IE.4
Connexion au compte
Connectez-vous pour publier votre contenu sur SlideServe.