3.4.4_プログラムリスト(THERMOLOG2_User.c)(H20/9/21)

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

#__config _CONFIG1H, 0x02
#__config _CONFIG1L, 0x00
#__config _CONFIG2H, 0x0E
#__config _CONFIG2L, 0x0E
#__config _CONFIG3H, 0x01
#__config _CONFIG3L, 0x00
#__config _CONFIG4H, 0x00
#__config _CONFIG4L, 0x81

unsigned char    dow[7][5] ={"Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat."};
unsigned char    out_str1[17], out_str2[17], disp_Work1[3],rom_write[16], rom_read[16], rom_Work1[16], Receive_str[32], Transmit_str[32];
unsigned long    TL_PV,TL_PV_Work, TL_PV_Work1, TL_PV_Work2, TL_PV_Average[10],TL_PV_Average_Work;
WORD        TL_AJ_TEMP, TL_AJ_ADTEMP, TL_SAMPLING_CYCLE,TL_AJ_TEMP_Work, TL_AJ_ADTEMP_Work, TL_SAMPLING_CYCLE_Work;
WORD        TL_Work1, TL_Work2, TL_Work3,EE_LogNo,EE_NoReadLogNo,EE_adrs, EE_Work1,EE_SampReadLogNo, EE_SampNoReadLogNo;
WORD        secc,minc,hourc,dayc,monthc,yearc,weekc,secc_Work, minc_Work, hourc_Work, dayc_Work, monthc_Work, yearc_Work, weekc_Work;
BYTE        EE_uadrs,dt1, dt2, dt3, dt4, dt5, dt6;
int        Secc,SetModeNo, StrCount, CAL_Work,Aj_Write_No,AverageCount;
bit        CR_exist,LF_exist,Cmd_SampRead1,Cmd_SampRead2,Cmd_SampRead3,Cmd_CtrlRead,Flag1Sec, SetMode, SetKey, LeftKey, RightKey, UpKey, DownKey;
bit        AjTempMode,ModeKey_Work, SetKey_Work, LeftKey_Work, RightKey_Work, UpKey_Work, DownKey_Work, SetMode_Work,AjTempJp_Work,TL_PV_Init;
bit        EE_Check, EE_SetMode, EE_SetMode_Use, EE_SetTempAjMode,SampCtrlWrite;

void timer_1sec();
void Samp_CtrlWrite();
void I2C_AdrsSet(BYTE uadrs, WORD adrs);
void I2C_ROM_Write(BYTE uadrs, WORD adrs, BYTE *data, BYTE size);
void I2C_ROM_Read(BYTE uadrs, WORD adrs, BYTE *data, BYTE size);
void EE_Write();
void EE_Read(WORD logno);
void TxStr(char *Transmit_str);
void CmdProc();
void CmdSampRead();
void CmdCtrlRead();

//
// 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
    if(PIR1 & (1<<CCP1IF))
    {
        PIR1 &= ~(1<<CCP1IF);
        Secc++;
        if(Secc == 25)
        {
            Secc = 0;
            Flag1Sec = 1;
        }
    }
