[DemoCode下载] N76E003 UAR0的应用

[复制链接]
1461|4
 楼主| dongnanxibei 发表于 2017-7-17 20:34 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 UART-0 Mode1 demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include "N76E003.h"
  17. #include "Common.h"
  18. #include "Delay.h"
  19. #include "SFR_Macro.h"
  20. #include "Function_Define.h"

  21. /******************************************************************************
  22. * FUNCTION_PURPOSE: Serial interrupt, echo received data.
  23. * FUNCTION_INPUTS : P0.7(RXD) serial input
  24. * FUNCTION_OUTPUTS: P0.6(TXD) serial output
  25. * Following setting in Common.c
  26. ******************************************************************************/
  27. #if 0
  28. //void InitialUART0_Timer1(UINT32 u32Baudrate)    //T1M = 1, SMOD = 1
  29. //{
  30. //                P06_Quasi_Mode;               
  31. //                P07_Quasi_Mode;
  32. //       
  33. //    SCON = 0x52;     //UART0 Mode1,REN=1,TI=1
  34. //    TMOD |= 0x20;    //Timer1 Mode1
  35. //   
  36. //    set_SMOD;        //UART0 Double Rate Enable
  37. //    set_T1M;
  38. //    clr_BRCK;        //Serial port 0 baud rate clock source = Timer1

  39. //
  40. //#ifdef FOSC_160000
  41. //    TH1 = 256 - (1000000/u32Baudrate+1);               /*16 MHz */
  42. //#endif           
  43. //    set_TR1;
  44. //}
  45. ////---------------------------------------------------------------
  46. //void InitialUART0_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator
  47. //{
  48. //                P06_Quasi_Mode;
  49. //                P07_Quasi_Mode;       
  50. //       
  51. //    SCON = 0x52;     //UART0 Mode1,REN=1,TI=1
  52. //    set_SMOD;        //UART0 Double Rate Enable
  53. //    T3CON &= 0xF8;   //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1)
  54. //    set_BRCK;        //UART0 baud rate clock source = Timer3

  55. //#ifdef FOSC_160000
  56. //        RH3    = HIBYTE(65536 - (1000000/u32Baudrate)-1);                  /*16 MHz */
  57. //  RL3    = LOBYTE(65536 - (1000000/u32Baudrate)-1);                        /*16 MHz */
  58. //#endif
  59. //    set_TR3;         //Trigger Timer3
  60. //}
  61. #endif

  62. /*******************************************************************************
  63. * FUNCTION_PURPOSE: Main function
  64. ******************************************************************************/
  65. void main (void)
  66. {

  67. #if 0       
  68.     InitialUART0_Timer1(9600);                                                //UART0 Baudrate from Timer1
  69.     while(1)
  70.     Send_Data_To_UART0(0x55);
  71. #else
  72.                 InitialUART0_Timer3(115200);                                        //UART0 Baudrate from Timer3
  73.     while(1)
  74.     Send_Data_To_UART0(0x55);
  75. #endif
  76.                        

  77.                
  78.                
  79. }
  80.   


 楼主| dongnanxibei 发表于 2017-7-17 20:34 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 UART-0 Mode3 demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include "N76E003.h"
  17. #include "SFR_Macro.h"
  18. #include "Common.h"
  19. #include "Delay.h"
  20. #include "Function_Define.h"

  21. #define BUFFER_SIZE                16

  22. UINT8  UART_BUFFER[BUFFER_SIZE],temp;
  23. UINT16 u16CNT=0,u16CNT1=0;
  24. bit riflag;

  25. /**
  26. * FUNCTION_PURPOSE: serial interrupt, echo received data.
  27. * FUNCTION_INPUTS: P3.0(RXD) serial input
  28. * FUNCTION_OUTPUTS: P3.1(TXD) serial output
  29. */
  30. void serial_IT(void) interrupt 4
  31. {
  32.     if (RI)
  33.     {                                       /* if reception occur */
  34.         clr_RI;                             /* clear reception flag for next reception */
  35.         UART_BUFFER[u16CNT] = SBUF;
  36.         u16CNT ++;
  37.                                 riflag =1;
  38.     }
  39.     if(TI)
  40.     {
  41.         clr_TI;                             /* if emission occur */
  42.     }
  43. }
  44. /************************************************************************************************************
  45. *    Main function
  46. ************************************************************************************************************/
  47. void main (void)
  48. {

  49.    
  50.     P06_Quasi_Mode;                                                       //Set UART GPIO are Quasi Mode
  51.                 P07_Quasi_Mode;
  52.     InitialUART0_Timer1(115200);            /* 115200 Baud Rate from timer1*/
  53.        
  54.     SCON = 0xD2;                                                                                                                // Special setting the mode 3
  55.    
  56.     set_ES;                                 //enable UART interrupt
  57.     set_EA;                                 //enable global interrupt
  58.     clr_TB8;
  59.     Send_Data_To_UART0(0x53);                                                                //Send "start" ascii code show reset initial status
  60.           Send_Data_To_UART0(0x74);
  61.           Send_Data_To_UART0(0x61);
  62.           Send_Data_To_UART0(0x72);
  63.           Send_Data_To_UART0(0x74);
  64.        
  65.     while(1)
  66.                 {
  67.                         if (riflag)
  68.                         {
  69.                                 temp = SBUF;                                                                                                //This part send the receive data from RXD to TXD
  70.                                 Send_Data_To_UART0(temp);
  71.                                 riflag = 0;
  72.                         }
  73.                 }
  74.        
  75. }
 楼主| dongnanxibei 发表于 2017-7-17 20:43 | 显示全部楼层
这个芯片的其他串口用法没说。
heisexingqisi 发表于 2017-7-17 21:18 | 显示全部楼层
好久没用过51了,看看。
chen472015439 发表于 2017-8-3 12:10 | 显示全部楼层
这不是公版的例程吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

225

主题

3848

帖子

18

粉丝
快速回复 在线客服 返回列表 返回顶部