7.5.2.4 プログラムリスト(SERIALTEST01_User.c)

修正箇所(自動生成ファイルに記述追加)は、以下の青色の箇所です。
#include "C:\\WIZ_C\\Ver12\\Projects\\SERIALTEST01\\SERIALTEST01_Auto.h"
#include <Strings.h>
#include <Delays.h>

#__config 0x3f50

unsigned char Receive_str[32];
int    StrCount;
bit    CR_exist, LF_exist;
bit    SW1_work, SW2_work, SW3_work, SW4_work;

void TxStr(char *Transmit_str);
void CmdProc();


//
// This file includes all user definable routines. It may be changed at will as
// it will not be regenerated once the application has been generated for the
// first time.
//

//*******************************************************************************
//
// Insert your interrupt handling code if required here.
// Note quick interrupts are used so code must be simple
// See the manual for details of quick interrupts.
//

void UserInterrupt()
{
    // Insert your code here

#asmline SETPCLATH UserIntReturn,-1 ; SETPCLATH for interrupt routine
#asmline goto UserIntReturn     ; Assembler - go back to interrupt routine
}


//*******************************************************************************
//
// Insert your initialisation code if required here.
// Note that when this routine is called Interrupts will not be enabled - the
// Application Designer will enable them before the main loop
//

void UserInitialise()
{
}

//*******************************************************************************
//
// Insert your main loop code if required here. This routine will be called
// as part of the main loop code
//

void UserLoop()
{
        
    if(!PA.B4)
    {
        if(!SW1_work)
        {
            SW1_work = 1;
            TxStr("Hello World_MacBook Pro\r\n");
        }
    }
    else
        SW1_work = 0;

    if(!PA.B5)
    {
        if(!SW2_work)
        {
            SW2_work = 1;
            TxStr("WiZ-C_MacBook Pro\r\n");
        }
    }
    else
        SW2_work = 0;
    
    if(!PA.B6)
    {
        if(!SW3_work)
        {
            SW3_work = 1;
            TxStr("PIC PROGRAM_MacBook Pro\r\n");
        }
    }
    else
        SW3_work = 0;
        
    if(!PA.B7)
    {
        if(!SW4_work)
        {
            SW4_work = 1;
            TxStr("0123456789_MacBook Pro\r\n");
        }
    }
    else
        SW4_work = 0;

}

//
// User occurrence code
//

void TxStr(char *Transmit_str)
{
    int i;
    for(i = 0; i < 32; i++)
    {
        if(Transmit_str[i] !=0)
            AddTx(Transmit_str[i]);
        else
            break;
    }
}

void CmdProc()
{
    if (strcmp(Receive_str,"LD1,1") == 0)
    {
        PA.B0 = 1;
        TxStr("LD1,1:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD1,0") == 0)
    {
        PA.B0 = 0;
        TxStr("LD1,0:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD2,1") == 0)
    {
        PA.B1 = 1;
        TxStr("LD2,1:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD2,0") == 0)
    {
        PA.B1 = 0;
        TxStr("LD2,0:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD3,1") == 0)
    {
        PA.B2 = 1;
        TxStr("LD3,1:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD3,0") == 0)
    {
        PA.B2 = 0;
        TxStr("LD3,0:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD4,1") == 0)
    {
        PA.B3 = 1;
        TxStr("LD4,1:OK_MacBook Pro\r\n");
    }
    if (strcmp(Receive_str,"LD4,0") == 0)
    {
        PA.B3 = 0;
        TxStr("LD4,0:OK_MacBook Pro\r\n");
    }
    strcpy(Receive_str,"");

}

//
// Occurrence - Byte received on serial interface
//

void GetRx()
{
    BYTE ch;
    if(GetRxSize() > 0)
    {
        ch = WaitRx();
        if(ch == '\r')            //'\r'(0x0D)
            CR_exist = 1;
        if(ch == '\n')            //'\n'(0x0A)
            LF_exist = 1;
        if (!(CR_exist | LF_exist))
        {
            Receive_str[StrCount] = ch;
            StrCount = StrCount + 1;
        }
        if(CR_exist & LF_exist)
        {
            Receive_str[StrCount] = 0;    //NULL
            StrCount = 0;                                                
            CR_exist = 0;
            LF_exist = 0;
            CmdProc();
        }
    }

}




トップページヘもどる