#asmline goto UserIntReturn    ; PIC 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()
{
    INTCON |= 1<<PEIE;
    PIE1 |= 1<<CCP1IE;
    dt1 = ReadEEData(0);        //temp(adjust value)
    dt2 = ReadEEData(1);
    EE_Work1 = (WORD)dt2 << 8;
    TL_AJ_TEMP = EE_Work1 | dt1;
    dt1 = ReadEEData(2);        //ad temp(adjust value)
    dt2 = ReadEEData(3);
    EE_Work1 = (WORD)dt2 << 8;
    TL_AJ_ADTEMP = EE_Work1 | dt1;
    if(TL_AJ_TEMP > 650)
        EE_Check = 1;
    if(TL_AJ_ADTEMP > 1023)
        EE_Check = 1;
    if(EE_Check)
    {
        TL_AJ_TEMP = 650;
        TL_AJ_ADTEMP = 1010;
        dt1 = TL_AJ_TEMP & 0x00FF;
        dt2 = TL_AJ_TEMP >> 8;
        dt3 = TL_AJ_ADTEMP & 0x00FF;
        dt4 = TL_AJ_ADTEMP >> 8;
        WriteEEData(0,dt1);
        Wait(100);
        WriteEEData(1,dt2);
        Wait(100);
        WriteEEData(2,dt3);
        Wait(100);
        WriteEEData(3,dt4);
        Wait(100);
    }
    TL_AJ_TEMP_Work = TL_AJ_TEMP;
    TL_PV_Init = 1;
    yearc = 2001;
    monthc = 1;
    dayc = 1;
    I2C_ROM_Read(0x00,0x0000,rom_read,8);
    rom_Work1[0] = rom_read[0];
    rom_Work1[1] = rom_read[1];
    rom_Work1[2] = rom_read[2];
    rom_Work1[3] = rom_read[3];
    rom_Work1[4] = 0;
    EE_Work1 = atoi(rom_Work1);
    if(EE_Work1 > 8191)
        EE_LogNo = 0;        //EE_LogNo:1 -- 8191(0:Control Data)
    else
        EE_LogNo = EE_Work1;
    rom_Work1[0] = rom_read[4];
    rom_Work1[1] = rom_read[5];
    rom_Work1[2] = rom_read[6];
    rom_Work1[3] = rom_read[7];
    rom_Work1[4] = 0;
    EE_Work1 = atoi(rom_Work1);
    if((EE_Work1 > 8191) | (EE_Work1 < 0))
        EE_NoReadLogNo = 0;
    else
        EE_NoReadLogNo = EE_Work1;
    LCDClear();        
    sprintf(disp_Work1," ");        
    ADCON0 |= (1<<GO);
}

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

void UserLoop()
{
    if(!PD.B2 && !ModeKey_Work)        //Mode key
    {
        ModeKey_Work = 1;
        SetMode = !SetMode;
    }
    if(PD.B2)
        ModeKey_Work = 0;

    if(!PD.B3 && !SetKey_Work)        //Set key
    {
        SetKey_Work = 1;
        SetKey = 1;
    }
    if(PD.B3)
        SetKey_Work = 0;
    if(!SetKey)
        Aj_Write_No = 0;
    
    if(!PD.B6 && !LeftKey_Work)        //Left key
    {
        LeftKey_Work = 1;
        LeftKey = 1;
    }
    if(PD.B6)
        LeftKey_Work = 0;
    if(!PD.B7 && !RightKey_Work)        //Right key
    {
        RightKey_Work = 1;
        RightKey = 1;
    }
    if(PD.B7)
        RightKey_Work = 0;
    if(!PD.B4 && !UpKey_Work)        //Up key
        UpKey = 1;

    if(PD.B4)
        UpKey_Work = 0;

    if(!PD.B5 && !DownKey_Work)        //Down key
        DownKey = 1;

    if(PD.B5)
        DownKey_Work = 0;

    if(!PC.B5 && !AjTempJp_Work)        //AjTemp Jp
    {
        AjTempJp_Work = 1;
        AjTempMode = !AjTempMode;
    }
    if(PC.B5)
    {
        AjTempJp_Work = 0;
        AjTempMode = 0;
    }
    PIE1 &= ~(1<<CCP1IE);            //1sec process
    if(Flag1Sec)
    {
        Flag1Sec = 0;
        timer_1sec();
    }
    PIE1 |= 1<<CCP1IE;
}


