zoukankan      html  css  js  c++  java
  • 16V554 的测试代码

    1.    
    2. /* SC16C554 */   
    3. #define SC16C554_BASE           ( (unsigned char *) 0x50004000 )   
    4. #define SC16C554_PORTA_BASE     ( (unsigned char *) 0x50004000 )   
    5. #define SC16C554_PORTB_BASE     ( (unsigned char *) 0x50004100 )   
    6. #define SC16C554_PORTC_BASE     ( (unsigned char *) 0x50004200 )   
    7. #define SC16C554_PORTD_BASE     ( (unsigned char *) 0x50004300 )   
    8. char *SC16C554_RegPtrA = (char *)SC16C554_PORTA_BASE;   
    9. char *SC16C554_RegPtrB = (char *)SC16C554_PORTB_BASE;   
    10. char *SC16C554_RegPtrC = (char *)SC16C554_PORTC_BASE;   
    11. char *SC16C554_RegPtrD = (char *)SC16C554_PORTD_BASE;   
    12.    
    13. extern void DelayMs(unsigned char Count);   
    14. /************************************************************************/   
    15. #define Port_RHR                0   
    16. #define Port_THR                0   
    17.    
    18. #define Port_IER                1   
    19. #define Port_ISR                2   
    20. #define Port_FCR                2   
    21. #define Port_LCR                3   
    22. #define Port_MCR                4   
    23. #define Port_LSR                5   
    24. #define Port_MSR                6   
    25. #define Port_SR             7   
    26.    
    27. #define Port_DLL                0   
    28. #define Port_DLM                1   
    29. /************************************************************************/   
    30. #define BAUD_2400_DLL               0xC0   
    31. #define BAUD_2400_DLM               0x0   
    32.    
    33. #define BAUD_4800_DLL               0x60   
    34. #define BAUD_4800_DLM               0x0   
    35.    
    36. #define BAUD_9600_DLL               0x30   
    37. #define BAUD_9600_DLM               0x0   
    38.    
    39. #define BAUD_19200_DLL              0x18   
    40. #define BAUD_19200_DLM              0x0   
    41.    
    42. #define BAUD_38400_DLL              0x0C   
    43. #define BAUD_38400_DLM              0x0   
    44.    
    45. #define BAUD_57600_DLL              0x08   
    46. #define BAUD_57600_DLM              0x0   
    47.    
    48. #define BAUD_76800_DLL              0x06   
    49. #define BAUD_76800_DLM              0x0   
    50.    
    51. #define BAUD_115200_DLL             0x04   
    52. #define BAUD_115200_DLM             0x0   
    53.    
    54. #define BAUD_153600_DLL             0x03   
    55. #define BAUD_153600_DLM             0x0   
    56.    
    57. #define BAUD_230400_DLL             0x02   
    58. #define BAUD_230400_DLM             0x0   
    59.    
    60. #define BAUD_460800_DLL             0x01   
    61. #define BAUD_460800_DLM             0x0   
    62. /************************************************************************/   
    63. #define PORTA       0   
    64. #define PORTB       1   
    65. #define PORTC       2   
    66. #define PORTD       3   
    67. /************************************************************************/   
    68. void SC16C554_init(void)   
    69. {   
    70.        
    71.     *(SC16C554_RegPtrA + Port_LCR) = 0x80;   
    72.     *(SC16C554_RegPtrA + Port_DLL) = BAUD_115200_DLL;   
    73.     *(SC16C554_RegPtrA + Port_DLM) = BAUD_115200_DLM;   
    74.     *(SC16C554_RegPtrA + Port_LCR) = 0x03;   // N,8,1   
    75.     *(SC16C554_RegPtrA + Port_FCR) = 0x00;   
    76.     *(SC16C554_RegPtrA + Port_MCR) = 0x08;   
    77.     *(SC16C554_RegPtrA + Port_IER) = 0x05;   
    78.        
    79.        
    80.     *(SC16C554_RegPtrB + Port_LCR) = 0x80;   
    81.     *(SC16C554_RegPtrB + Port_DLL) = BAUD_115200_DLL;   
    82.     *(SC16C554_RegPtrB + Port_DLM) = BAUD_115200_DLM;   
    83.     *(SC16C554_RegPtrB + Port_LCR) = 0x03;   // N,8,1   
    84.     *(SC16C554_RegPtrB + Port_FCR) = 0x00;   
    85.     *(SC16C554_RegPtrB + Port_MCR) = 0x08;   
    86.     *(SC16C554_RegPtrB + Port_IER) = 0x05;   
    87.        
    88.     *(SC16C554_RegPtrC + Port_LCR) = 0x80;   
    89.     *(SC16C554_RegPtrC + Port_DLL) = BAUD_115200_DLL;   
    90.     *(SC16C554_RegPtrC + Port_DLM) = BAUD_115200_DLM;   
    91.     *(SC16C554_RegPtrC + Port_LCR) = 0x03;   // N,8,1   
    92.     *(SC16C554_RegPtrC + Port_FCR) = 0x00;   
    93.     *(SC16C554_RegPtrC + Port_MCR) = 0x08;   
    94.     *(SC16C554_RegPtrC + Port_IER) = 0x05;   
    95.        
    96.     *(SC16C554_RegPtrD + Port_LCR) = 0x80;   
    97.     *(SC16C554_RegPtrD + Port_DLL) = BAUD_115200_DLL;   
    98.     *(SC16C554_RegPtrD + Port_DLM) = BAUD_115200_DLM;   
    99.     *(SC16C554_RegPtrD + Port_LCR) = 0x03;   // N,8,1   
    100.     *(SC16C554_RegPtrD + Port_FCR) = 0x00;   
    101.     *(SC16C554_RegPtrD + Port_MCR) = 0x08;   
    102.     *(SC16C554_RegPtrD + Port_IER) = 0x05;   
    103.        
    104. }   
    105. /************************************************************************/   
    106. void Reset16C554(void)   
    107. {   
    108.     AT91F_PIO_SetOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);   
    109.     DelayMs(50);   
    110.     AT91F_PIO_ClearOutput(AT91C_BASE_PIOD, AT91C_PIO_PD8);   
    111.     DelayMs(50);   
    112. }   
    113. /************************************************************************/   
    114. void SC16C554_Send(unsigned char Port,unsigned char *buf,unsigned short len)   
    115. {   
    116.     unsigned short i;   
    117.     if(Port == PORTA)   
    118.     {   
    119.         for(i=0;i<len;i++)   
    120.         {   
    121.             *(SC16C554_RegPtrA + Port_THR) = buf[i];           
    122.         }   
    123.     }   
    124.     if(Port == PORTB)   
    125.     {   
    126.         for(i=0;i<len;i++)   
    127.         {   
    128.             *(SC16C554_RegPtrB + Port_THR) = buf[i];           
    129.         }   
    130.     }   
    131.     if(Port == PORTC)   
    132.     {   
    133.         for(i=0;i<len;i++)   
    134.         {   
    135.             *(SC16C554_RegPtrC + Port_THR) = buf[i];           
    136.         }   
    137.     }   
    138.     if(Port == PORTD)   
    139.     {   
    140.         for(i=0;i<len;i++)   
    141.         {   
    142.             *(SC16C554_RegPtrD + Port_THR) = buf[i];           
    143.         }   
    144.     }   
    145. }   
    146. /************************************************************************/   
    147. unsigned char SC16C554_Receive(unsigned char Port)   
    148. {   
    149.     unsigned char TempChar;   
    150.     unsigned char IntStatus;   
    151.        
    152.     if(Port == PORTA)   
    153.     {   
    154.         TempChar = *(SC16C554_RegPtrA + Port_RHR);   
    155.         IntStatus = *(SC16C554_RegPtrA + Port_ISR);   
    156.     }   
    157.        
    158.     if(Port == PORTB)   
    159.     {   
    160.         TempChar = *(SC16C554_RegPtrB + Port_RHR);   
    161.         IntStatus = *(SC16C554_RegPtrB + Port_ISR);   
    162.     }   
    163.        
    164.     if(Port == PORTC)   
    165.     {   
    166.         TempChar = *(SC16C554_RegPtrC + Port_RHR);   
    167.         IntStatus = *(SC16C554_RegPtrC + Port_ISR);   
    168.     }   
    169.        
    170.     if(Port == PORTD)   
    171.     {   
    172.         TempChar = *(SC16C554_RegPtrD + Port_RHR);   
    173.         IntStatus = *(SC16C554_RegPtrD + Port_ISR);   
    174.     }   
    175.     return TempChar;   
    176. }  
  • 相关阅读:
    Centos7下rc.local文件开机不执行…
    Centos7添加密码安全策略
    Java8 时间日期类操作
    XML配置spring session jdbc实现session共享
    Spring Boot 2.x以后static下面的静态资源被拦截
    外观模式
    组合设计模式
    Java线程池源码解析
    观察者模式
    Java使用POI解析Excel表格
  • 原文地址:https://www.cnblogs.com/zym0805/p/4957658.html
Copyright © 2011-2022 走看看