打印
[DemoCode下载]

N76E003 UAR0的应用

[复制链接]
1236|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dongnanxibei|  楼主 | 2017-7-17 20:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: N76E003 UART-0 Mode1 demo code
//***********************************************************************************************************

#include <stdio.h>
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_Define.h"

/******************************************************************************
* FUNCTION_PURPOSE: Serial interrupt, echo received data.
* FUNCTION_INPUTS : P0.7(RXD) serial input
* FUNCTION_OUTPUTS: P0.6(TXD) serial output
* Following setting in Common.c
******************************************************************************/
#if 0
//void InitialUART0_Timer1(UINT32 u32Baudrate)    //T1M = 1, SMOD = 1
//{
//                P06_Quasi_Mode;               
//                P07_Quasi_Mode;
//       
//    SCON = 0x52;     //UART0 Mode1,REN=1,TI=1
//    TMOD |= 0x20;    //Timer1 Mode1
//   
//    set_SMOD;        //UART0 Double Rate Enable
//    set_T1M;
//    clr_BRCK;        //Serial port 0 baud rate clock source = Timer1

//
//#ifdef FOSC_160000
//    TH1 = 256 - (1000000/u32Baudrate+1);               /*16 MHz */
//#endif           
//    set_TR1;
//}
////---------------------------------------------------------------
//void InitialUART0_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator
//{
//                P06_Quasi_Mode;
//                P07_Quasi_Mode;       
//       
//    SCON = 0x52;     //UART0 Mode1,REN=1,TI=1
//    set_SMOD;        //UART0 Double Rate Enable
//    T3CON &= 0xF8;   //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1)
//    set_BRCK;        //UART0 baud rate clock source = Timer3

//#ifdef FOSC_160000
//        RH3    = HIBYTE(65536 - (1000000/u32Baudrate)-1);                  /*16 MHz */
//  RL3    = LOBYTE(65536 - (1000000/u32Baudrate)-1);                        /*16 MHz */
//#endif
//    set_TR3;         //Trigger Timer3
//}
#endif

/*******************************************************************************
* FUNCTION_PURPOSE: Main function
******************************************************************************/
void main (void)
{

#if 0       
    InitialUART0_Timer1(9600);                                                //UART0 Baudrate from Timer1
    while(1)
    Send_Data_To_UART0(0x55);
#else
                InitialUART0_Timer3(115200);                                        //UART0 Baudrate from Timer3
    while(1)
    Send_Data_To_UART0(0x55);
#endif
                       

               
               
}
  


沙发
dongnanxibei|  楼主 | 2017-7-17 20:34 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: N76E003 UART-0 Mode3 demo code
//***********************************************************************************************************

#include <stdio.h>
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Common.h"
#include "Delay.h"
#include "Function_Define.h"

#define BUFFER_SIZE                16

UINT8  UART_BUFFER[BUFFER_SIZE],temp;
UINT16 u16CNT=0,u16CNT1=0;
bit riflag;

/**
* FUNCTION_PURPOSE: serial interrupt, echo received data.
* FUNCTION_INPUTS: P3.0(RXD) serial input
* FUNCTION_OUTPUTS: P3.1(TXD) serial output
*/
void serial_IT(void) interrupt 4
{
    if (RI)
    {                                       /* if reception occur */
        clr_RI;                             /* clear reception flag for next reception */
        UART_BUFFER[u16CNT] = SBUF;
        u16CNT ++;
                                riflag =1;
    }
    if(TI)
    {
        clr_TI;                             /* if emission occur */
    }
}
/************************************************************************************************************
*    Main function
************************************************************************************************************/
void main (void)
{

   
    P06_Quasi_Mode;                                                       //Set UART GPIO are Quasi Mode
                P07_Quasi_Mode;
    InitialUART0_Timer1(115200);            /* 115200 Baud Rate from timer1*/
       
    SCON = 0xD2;                                                                                                                // Special setting the mode 3
   
    set_ES;                                 //enable UART interrupt
    set_EA;                                 //enable global interrupt
    clr_TB8;
    Send_Data_To_UART0(0x53);                                                                //Send "start" ascii code show reset initial status
          Send_Data_To_UART0(0x74);
          Send_Data_To_UART0(0x61);
          Send_Data_To_UART0(0x72);
          Send_Data_To_UART0(0x74);
       
    while(1)
                {
                        if (riflag)
                        {
                                temp = SBUF;                                                                                                //This part send the receive data from RXD to TXD
                                Send_Data_To_UART0(temp);
                                riflag = 0;
                        }
                }
       
}

使用特权

评论回复
板凳
dongnanxibei|  楼主 | 2017-7-17 20:43 | 只看该作者
这个芯片的其他串口用法没说。

使用特权

评论回复
地板
heisexingqisi| | 2017-7-17 21:18 | 只看该作者
好久没用过51了,看看。

使用特权

评论回复
5
chen472015439| | 2017-8-3 12:10 | 只看该作者
这不是公版的例程吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

187

主题

3489

帖子

16

粉丝