//
// User occurrence code
//
void timer_1sec()
{
    secc = secc + 1;
    if(secc > 59)
    {
        secc = 0;
        minc = minc + 1;
    }
    if(minc > 59)
    {
        minc = 0;
        hourc = hourc + 1;
    }
    if(hourc > 23)
        hourc = 0;
    if((hourc == 0) && (minc == 0) && (secc == 0))
    {
        dayc = dayc + 1;
        if(weekc > 6)
            weekc = 0;
        switch(monthc)
        {
            case 1: CAL_Work = 1; break;
            case 2: CAL_Work = 3; break;
            case 3: CAL_Work = 1; break;
            case 4: CAL_Work = 2; break;
            case 5: CAL_Work = 1; break;
            case 6: CAL_Work = 2; break;
            case 7: CAL_Work = 1; break;
            case 8: CAL_Work = 1; break;
            case 9: CAL_Work = 2; break;
            case 10: CAL_Work = 1; break;
            case 11: CAL_Work = 2; break;
            case 12: CAL_Work = 1; break;
        }
        if(CAL_Work == 1)
        {
            if(dayc > 31)
            {
                if(monthc == 12)
                {
                    monthc = 1;
                    yearc = yearc + 1;
                }
                else
                    monthc = monthc + 1;
                dayc = 1;
            }
        }
        if(CAL_Work == 2)
        {
            if(dayc > 30)
            {
                monthc = monthc + 1;
                dayc = 1;
            }
        }
        if(CAL_Work == 3)
        {
            if(dayc > 28)
            {
                if((yearc % 4 == 0) && (yearc % 100 != 0) || (yearc % 400 == 0))
                {
                    if(dayc > 29)
                    {
                        monthc = monthc + 1;
                        dayc = 1;
                    }
                }
                else
                {
                    if(dayc > 28)
                    {
                        monthc = monthc + 1;
                        dayc = 1;
                    }
                }
            }
        }    
    }

    int    i;
    TL_PV_Average_Work = 0;
    for(i=0;i<10;i++)
        TL_PV_Average_Work = TL_PV_Average_Work + TL_PV_Average[i];
    TL_PV = (TL_PV_Average_Work / 10) * TL_AJ_TEMP / TL_AJ_ADTEMP;

    if(SetMode && !AjTempMode)
    {
        if(LeftKey)
        {
            SetModeNo = SetModeNo - 1;
            if(SetModeNo < 0)
                 SetModeNo = 6;
        }        
        if(RightKey)
        {
            SetModeNo = SetModeNo + 1;
            if(SetModeNo > 6)
                 SetModeNo = 0;
        }
        if(LeftKey || RightKey)
        {
            LeftKey = 0;
            RightKey = 0;
            switch(SetModeNo)
            {
                case 0: sprintf(out_str2,"Year:%04d ",yearc_Work); break;
                case 1: sprintf(out_str2,"Month:%02d ",monthc_Work); break;
                case 2: sprintf(out_str2,"Day:%02d ",dayc_Work); break;
                case 3: sprintf(out_str2,"Hour:%02d ",hourc_Work); break;
                case 4: sprintf(out_str2,"Minute:%02d ",minc_Work); break;
                case 5: sprintf(out_str2,"Second:%02d ",secc_Work); break;
                case 6: sprintf(out_str2,"Week:%04s ",dow[weekc_Work]); break;
            }
        }
        if(UpKey)        //Up Key
        {
            UpKey = 0;
            switch(SetModeNo)
            {
                case 0;
                    yearc_Work = yearc_Work + 1;
                    if(yearc_Work > 2100)
                        yearc_Work = 2001;
                    sprintf(out_str2,"Year:%04d ",yearc_Work);
                    break;
                case 1:
                    monthc_Work = monthc_Work + 1;
                    if(monthc_Work > 12)
                        monthc_Work = 1;
                    sprintf(out_str2,"Month:%02d ",monthc_Work);
                    break;
                case 2:
                    dayc_Work = dayc_Work + 1;
                    if(dayc_Work > 31)
                        dayc_Work = 1;
                    sprintf(out_str2,"Day:%02d ",dayc_Work);
                    break;
                case 3:
                    hourc_Work = hourc_Work + 1;
                    if(hourc_Work > 23)
                        hourc_Work = 0;
                    sprintf(out_str2,"Hour:%02d ",hourc_Work);
                    break;
                case 4:
                    minc_Work = minc_Work + 1;
                    if(minc_Work > 59)
                        minc_Work = 0;
                    sprintf(out_str2,"Minute:%02d ",minc_Work);
                    break;
                case 5:
                    secc_Work = secc_Work + 1;
                    if(secc_Work > 59)
                        secc_Work = 0;
                    sprintf(out_str2,"Second:%02d ",secc_Work);
                    break;
                case 6:
                    weekc_Work = weekc_Work + 1;
                    if(weekc_Work > 6)
                        weekc_Work = 0;
                    sprintf(out_str2,"Week:%04s ",dow[weekc_Work]);
            }
        }
        if(DownKey)        //Down Key
        {
            DownKey = 0;
            switch(SetModeNo)
            {

                case 0:
                    yearc_Work = yearc_Work - 1;
                    if(yearc_Work < 2001)
                        yearc_Work = 2100;
                    sprintf(out_str2,"Year:%04d ",yearc_Work);
                    break;
                case 1:
                    monthc_Work = monthc_Work - 1;
                    if(monthc_Work < 1)
                        monthc_Work = 12;
                    sprintf(out_str2,"Month:%02d ",monthc_Work);
                    break;
                case 2:
                    dayc_Work = dayc_Work - 1;
                    if(dayc_Work < 1)
                        dayc_Work = 31;
                    sprintf(out_str2,"Day:%02d ",dayc_Work);
                    break;
                case 3:
                    if(hourc_Work == 0)
                        hourc_Work = 23;
                    else
                        hourc_Work = hourc_Work - 1;
                    sprintf(out_str2,"Hour:%02d ",hourc_Work);
                    break;
                case 4:
                    if(minc_Work == 0)
                        minc_Work = 59;
                    else
                        minc_Work = minc_Work - 1;
                    sprintf(out_str2,"Minute:%02d ",minc_Work);
                    break;
                case 5:
                    if(secc_Work == 0)
                        secc_Work = 59;
                    else
                        secc_Work = secc_Work - 1;
                    sprintf(out_str2,"Second:%02d ",secc_Work);
                    break;
                case 6:
                    if(weekc_Work == 0)
                        weekc_Work = 6;
                    else
                        weekc_Work = weekc_Work - 1;
                    sprintf(out_str2,"Week:%04s ",dow[weekc_Work]);
            }
        }
        if(SetKey)        //Set Key
        {
            SetKey = 0;
            yearc = yearc_Work;
            monthc = monthc_Work;
            dayc = dayc_Work;
            hourc = hourc_Work;
            minc = minc_Work;
            secc = secc_Work;
            weekc = weekc_Work;
            SetMode = 0;
        }
        sprintf(out_str1,"SETTING MODE ");
        LCDPrintAt(0,0);
        LCDString(out_str1);
        LCDPrintAt(0,1);
        LCDString(out_str2);
    }

    if(AjTempMode)
    {
        SetMode = 0;
        LeftKey = 0;
        RightKey = 0;
        if(UpKey)        //Up Key
        {
            UpKey = 0;
            TL_AJ_TEMP_Work = TL_AJ_TEMP_Work + 1;
            if(TL_AJ_TEMP_Work > 650)
                TL_AJ_TEMP_Work = 0;
        }
        if(DownKey)        //Down Key
        {
            DownKey = 0;
            if(TL_AJ_TEMP_Work == 0)
                TL_AJ_TEMP_Work = 650;
            else
                TL_AJ_TEMP_Work = TL_AJ_TEMP_Work - 1;
        }
        sprintf(out_str1,"PRESENT TEMP SET");
        LCDPrintAt(0,0);
        LCDString(out_str1);
        if(!SetKey)
        {
            TL_Work1 = TL_AJ_TEMP_Work / 10;
            TL_Work2 = TL_AJ_TEMP_Work % 10;
            disp_Work1 = 0xdf;
            TL_AJ_ADTEMP_Work = TL_PV_Work;
            sprintf(out_str2,"%02d.%01d%sC(AD:%04d) ",TL_Work1,TL_Work2,disp_Work1,TL_AJ_ADTEMP_Work);    
             LCDPrintAt(0,1);
            LCDString(out_str2);
        }

        if(SetKey)        //Set Key
        {
            sprintf(out_str2,"TEMP WRITING. ");
            LCDPrintAt(0,1);
            LCDString(out_str2);
            switch(Aj_Write_No)
            {
                case 0:
                    dt1 = TL_AJ_TEMP_Work & 0x00FF;
                    dt2 = TL_AJ_TEMP_Work >> 8;
                    dt3 = TL_AJ_ADTEMP_Work & 0x00FF;
                    dt4 = TL_AJ_ADTEMP_Work >> 8;
                    WriteEEData(0,dt1);
                    Aj_Write_No = 1;
                    break;
                case 1:
                    WriteEEData(1,dt2);
                    Aj_Write_No = 2;
                    break;
                case 2:
                    WriteEEData(2,dt3);
                    Aj_Write_No = 3;
                    break;
                case 3:
                    WriteEEData(3,dt4);
                    TL_AJ_TEMP = TL_AJ_TEMP_Work;
                    TL_AJ_ADTEMP = TL_AJ_ADTEMP_Work;
                    AjTempMode = 0;
                    SetKey = 0;
                    break;
            }
        }
    }

    if(!SetMode && !AjTempMode)
    {
        sprintf(out_str1,"%04d/%02d/%02d %04s",yearc,monthc,dayc,dow[weekc]);
        TL_PV_Work1 = TL_PV / 10;
        TL_PV_Work2 = TL_PV % 10;
        disp_Work1 = 0xdf;
        sprintf(out_str2,"%02d:%02d:%02d %02ld.%01ld%sC",hourc,minc,secc,TL_PV_Work1,TL_PV_Work2,disp_Work1);
        LCDPrintAt(0,0);
        LCDString(out_str1);
        LCDPrintAt(0,1);
        LCDString(out_str2);
        yearc_Work = yearc;
        monthc_Work = monthc;
        dayc_Work = dayc;
        hourc_Work = hourc;
        minc_Work = minc;
        secc_Work = secc;
        weekc_Work = weekc;
        TL_AJ_TEMP_Work = TL_AJ_TEMP;
        TL_AJ_ADTEMP_Work = TL_AJ_ADTEMP;
        SetKey = 0;
        LeftKey = 0;
        RightKey = 0;
        UpKey = 0;
        DownKey = 0;
        SetModeNo = 0;
        sprintf(out_str2,"Year:%04d ",yearc_Work);             
    }

    if( ((minc == 0) || (minc == 10) || (minc == 20) || (minc == 30) || (minc == 40) || (minc == 50)) && (secc == 0) )    //10min SAMPLING
        EE_Write();
    else
    {
        if(SampCtrlWrite)
            Samp_CtrlWrite();
        else
        {
            if(Cmd_SampRead1 | Cmd_SampRead2 | Cmd_SampRead3)
                CmdSampRead();
            else
            {
                if(Cmd_CtrlRead)
                    CmdCtrlRead();
            }
        }
    }
    ADCON0 |= (1<<GO);
}

