16V554 的测试代码
- /* SC16C554 */
- #define SC16C554_BASE ( (unsigned char *) 0x50004000 )
- #define SC16C554_PORTA_BASE ( (unsigned char *) 0x50004000 )
- #define SC16C554_PORTB_BASE ( (unsigned char *) 0x50004100 )
- #define SC16C554_PORTC_BASE ( (unsigned char *) 0x50004200 )
- #define SC16C554_PORTD_BASE ( (unsigned char *) 0x50004300 )
- char *SC16C554_RegPtrA = (char *)SC16C554_PORTA_BASE;
- char *SC16C554_RegPtrB = (char *)SC16C554_PORTB_BASE;
- char *SC16C554_RegPtrC = (char *)SC16C554_PORTC_BASE;
- char *SC16C554_RegPtrD = (char *)SC16C554_PORTD_BASE;
- extern void DelayMs(unsigned char Count);
- /************************************************************************/
- #define Port_RHR 0
- #define Port_THR 0
- #define Port_IER 1
- #define Port_ISR 2
- #define Port_FCR 2
- #define Port_LCR 3
- #define Port_MCR 4
- #define Port_LSR 5
- #define Port_MSR 6
- #define Port_SR 7
- #define Port_DLL 0
- #define Port_DLM 1
- /************************************************************************/
- #define BAUD_2400_DLL 0xC0
- #define BAUD_2400_DLM 0x0
- #define BAUD_4800_DLL 0x60
- #define BAUD_4800_DLM 0x0
- #define BAUD_9600_DLL 0x30
- #define BAUD_9600_DLM 0x0
- #define BAUD_19200_DLL 0x18
- #define BAUD_19200_DLM 0x0
- #define BAUD_38400_DLL 0x0C
- #define BAUD_38400_DLM 0x0
- #define BAUD_57600_DLL 0x08
- #define BAUD_57600_DLM 0x0
- #define BAUD_76800_DLL 0x06
- #define BAUD_76800_DLM 0x0
- #define BAUD_115200_DLL 0x04
- #define BAUD_115200_DLM 0x0
- #define BAUD_153600_DLL 0x03
- #define BAUD_153600_DLM 0x0
- #define BAUD_230400_DLL 0x02
- #define BAUD_230400_DLM 0x0
- #define BAUD_460800_DLL 0x01
- #define BAUD_460800_DLM 0x0
- /************************************************************************/
- #define PORTA 0
- #define PORTB 1
- #define PORTC 2
- #define PORTD 3
- /************************************************************************/
- void SC16C554_init(void)
- {
- *(SC16C554_RegPtrA + Port_LCR) = 0x80;
- *(SC16C554_RegPtrA + Port_DLL) = BAUD_115200_DLL;
- *(SC16C554_RegPtrA + Port_DLM) = BAUD_115200_DLM;
- *(SC16C554_RegPtrA + Port_LCR) = 0x03; // N,8,1
- *(SC16C554_RegPtrA + Port_FCR) = 0x00;
- *(SC16C554_RegPtrA + Port_MCR) = 0x08;
- *(SC16C554_RegPtrA + Port_IER) = 0x05;
- *(SC16C554_RegPtrB + Port_LCR) = 0x80;
- *(SC16C554_RegPtrB + Port_DLL) = BAUD_115200_DLL;
- *(SC16C554_RegPtrB + Port_DLM) = BAUD_115200_DLM;
- *(SC16C554_RegPtrB + Port_LCR) = 0x03; // N,8,1
- *(SC16C554_RegPtrB + Port_FCR) = 0x00;
- *(SC16C554_RegPtrB + Port_MCR) = 0x08;
- *(SC16C554_RegPtrB + Port_IER) = 0x05;
- *(SC16C554_RegPtrC + Port_LCR) = 0x80;
- *(SC16C554_RegPtrC + Port_DLL) = BAUD_115200_DLL;
- *(SC16C554_RegPtrC + Port_DLM) = BAUD_115200_DLM;
- *(SC16C554_RegPtrC + Port_LCR) = 0x03; // N,8,1
- *(SC16C554_RegPtrC + Port_FCR) = 0x00;
- *(SC16C554_RegPtrC + Port_MCR) = 0x08;
- *(SC16C554_RegPtrC + Port_IER) = 0x05;
- *(SC16C554_RegPtrD + Port_LCR) = 0x80;
- *(SC16C554_RegPtrD + Port_DLL) = BAUD_115200_DLL;
- *(SC16C554_RegPtrD + Port_DLM) = BAUD_115200_DLM;
- *(SC16C554_RegPtrD + Port_LCR) = 0x03; // N,8,1
- *(SC16C554_RegPtrD + Port_FCR) = 0x00;
- *(SC16C554_RegPtrD + Port_MCR) = 0x08;
- *(SC16C554_RegPtrD + Port_IER) = 0x05;
- }
- /************************************************************************/
- void Reset16C554(void)
- {
- AT91F_PIO_SetOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);
- DelayMs(50);
- AT91F_PIO_ClearOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);
- DelayMs(50);
- }
- /************************************************************************/
- void SC16C554_Send(unsigned char Port,unsigned char *buf,unsigned short len)
- {
- unsigned short i;
- if(Port == PORTA)
- {
- for(i=0;i<len;i++)
- {
- *(SC16C554_RegPtrA + Port_THR) = buf[i];
- }
- }
- if(Port == PORTB)
- {
- for(i=0;i<len;i++)
- {
- *(SC16C554_RegPtrB + Port_THR) = buf[i];
- }
- }
- if(Port == PORTC)
- {
- for(i=0;i<len;i++)
- {
- *(SC16C554_RegPtrC + Port_THR) = buf[i];
- }
- }
- if(Port == PORTD)
- {
- for(i=0;i<len;i++)
- {
- *(SC16C554_RegPtrD + Port_THR) = buf[i];
- }
- }
- }
- /************************************************************************/
- unsigned char SC16C554_Receive(unsigned char Port)
- {
- unsigned char TempChar;
- unsigned char IntStatus;
- if(Port == PORTA)
- {
- TempChar = *(SC16C554_RegPtrA + Port_RHR);
- IntStatus = *(SC16C554_RegPtrA + Port_ISR);
- }
- if(Port == PORTB)
- {
- TempChar = *(SC16C554_RegPtrB + Port_RHR);
- IntStatus = *(SC16C554_RegPtrB + Port_ISR);
- }
- if(Port == PORTC)
- {
- TempChar = *(SC16C554_RegPtrC + Port_RHR);
- IntStatus = *(SC16C554_RegPtrC + Port_ISR);
- }
- if(Port == PORTD)
- {
- TempChar = *(SC16C554_RegPtrD + Port_RHR);
- IntStatus = *(SC16C554_RegPtrD + Port_ISR);
- }
- return TempChar;
- }