1 / 24

Programming 8051 SPORT (Assembly Language)

Programming 8051 SPORT (Assembly Language). serial communication. The data is sent one bit at a time. serial communication uses single data line making it much cheaper. serial communication. 2 methods, asynchronous and synchronous

lixue
Télécharger la présentation

Programming 8051 SPORT (Assembly Language)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming8051 SPORT(Assembly Language)

  2. serial communication • The data is sent one bit at a time. • serial communication uses single data line making it much cheaper.

  3. serial communication • 2 methods, asynchronous and synchronous • synchronous method transfers a block of data (characters) at a time • asynchronous method transfers a single byte at a time • Uses special IC chips called UART (universal asynchronous receiver-transmitter) and USART (universal synchronous­asynchronous receiver-transmitter) • 8051 chip has a built-in UART

  4. Simple and Duplex transmission

  5. Simple and Duplex transmission • Half- and full-duplex transmission • simplex (one way) communication allows data to be transmitted in only one direction • duplex(two way) communication allows data to be transmitted in two directions. • duplex transmissions can be half or full duplex • If one way at a time, it is half duplex • If can go both ways at the same time, it is full duplex • full duplex requires two wire conductors for the data lines (in addition to the signal ground)

  6. Asynchronous serial communication and data framing • data coming in 0s and 1s • to make sense of the data sender and receiver agree on a set of rules • Protocol determines • how the data is packed • how many bits/character • when the data begins and ends

  7. Asynchronous serial communication and data framing cont… • Start and stop bits • asynchronous method, each character is placed between start and stop bits • called framing • start bit is always one bit • stop bit can be one or two bits • start bit is always a 0 (low) • stop bit(s) is 1 (high) • LSB is sent out first

  8. Framing ASCII “A” When there is no data transfer the signal is highTransmission begins with a start (low) bitLSB firstFinally 1 stop bit (high)Data transfer rate (baud rate) is stated in bps

  9. Baud rate • Data transfer rate • rate of data transfer is stated in bps (bits per second) • widely used terminology for bps is baud rate • baud and bps rates are not necessarily equal • The baud rate is the number of times per second a serial communication signal changes states; a state being either a voltage level, a frequency, or a frequency phase angle.

  10. RS232 Standard • This standard is used in PCs • Logic 1 : -3 to -25 volt • Logic 0 : 3 to 25 volt • To Connect TXD to RXD and RXD to TXD from pc to 8051 you must use max232 to convert signal from TTL level to RS232 level • The baud rate of the 8051 must matched the baud rate of the pc • PC standard baud rate (see hyper terminal configuration) • 2400-4800-9600-14400-19200-28800-33600-57600

  11. 8051 Serial Port • 8051 has an internal UART • P3.0 (pin 11) is assigned to TxD • P3.1 (pin 10) is assigned to Rxd • Baud rate is set by Timer1 • these pins are TTL compatible • require a line driver to make them RS232 compatible • driver is the MAX232 chip • SBUF : Serial Buffer Register • There are physically two SBUF registers having same address i.e 99 H. • Data moved to SBUF is Transmitted serially • Serial data Rx-ed is stored by CPU in SBUF

  12. SM0 SM1 SM2 REN TB8 RB8 TI RI Serial control (SCON) Register 7 6 5 4 3 2 1 0 SM2: used for multi processor communication (Make it 0) REN: receive enable (by software enable/disable) TB8: Not widely used RB8: Not widely used TI: transmit interrupt flag set by HW after send , clear by SW RI: receive interrupt flag set by HW after received ,clear by SW SM0 SM1 MODE operation transmit rate 0 0 0 shift register fixed (xtal/12) 0 1 1 8 bit UART variable (timer1) 1 0 2 9 bit UART fixed (xtal/32 or xtal/64) 1 1 3 9 bit UART variable (timer1) SM0: mode specifier SM1: mode specifier

  13. Mode of operation • Mode 1 • Ten bits are transmitted (through TxD) or received (through RxD) (A start bit (0), 8 data bits (LSB first), and a stop bit (1) ) • On receive, the stop bit goes into RB8 in SCON • the baud rate is determined by the Timer 1 overflow rate (not by TF1). • Timer1 clock is (1/32) machine cycle (MC=1/12 XTAL) To timer1 to set baudrate

  14. Finding timer1 registers values 11.0592MHz Xtal frequency allows the 8051 system to communicate with the PC without any error. Machine cycle frequency = 11.0592 MHz/ 12 = 921.6 kHz Timer1 clock = 921.6 kHz / 32 = 28,800 Hz Initial value in TH1 = 256 – (Timer1 clock / Required baudrate) Example: For 9600 baud rate TH1 = 256 – ( 28800/9600) = 256 – 3 = 253 = FDh or -3 For 2400 baud rate TH1 = 256 – ( 28800/2400) = 256 – 12 = 253 = F4h or -12

  15. Doubling Baud Rate • Ways of Increasing the baud rate • increase the crystal frequency • set SMOD bit in the PCON register (baud rate will doubled) PCON Register (SFR address 87) How to set SMOD Mov a, pcon Setb acc.7 Mov pcon, a

  16. Doubling baud ratecont...

  17. Programming the 8051 to transfer data serially • Load TMOD with value 20h. Timer1 mode 2 ( 8bit auto reload ) • Load calculated initial value into TH1 register • Write 40h into SCON (mode 1, REN =0) • Start timer by SETB TR1 • Clear TI by CLR TI • Write data to be transmitted into SBUF • Keep monitoring TI using the instruction JNB TI, xx TI is set while transmitting the Stop bit • Go to step 5 to transfer the next byte

  18. Program for sending data( in mode 1 ) Transfer letter ‘A’ serially at 9600 baudrate org 0 ljmp main org 030h main: MOV TMOD,#20H ;TIMER 1 MODE 2 MOV TH1,#-3 ;9600 BAUD MOV TL1,#-3 ;9600 BAUD MOV SCON,#40H ;mode 1, REN = 0 SETB TR1 ;start timer1 again: CLR TI ; Clear TI to transfer the next ; character MOV SBUF, #”‘A”;SBUF = 41H • wait: JNB TI, wait ; wait for the last bit • SJMP again ; keep sending A • end

  19. Programming the 8051 to receive data serially • Load TMOD with value 20h. Timer1 mode 2 ( 8bit auto reload ) • Load calculated initial value into TH1 register • Write 50h into SCON (mode 1, REN = 1) • Start timer by SETB TR1 • Keep monitoring RI using the instruction JNB RI, xx • RI is set while receiving the Stop bit • Save received data • Clear RI get ready to receive next byte • Go to step 5 to receive next byte

  20. Program for receiving data( in mode 1 ) Receive serial data with 9600 baud rate, 1 start bit, 1 stop bit and 8 data bit and write it into port 1 org 0 ljmpmain org 030h main: MOV TMOD,#20H ;Timer1 mode 2 MOV TH1,#-3 ;9600 baud rate MOV SCON,#50H ;mode 1 & Rx Enable SETB TR1 ;start timer1 • WAIT: JNB RI, WAIT ;wait for char to come in • MOV A,SBUF ; save incoming byte in A • MOV P1, A ; send to port 1 • CLR RI ; get ready to receive next byte • SJMP WAIT ; keep getting data • end

  21. Thank you

More Related