void Samp_CtrlWrite()
{
    SampCtrlWrite = 0;
    sprintf(rom_write,"%04d%04d ",EE_LogNo,EE_NoReadLogNo);
    I2C_ROM_Write(0x00,0x0000,rom_write,8);        //Control Data
}

//
// I2C-EEPROM DATA WRITE
//
void I2C_ROM_Write(BYTE uadrs, WORD adrs, BYTE *data, BYTE size)
{
    int i;
    I2C_AdrsSet(uadrs, adrs);
    for(i = 0; i < size; i++)
    {
        I2CWrite(*data);
        data++;
    }
    I2CStop();
}

//
// I2C-EEPROM DATA READ
//
void I2C_ROM_Read(BYTE uadrs, WORD adrs, BYTE *data, BYTE size)
{
    int i;
    I2C_AdrsSet(uadrs, adrs);
    I2CStart(I2C_START_CONT);
    if(uadrs == 0)
        I2CWrite(0xA1);            // control byte (write)
    else
        I2CWrite(0xA3);            // control byte (write)

    for(i = 0; i < size; i++)
    {
        if(i != (size - 1))
            *data = I2CRead(I2C_READ_ACK);
        else
            *data = I2CRead(I2C_READ_NOACK);
        data++;
    }
    I2CStop();
}

