of 59/59
8051 직직직직 직직직직직직 직직직직직직직 직직직

8051 직렬포트

  • View
    110

  • Download
    0

Embed Size (px)

DESCRIPTION

8051 직렬포트. 순천향대학교 정보기술공학부 이상정. 개 요. 4 가지의 동작 모드를 갖는 전이중 (full-duplex) 통신방식 의 직렬 포트 송신부와 수신부는 각각 2 중 버퍼 (double buffer) 로 구성 수신의 경우 CPU 가 먼저 수신된 데이터를 읽어가기 전에라도 다음 데이터를 수신하는 동작이 가능 송신 및 수신 데이터 버퍼로는 SBUF 가 사용 송신시에는 CPU 가 송신할 데이터를 SBUF 에 라이트하면 이는 곧바로 직렬 포트의 송신 레지스터에 로드되고 , - PowerPoint PPT Presentation

Text of 8051 직렬포트

  • 8051

    2003-1

    4 (full-duplex) 2 (double buffer) CPU SBUF CPU SBUF , CPU SBUF .

    2003-1

    P.190 8.10

    2003-1

    SCON Serial Port Control Register

    2003-1

    SCON TI RI 1 (empty)1 (full) 1 TB8 RB8 2 3 11 9 1 SM2=0 RB8 SM0SM1

    2003-1

    SCON SM2 1 2 3 9 RB8=1 RB8=0 . 1 SM2=1 .: MOV SCON, #52H ; 01010010BSM0 SM1 = 01 : 1, SM2 = 0REN =1 : receive enableTI = 1 : transmit interrupt flag

    2003-1

    PCON Power Control Register

    2003-1

    PCON (baud rate) 1 SMOD 2 13 SMOD=0 ,SMOD=1 2 .SMOD00 SCON.7 SM0 ,1 SCON.7 FE(Framing Error) .

    2003-1

    0 (half-duplex) I/O TxD , RxD . 8 LSB , 1/12 .

    2003-1

    P.193 8.12

    2003-1

    0 SBUF , 1 LSB(b0) . 1 1 , MSB TI 1 . REN=1 RI 0 RxD TxD 8 SBUF RI 1 .

    2003-1

    8.13 8.14

    2003-1

    2003-1

    1 10 (1 , 8 , 1 ) 1 2 2 1 2 .

    2003-1

    8.16

    2003-1

    1 SBUF SBUF 9 1 , . 9 (1) TI . REN=1 RxD (0) 8 D0D7

    2003-1

    1 9 1 RI=0 RI 1 SCON SM2=0 RI=0 RI . SCON RB8 , 8 SBUF .

    2003-1

    2003-1

    2 311 (1 , 8 , 9 , 1 ) 3 9 SCON TB8 , 9 SCON RB8 .SCON SM2=1 RB8 1 0 .

    2003-1

    2 3 3 2 . 2 1/32 1/64 , 3 1 2 .

    2003-1

    (Baud rate) 1 3 1 2 . 1 1 2(8 auto-reload mode) 2 . 2 16 11.0592MHz .

    2003-1

    (Baud rate)

    2003-1

    (Baud rate)

    2003-1

    2003-1

    2003-1

    1 1 9600 bps 1 () (): echo print : -32 1 MOV SCON, #52H SM0 SM1 = 01 : 1, SM2 = 0 REN =1 : receive enable TI = 1 : transmit interrupt flag,

    2003-1

    11, 2 9600 bps MOV TMOD, #20H; Timer 1, Mode 2MOV TH1, #0FDH; 9600 bpsMOV TL1, #0FDHMOV PCON, #0; disable double baud rateSETB TR1

    (30H) RXD_CH:JNBRI, RXD_CH; receive ready?CLRRIMOV30H, SBUF; receive

    2003-1

    1(30H) TXD_CH: JNB TI, TXD_CH; transmit ready? CLR TI MOV SBUF, 30H; transmit

    2003-1

    1CSEGAT8000H

    ; main programCALL SER_INITCLR CLOOP:CALL GETCHCALL PUTCH ; echo printMOV A, 30HSUBB A, #32 ; conversion from lower to upper characterMOV 30H, ACALL PUTCHJMP LOOP

    2003-1

    1; serial port initializarionSER_INIT:MOV TMOD, #20H; Timer 1, Mode 2MOV TH1, #0FDH; 9600 bps MOV TL1, #0FDHMOV PCON, #0; disable double baud rateMOV SCON, #52H; TI=1, REN=1, Mode 1SETB TR1; start countRET; get character from serial portGETCH: RXD_CH:JNBRI, RXD_CH; receive ready?CLRRIMOV30H, SBUF; receiveRET

    2003-1

    1; put character to serial portPUTCH: TXD_CH:JNB TI, TXD_CH; transmit ready?CLR TIMOV SBUF, 30H; transmitRET

    END

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2 1 9600 bps 1 C () (): echo print : -32

    2003-1

    2#include void serial_init(void){ TMOD = 0x20;// Timer 1, Mode 2 TH1 = TL1 = 0xfd;// 9600 bps PCON = 0x00;// disable double baud rate SCON = 0x52;// TI=1, REN=1, Mode 1 TR1 = 1;// start count}void putch(char ch){ while (!TI) ; SBUF = ch; TI = 0;}

    2003-1

    2char getch(void){ char ch; while (!RI) ; ch = SBUF; RI = 0; return ch;}

    2003-1

    2main(){ char c;

    serial_init();

    while (1) { c = getch(); putch(c); // echo print putch(c-32); }}

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    3 19200 bps Soonchunhyang University Information Technology C

    2003-1

    3#include char buffer[] = "Soonchunhyang University Information Technology\r\n";unsigned char i = 0;void delay(unsigned int k)// delay function { while (k--) ;}void serial_service(void) interrupt 4// 8*n + 3{ SBUF = buffer[i]; delay(50); TI = 0; if (buffer[i++] =='\0') i = 0;}

    2003-1

    3void serial_init(void){ EA = 0; TMOD = 0x20;// Timer 1, Mode 2 TH1 = 0xfd;// 19200 bps PCON = 0x80;// enable double baud rate SCON = 0x52;// TI=1, REN=1, Mode 1 ES = 1; EA = 1; TR1 = 1;// start count}main(){ serial_init(); while (1) ;}

    2003-1

    2003-1

    2003-1

    2003-1

    2003-1

    1 3 2 C -> -> ->