⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsn_coordinator.c

📁 内部包含如何用rs232来和rs485通信的示范代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/***        头文件                                                        ***/
/****************************************************************************/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <Utilities.h>
#include <JZ_Api.h>
#include "WSN_Profile.h"
/****************************************************************************/
/***        宏定义                                                        ***/
/****************************************************************************/
#define APP_TICK_PERIOD_ms			 500    // Timing values

#define LED_INIT                  (vAHI_DioSetDirection(0, E_AHI_DIO16_INT))
#define IO16_OFF            	  (vAHI_DioSetOutput(E_AHI_DIO16_INT, 0))
#define IO16_ON             	  (vAHI_DioSetOutput(0, E_AHI_DIO16_INT))

/****************************************************************************/
/***        函数预定义                                                   ***/
/****************************************************************************/
PRIVATE void vInit(void);
PRIVATE void vPutC0(unsigned char c);
PRIVATE void vPutC1(unsigned char c);
PRIVATE void DELAY_TIME(int mSec);
/****************************************************************************/
/***        局部变量                                                     ***/
/****************************************************************************/
PRIVATE bool_t bNwkStarted = FALSE;
PRIVATE bool_t bAppTimerStarted = FALSE;
PRIVATE  uint8   receive[50];
PRIVATE  uint8 cnn,cCharIn;
uint16 u16ADC3_Result;
uint16 u16ADC4_Result;
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
    vInit();
}

/****************************************************************************
 *
 * NAME: AppWarmStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Simply jumps to AppColdStart
 * as, in this instance, application will never warm start.
 ****************************************************************************/
PUBLIC void AppWarmStart(void)
{
    AppColdStart();
}
/****************************************************************************
 * NAME: vInit
 *
 * DESCRIPTION:
 * Initialises Zigbee stack and hardware. Final action is to start BOS, from
 * which there is no return. Subsequent application actions occur in the
 * functions defined above.
 ****************************************************************************/
PRIVATE void vInit(void)
{
    JZS_u32InitSystem(TRUE);             // 初始化Zigbee栈

    LED_INIT;

    vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
                     E_AHI_AP_INT_DISABLE,
                     E_AHI_AP_SAMPLE_8,
                     E_AHI_AP_CLOCKDIV_2MHZ,
                     E_AHI_AP_INTREF);
    while(bAHI_APRegulatorEnabled() == 0);
    vAHI_DacEnable(E_AHI_AP_DAC_1,
                   E_AHI_AP_INPUT_RANGE_2,
                   E_AHI_DAC_RETAIN_ENABLE,
                   0x0400);
    while(bAHI_DacPoll() != 000);
    vAHI_DacEnable(E_AHI_AP_DAC_2,
                   E_AHI_AP_INPUT_RANGE_2,
                   E_AHI_DAC_RETAIN_ENABLE,
                   0x0400);
    while(bAHI_DacPoll() != 000);

    /**********初始化串口0*************************************************/
    vAHI_UartEnable(E_AHI_UART_0);
    vAHI_UartReset(E_AHI_UART_0,TRUE,TRUE);
    vAHI_UartReset(E_AHI_UART_0, FALSE, FALSE);
    vAHI_UartSetClockDivisor(E_AHI_UART_0,E_AHI_UART_RATE_9600);
    vAHI_UartSetControl(E_AHI_UART_0,
                        FALSE,
                        FALSE,
                        E_AHI_UART_WORD_LEN_8,
                        TRUE,
                        FALSE);
   vAHI_UartSetInterrupt(E_AHI_UART_0, FALSE, FALSE, FALSE, TRUE, E_AHI_UART_FIFO_LEVEL_1);
    /**********初始化串口1*************************************************/
    vAHI_UartEnable(E_AHI_UART_1);
    vAHI_UartReset(E_AHI_UART_1,TRUE,TRUE);
    vAHI_UartReset(E_AHI_UART_1, FALSE, FALSE);
    vAHI_UartSetClockDivisor(E_AHI_UART_1,E_AHI_UART_RATE_9600);
    vAHI_UartSetControl(E_AHI_UART_1,
                        FALSE,
                        FALSE,
                        E_AHI_UART_WORD_LEN_8,
                        TRUE,
                        FALSE);
    vAHI_UartSetInterrupt(E_AHI_UART_1, FALSE, FALSE, FALSE, TRUE, E_AHI_UART_FIFO_LEVEL_1);

    /**********初始化timer*************************************************/
    // vAHI_TimerEnable(E_AHI_TIMER_0, 10, FALSE, TRUE, FALSE);
    //vAHI_TimerClockSelect(E_AHI_TIMER_0, FALSE, TRUE);
    //vAHI_TimerStartRepeat(E_AHI_TIMER_0, 160*5, 320*5);

    (void)bBosRun(TRUE);            //启动BOS
}
/****************************************************************************
 * NAME: JZA_vAppEventHandler
 *
 * DESCRIPTION:
 * Called regularly by the task scheduler. This function reads the hardware
 * event queue and processes the events therein. It is important that this
 * function exits after a relatively short time so that the other tasks are
 * not adversely affected.
 ****************************************************************************/
void JZA_vAppEventHandler(void)
{
    uint8 i;
   //设置测试的字节长度-1
    if(cnn>0)
    {
        IO16_OFF;
        //串口0输出
        for(i=0;i<cnn;i++)
        {
            vPutC0(receive[i]);
        }
        DELAY_TIME(5);
        IO16_ON;
        //串口1输出
        for(i=0;i<cnn;i++)
        {
            vPutC1(receive[i]);
        }
        cnn=0;
    }

    if (!bAppTimerStarted)
    {
        if (bNwkStarted)
        {
            bAppTimerStarted = TRUE;
        }
    }
}
/****************************************************************************
 * NAME: JZA_vPeripheralEvent
 *
 * DESCRIPTION:
 * Called when a hardware event causes an interrupt. This function is called
 * from within the interrupt context so should be brief. In this case, the
 * information is placed on a simple FIFO queue to be processed later.
 *
 * PARAMETERS: Name          RW  Usage
 *             u32Device     R   Peripheral generating interrupt
 *             u32ItemBitmap R   Bitmap of interrupt sources within peripheral
 ****************************************************************************/
PUBLIC void JZA_vPeripheralEvent(uint32 u32Device, uint32 u32ItemBitmap)
{
    if (u32Device == E_AHI_DEVICE_UART0)
    {
        if ((u32ItemBitmap & 0x000000FF) == E_AHI_UART_INT_RXDATA)
        {
            cCharIn = ((u32ItemBitmap & 0x0000FF00) >> 8);
            receive[cnn]=cCharIn;
            cnn++;
        }
    }

    if (u32Device == E_AHI_DEVICE_UART1)
    {
        if ((u32ItemBitmap & 0x000000FF) == E_AHI_UART_INT_RXDATA)
        {
            cCharIn = ((u32ItemBitmap & 0x0000FF00) >> 8);
            receive[cnn]=cCharIn;
            cnn++;
        }
    }

    /*if (u32Device == E_AHI_DEVICE_TIMER1)
    {
        if ( bNwkStarted && cnn>0 )
        {
            cnn = 0 ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -