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

📄 main.c

📁 DS2438 one wire (ow) battery monitor code for renesas M16c... (-:cool:-)
💻 C
字号:
//_____________________________________________________________________________
//_____________________________________________________________________________
// Main
//_____________________________________________________________________________
//_____________________________________________________________________________
// FILENAME: main.c
// TARGET:  M16C/62 group MCU
// WRITTEN BY: Pete Cross 1/1/2001
// Copyright 2001 Pete Cross	
//_____________________________________________________________________________
// Tests the gas_mon.c functions.  
//_____________________________________________________________________________

// Includes
//_________

#include ".\gas_mon.h"  // Prototypes and defines for this file


// Defines 
//________
#define PAGE_TEST 3
#define BYTE_TEST 4
#define DATA_TEST 99

// Prototypes
//___________

void main(void);
void transmitThis(char *text);

// Functions
//__________

//_____________________________________________________________________________
// Main
//_____________________________________________________________________________
// Excercises the port pin with delays
//_____________________________________________________________________________
void main(void)
{
    int i, j;
    char text[80] = "";
    char text2[80] = "";
    float Vref = 0.0;
            
    initialise_udder(); // individual pin initial settings
    
    HR_Gascell_Switch_IN = ON;   
    pd_LED_Red = OUTPUT;
    pd_LED_Green = OUTPUT;
    

    sprintf(text, "\n\r================================");
    transmitThis(text);
    sprintf(text, "\n\r    Gascell monitor testing");
    transmitThis(text);
    sprintf(text, "\n\r================================");
    transmitThis(text);


    while(TRUE)
    {


    HR_Gascell_Switch_IN ^= 1;   

    if (HR_Gascell_Switch_IN)
    {
        sprintf(text, "\n\r================ Gascell switched ON ================");
        transmitThis(text);
        LED_Red = ON;    
    }
    else
    {
        sprintf(text, "\n\r=============== Gascell switched OFF ================");
        transmitThis(text);
        LED_Red = OFF;        
    }
    
    sprintf(text, "\n\r_______________________________________________________");
    transmitThis(text);
    
   for (i=1; i<100; i++)
  {
    LED_Green = ON;

    gas_mon_changeToVdd(); //  Vdd pin on gascell monitor is AVdd = Vref
    Vref = gas_mon_readVoltage();  // up date Vref reading
    
    sprintf(text, "\n\rReading : %d, Gascell switch is %s", i, (HR_Gascell_Switch_IN)? "on.":"off.");
    transmitThis(text);

    sprintf(text, "_______\n\r");
    transmitThis(text);

    sprintf(text, "\n\r\t\tID                 = 0x%2X", gas_mon_readID());
    transmitThis(text);


    sprintf(text, "\n\r\t\tGascell I          = %2.2f mA", gas_mon_readCurrent());
    transmitThis(text);

    sprintf(text, "\n\r\t\tGascell ICA        = %2.3f mAhr", gas_mon_readICA());
    transmitThis(text);

    sprintf(text, "\n\r\t\tGascell Rsense V   = %.1f mV  \t\t", gas_mon_readCurrent()*GAS_MON_R_SENSE);
    transmitThis(text);

    sprintf(text, "\n\r\t\tTemp from gas mon  = %3.1f C", gas_mon_readTemp() );
    transmitThis(text);


    gas_mon_changeToVad(); //  Vad pin on gascell monitor is +Battery
    sprintf(text, "\n\r\t\tBattery V          = %.2f V\t\t", gas_mon_readVoltage());
    transmitThis(text);

    gas_mon_changeToVdd(); //  Vdd pin on gascell monitor is AVdd = Vref
    sprintf(text, "\n\r\t\tAVdd = Vref        = %.2f V\t\t", gas_mon_readVoltage());
    transmitThis(text);

/*
    // Read/Write testing
    
    sprintf(text, "\n\n\rBefore Writing:");
    transmitThis(text);

    for(j=0; j<8; j++)
    {
        sprintf(text, "\n\r\t\t    Contents of page %i, byte %i is: %i", \
                        PAGE_TEST, j, readRegister(PAGE_TEST, j) );
        transmitThis(text);
    }
    
    writeRegister(PAGE_TEST, BYTE_TEST, DATA_TEST);

    sprintf(text, "\n\n\rAfter Writing:");
    transmitThis(text);

    for(j=0; j<8; j++)
    {
        sprintf(text, "\n\r\t\t     Contents of page %i, byte %i is: %i", \
                        PAGE_TEST, j, readRegister(PAGE_TEST, j) );
        transmitThis(text);
    }
    
    wordToStringAsBinary(text2, DATA_TEST);
    sprintf(text, "\n\n\r%d in decimal is %s in binary", DATA_TEST, text2);
    transmitThis(text);
    
*/

    sprintf(text, "\n\n\r");
    transmitThis(text);

    LED_Green = OFF;

    delay_ms(1000);

    }
 }

}
//_____________________________________________________________________________
//  transmitThis
//_____________________________________________________________________________
//_____________________________________________________________________________
void transmitThis(char *text)
{
    char preamble[] = {0x55, 0x55, 0x55, 0xF0, 0xF0, 0xF0, 0xF0, }; 
    char tx_buff[80] = "";

   
    printToCommPort(text); // only to comm port for now, no transmission
   
/*    strcpy (tx_buff,"");
    strcat(tx_buff, preamble);
    strcat(tx_buff, text);
    printToCommPort(tx_buff);
    TXR_OOK_transmit_mode();
    printToCommPort(tx_buff);
    te_u0c1 = 0; // disable UART0 transmit (get rid of idleline high)
    TXR_receive_mode();
    
    */

    delay_ms(5);
        
//        transmitString(text);


}




// End of file: main.c 
//_____________________________________________________________________________

⌨️ 快捷键说明

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