?? 16c550cfg.h
字號:
#include <absacc.h>
//定義16C550的外部晶體頻率和要求的波特率
#define C550_BAUD 19200 //單位: bps
#define C550_XTAL 1843200 //單位: Hz
//----------------------------------------------------------------------------------------
//變量存儲寄存器類型
#define C550_REG xdata
//----------------------------------------------------------------------------------------
//外部中斷號(0,1),使用INT0或INT1
#define C550_USING_EXTERN_INT_NUMBER 1
//----------------------------------------------------------------------------------------
//接收緩沖區長度(2, 4, 8, 16, 32, 64, 128 )
#define C550_RBUFF_LEN 128
//發送緩沖區長度(2, 4, 8, 16, 32, 64, 128 )
#define C550_TBUFF_LEN 128
//----------------------------------------------------------------------------------------
//寄存器選擇地址的16位地址的基址
#define C550_BASE 0x8000
//寄存器選擇地址對應16位地址的位號,0-15
#define C550_A0 8
//寄存器選擇地址對應16位地址的位號,0-15
#define C550_A1 9
//寄存器選擇地址對應16位地址的位號,0-15
#define C550_A2 10
//----------------------------------------------------------------------------------------
#define FORM_BIT(B7,B6,B5,B4,B3,B2,B1,B0) (((B7)<<7)+((B6)<<6)+((B5)<<5)+((B4)<<4)+((B3)<<3)+((B2)<<2)+((B1)<<1)+(B0))
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |CTS |RTS |Xoff |Sleep |modem |receive |transmit |receive |
// IER | 00 |interrupt|interrupt|interrupt|interrupt|status |line |holding |holding |
// | | | | | |interrupt|status |register |register |
// | | | | | | |interrupt| | |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define C550_VAL_IER FORM_BIT( 0, 0, 0, 0, 0, 0, 1, 1 )
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |RCVR |RCVR |reserved |reserved |DMA |XMIT |RCVR |FIFO |
// FCR | 00 |trigger |trigger | | |mode |FIFO |FIFO |enable |
// | |(MSB) |(MSB) | | |select |reset |reset | |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define C550_VAL_FCR FORM_BIT( 1, 0, 0, 0, 0, 1, 1, 1 )
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |divisor |set break|set |even |parity |stop bits|word |word |
// LCR | 00 |latch | |parity |parity |enable | |length |length |
// | |enable | | | | | |bit 1 |bit 0 |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define C550_VAL_LCR FORM_BIT( 0, 0, 0, 0, 0, 0, 1, 1 )
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |reserved |IR enable|reserved |loop back|_OUT2 |_OUT1 |_RTS |_DTR |
// MCR | 00 | | | | |INT | | | |
// | | | | | |enable | | | |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define C550_VAL_MCR FORM_BIT( 0, 0, 0, 0, 0, 0, 0, 0 )
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |Auto CTS |Auto RTS |Special |Enable |Cout-3 |Cout-2 |Cout-1 |Cout-0 |
// | | | |char. |IER[4-7] |Tx,Rx |Tx,Rx |Tx,Rx |Tx,Rx |
// EFR | 00 | | |sekect |ISR[4,5] |Control |Control |Control |Control |
// | | | | |FCR[4,5] | | | | |
// | | | | |MCR[5-7] | | | | |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define C550_VAL_EFR FORM_BIT( 0, 0, 0, 0, 0, 0, 0, 0 )
#define C550_VAL_DL ( C550_XTAL / C550_BAUD / 16 )
#define C550_VAL_XON1
#define C550_VAL_XON2
#define C550_VAL_XOFF1
#define C550_VAL_XOFF2
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |FIFOs |FIFOs |INT |INT |INT |INT |INT |INT |
// ISR | 01 |enabled |enabled |priority |priority |priority |priority |priority |status |
// | | | |bit 4 |bit 3 |bit 2 |bit 1 |bit 0 | |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// | |FIFO |trans. |trans. |break |framing |parity |overrun |receive |
// LSR | 60 |data |empty |holding |interrupt|error |error |error |data |
// | |error | |empty | | | | |ready |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
// MSR | X0 |DCD |RI |DSR |CTS |_DCD |_RI |_DSR |_CTS |
//----------------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
#define address(A2,A1,A0) ((C550_BASE)+((A2)<<(C550_A2))+((A1)<<(C550_A1))+((A0)<<(C550_A0)))
//接收緩沖器,地址A2-A0 = 000
#define C550_RHR XBYTE[ address( 0, 0, 0 ) ]
//發送緩沖器,地址A2-A0 = 000
#define C550_THR XBYTE[ address( 0, 0, 0 ) ]
//中斷使能寄存器,地址A2-A0 = 001
#define C550_IER XBYTE[ address( 0, 0, 1 ) ]
//中斷狀態寄存器,地址A2-A0 = 010
#define C550_ISR XBYTE[ address( 0, 1, 0 ) ]
//FIFO控制寄存器,地址A2-A0 = 010
#define C550_FCR XBYTE[ address( 0, 1, 0 ) ]
//行控制寄存器,地址A2-A0 = 011
#define C550_LCR XBYTE[ address( 0, 1, 1 ) ]
//MODEM控制寄存器,地址A2-A0 = 100
#define C550_MCR XBYTE[ address( 1, 0, 0 ) ]
//行狀態寄存器,地址A2-A0 = 101
#define C550_LSR XBYTE[ address( 1, 0, 1 ) ]
//MODEM狀態寄存器,地址A2-A0 = 110
#define C550_MSR XBYTE[ address( 1, 1, 0 ) ]
//暫存寄存器,地址A2-A0 = 111
#define C550_SPR XBYTE[ address( 1, 1, 1 ) ]
//分頻寄存器低字節,地址A2-A0 = 000
#define C550_DLL XBYTE[ address( 0, 0, 0 ) ]
//分頻寄存器高字節,地址A2-A0 = 001
#define C550_DLM XBYTE[ address( 0, 0, 1 ) ]
//增強性能寄存器,地址A2-A0 = 010
#define C550_EFR XBYTE[ address( 0, 1, 0 ) ]
//軟流控制 Xon1 符號,地址A2-A0 = 100
#define C550_XON1 XBYTE[ address( 1, 0, 0 ) ]
//軟流控制 Xon2 符號,地址A2-A0 = 101
#define C550_XON2 XBYTE[ address( 1, 0, 1 ) ]
//軟流控制 Xoff1 符號,地址A2-A0 = 110
#define C550_XOFF1 XBYTE[ address( 1, 1, 0 ) ]
//軟流控制 Xoff2 符號,地址A2-A0 = 111
#define C550_XOFF2 XBYTE[ address( 1, 1, 1 ) ]
//----------------------------------------------------------------------------------------
#if C550_RBUFF_LEN==2
#elif C550_RBUFF_LEN==4
#elif C550_RBUFF_LEN==8
#elif C550_RBUFF_LEN==16
#elif C550_RBUFF_LEN==32
#elif C550_RBUFF_LEN==64
#elif C550_RBUFF_LEN==128
#else
#error C550_RBUFF_LEN 定義錯誤!!!
#endif
#if C550_TBUFF_LEN==2
#elif C550_TBUFF_LEN==4
#elif C550_TBUFF_LEN==8
#elif C550_TBUFF_LEN==16
#elif C550_TBUFF_LEN==32
#elif C550_TBUFF_LEN==64
#elif C550_TBUFF_LEN==128
#else
#error C550_TBUFF_LEN 定義錯誤!!!
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -