PIC18

PIC18, MPLAB X IDE, XC8, UART, printf

CoyoteUgly 2018. 9. 12. 22:39

PIC18, MPLAB X IDE, XC8, UART, printf


0. 참고 사항


1. HW 연결


2. 소스 설명

full 소스는 아래 github를 통해 확인하세요.



OSC 값이 INTIO67 인 경우에는 1MHz로

HS 인 경우에는 4MHz로 Clock이 설정됨


4MHz, 19200 baudrate


//#pragma config OSC = INTIO67
#pragma config OSC = HS



TXSTA = 0x24;         // CSRC TX9 TXEN SYNC SENDB BRGH TRMT TX9D
                          // 0    0   1    0    0     1    0    0
                          // CSRC: Clock Source Select bit
                          // TX9: 9-bit Transmit Enable bit
                          // TXEN: Transmit Enable bit
                          // SYNC: EUSART Mode Select bit
                          // SENDB: Send Break Character bit
                          // BRGH: High Baud Rate Select bit
                          // TRMT: Transmit Shift Register Status bit
                          // TX9D: 9th bit of Transmit Data
   
RCSTA = 0x90;         // SPEN RX9 SREN CREN ADDEN FERR OERR RX9D
                          // 1    0   0    0    0     0    0    0  
                          // SPEN: Serial Port Enable bit
                          // RX9: 9-bit Receive Enable bit
                          // SREN: Single Receive Enable bit
                          // CREN: Continuous Receive Enable bit
                          // ADDEN: Address Detect Enable bit
                          // FERR: Framing Error bit
                          // OERR: Overrun Error bit
                          // RX9D: 9th bit of Received Data
   
    SPBRG = 12;           // 4MHz, 19200


3. 소스


4. 결과