//
// I2C-EEPROM DATA READ/WRITE ADDRES SET
//
void I2C_AdrsSet(BYTE uadrs, WORD adrs)
{
    I2CStart(I2C_START_NORM);
    if(uadrs == 0)
        I2CWrite(0xA0);            // control byte (write)
    else
        I2CWrite(0xA2);            // control byte (write)
    I2CWrite(adrs>>8);            // EEPROM Address(H)
    I2CWrite(adrs);                // EEPROM Address(L)
}

//
// I2C-EEPROM DATA WRITE
//
void EE_Write()
{
    EE_LogNo = EE_LogNo + 1;
    EE_NoReadLogNo = EE_NoReadLogNo + 1;

    if(EE_LogNo > 8191)
        EE_LogNo = 1;
    if(EE_LogNo > 4095)
    {
        EE_uadrs = 1;
        EE_adrs = (EE_LogNo - 4096) * 16;
    }
    else
    {
        EE_uadrs = 0;
        EE_adrs = EE_LogNo * 16;
    }
    
    TL_Work3 = yearc % 2000;
    sprintf(rom_write,"%02d%02d%02d%02d%02d%02d%03ld ",TL_Work3,monthc,dayc,weekc,hourc,minc,TL_PV);            
    I2C_ROM_Write(EE_uadrs,EE_adrs,rom_write,16);    //Sampling Data
    SampCtrlWrite = 1;
}

