SCON

SCON is an 8-bit register used to program the start bit, stop bit, and data bits of data framing, among other things

SCON

SM0 SM1 Mode
0 0 Serial mode 0
0 1 Serial mode 1, 8-bit data, 1 stop bit, 1 start bit
1 0 Serial mode 2
1 1 Serial mode 3

Transmitting, TI(transfer interrupt) is raised when the last bit of the framed data, the stop bit, is transferred, indicating that the SBUF register is ready to transfer the next byte

  1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2(8-bit auto-reload) to set baud rate
  2. The TH1 is loaded with one of the values to set baud rate for serial data transfer
  3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data is framed with start and stop bits
  4. TR1 is set to 1 to start timer 1
  5. TI is cleared by CLR TI instruction
  6. The character byte to be transfered serially is written into SBUF register
  7. The TI flag bit is monitored with the used of instruction JNB TI, xx to see if the character has been transferred completely
  8. To tranfer the next byte, go to step 5.
        MOV TMOD,#20H     ;timer 1,mode 2(auto reload)
        MOV TH1,#-6       ;4800 baud rate
        MOV SCON,#50H     ;8-bit, 1 stop, REN enabled
        SETB TR1          ;start timer 1
AGAIN:  MOV SBUF,#”A”     ;letter “A” to transfer
HERE:   JNB TI,HERE       ;wait for the last bit
        CLR TI            ;clear TI for next char
        SJMP AGAIN        ;keep sending A

Receiving, RI(received interrupt) is raised when the entire frame of data, including the stop bit, is received

  1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate
  2. TH1 is loaded to set baud rate
  3. The SCON register is loaded with the value 50H indicating serial mode 1, where an 8-bit data is framed with start and stop bits
  4. TR1 is set to 1 to start timer 1
  5. RI is cleared by CLR RI instruction
  6. The RI flag bit is monitored with the use of instruction JNB RI, xx to see if an entire character has been received yet
  7. When RI is raised, SBUF has the byte, its contents are moved into a safe place
  8. To receive the next character, go to step 5
        MOV TMOD,#20H         ;timer 1,mode 2(auto reload)
        MOV TH1,#-6           ;4800 baud rate
        MOV SCON,#50H         ;8-bit, 1 stop, REN enabled
        SETB TR1              ;start timer 1
HERE:   JNB RI,HERE           ;wait for char to come in
        MOV A,SBUF            ;saving incoming byte in A
        MOV P1,A              ;send to port 1
        CLR RI                ;get ready to receive next
                              ;byte
        SJMP HERE             ;keep getting data

Page Source