//
// I2C-EEPROM DATA READ
//
void EE_Read(WORD logno)
{
    if(logno > 8191)
        logno = 1;
    if(logno > 4095)
    {
        EE_uadrs = 1;
        EE_adrs = (logno - 4096) * 16;
    }
    else
    {
        EE_uadrs = 0;
        EE_adrs = logno * 16;
    }
    I2C_ROM_Read(EE_uadrs,EE_adrs,rom_read,16);
}

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

//
// SERIAL PORT RECEIVE PROCESS
//
void CmdSampRead()
{
        int    i;
        for(i = 0; i < 3; i++)
        {
            if(EE_SampNoReadLogNo != 0)
            {
                if(EE_SampReadLogNo < 1)
                    EE_SampReadLogNo = 8191;
                EE_Read(EE_SampReadLogNo);
                strcpy(Transmit_str, rom_read);
                Transmit_str[15] = '\r';
                Transmit_str[16] = '\n';
                Transmit_str[17] = 0;
                TxStr(Transmit_str);
                EE_SampReadLogNo = EE_SampReadLogNo - 1;
                EE_SampNoReadLogNo = EE_SampNoReadLogNo - 1;
                if(Cmd_SampRead1)
                    EE_NoReadLogNo = EE_NoReadLogNo - 1;
            }
            else
            {
                if(Cmd_SampRead1)
                {
                    Cmd_SampRead1 = 0;
                    SampCtrlWrite = 1;
                }
                Cmd_SampRead2 = 0;
                Cmd_SampRead3 = 0;
            }
        }
}

void CmdCtrlRead()
{
        I2C_ROM_Read(0x00,0x0000,rom_read,8);
        strcpy(Transmit_str, rom_read);
        Transmit_str[8] = '\r';
        Transmit_str[9] = '\n';
        Transmit_str[10] = 0;
        TxStr(Transmit_str);
        Cmd_CtrlRead = 0;
}

void CmdProc()
{
    if(strcmp(Receive_str,"SAR1") == 0)
    {
        if(!(Cmd_SampRead2 | Cmd_SampRead3))
        {
            Cmd_SampRead1 = 1;
            EE_SampReadLogNo = EE_LogNo;
            EE_SampNoReadLogNo = EE_NoReadLogNo;
        }
    }
    if(strcmp(Receive_str,"SAR2") == 0)
    {
        if(!(Cmd_SampRead1 | Cmd_SampRead3))
        {
            Cmd_SampRead2 = 1;
            EE_SampReadLogNo = EE_LogNo;
            EE_SampNoReadLogNo = 144;
        }
    }
    if(strcmp(Receive_str,"SAR3") == 0)
    {
        if(!(Cmd_SampRead1 | Cmd_SampRead2))
        {
            Cmd_SampRead3 = 1;
            EE_SampReadLogNo = EE_LogNo;
            EE_SampNoReadLogNo = 720;
        }
    }
    if(strcmp(Receive_str,"CTR") == 0)
        Cmd_CtrlRead = 1;
    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();
        }
    }
}

//
// Occurrence - A/D Conversion complete
//
void ad_data_t()
{
    TL_PV_Work = (unsigned long)ADRESH << 8;
    TL_PV_Work = TL_PV_Work | ADRESL;
    if(AverageCount >= 10)
        AverageCount = 0;
    TL_PV_Average[AverageCount] = TL_PV_Work;
    AverageCount = AverageCount + 1;

    if(TL_PV_Init)        //Initial
    {
        TL_PV_Init = 0;
        int    i;    
        for(i=1;i<10;i++)
            TL_PV_Average[i] = TL_PV_Average[0];
    }
}





トップページヘもどる