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

📄 main.c

📁 430系列开发之MSP430FE42x开发代码实例
💻 C
字号:
/** \file 
  * ESP430CE1 Application Program Example
  *
  * This file shows exemplarily the usage of the ESP430CE1 module for
  * a single-phase emeter with two current sensors (one shunt and one
  * current transformer).
  *
  * \author Volker Rzehak
  * \date   04/08/2003
  *
  * \Modified Stefan Schauer
  * \date   04/29/2003
  */
//====================================================================

#include "device.h"
#include "comms_uart.h"
#include "subroutines.h"
#include "uart0.h"
#include "SendData.h"
#include "fet4xx_rtclcd.h"
#include "display.h"
#include "emeter.h"
#include "parameter.h"

#include <stdio.h>
#include <math.h>


// const and var definition
// const and var definition
const char banner[]="MSP430FE427   ";
const unsigned int sbanner = 14;
const char TempBanner[]="\rTemp: ";

unsigned int OP_Mode = idle;  // operation mode

// forward declarations

unsigned int sys_status = 0;   // System status bits

//====================================================================
  // Init Digital Hardware
void init_system(void)
{
    int i;
    char *LCD = LCDMEM;
    P1OUT = 0x03;
    P2OUT = 0x00;
    P1DIR = 0xFF;  // P1.0 + P1.1 = LED Output
                   // P1.2 - P1.7 = LCD
    P2DIR = 0xC3;  // P2.0 + P2.1 = LCD
                   // P2.2 + P2.3 = switch input
                   // P2.4 + P2.5 = UART


    //P1DIR |= 0x02; // MCLK out on - test
    //P1SEL |= 0x02; // MCLK out on - test

    P2IFG = 0x00;  // Clear interrupt Flags

    FCTL2 = FWKEY | FSSEL_1 | defFlashFreq;  // Configure Flash Timing Generator

    LCDCTL = LCDON + LCD4MUX + LCDP2 + LCDP0; // Enable LCD
    BTCTL  = BTHOLD + BTFRFQ1; // f(LCD) = ACLK / 256 = 128 Hz 
   // clear LCD memory to clear display //
    for (i=0; i<12; i++)
    {
       LCD[i] = 0;
    } 
}

void __low_level_init(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
//    P1OUT ^= 0x01;
//    P1DIR |= 0x01;  // P1.0 toggle on each reset

}
//====================================================================
void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT

  // Init Digital Hardware
  init_system();

  // Init. FLL and clocks  
  init_fll(10, defSystemFreq, 32);   

  // Init. UART
#ifdef withUARTComm
  InitUART(9600);
  InitUART(57600);
//  InitUART(115200);
  TX_Mode = tx_off;
  SendString("\r\r");
  SendString(banner);
  SendString("Firmware Version: ");
  SendResult((unsigned char*) &firmware_version, 2);
  SendChar('\r'); 
  SendChar('\n'); 
  SendChar('\r'); 
#endif // withUARTComm

 // Init. RTC and Display
#ifdef withDisplay
  SetupClock();
  LCDtext ((unsigned char *) banner, 6, 6);
#endif // withDisplay  

 // Init. analog front-end (sigma-delta ADC)
  init_analog_front_end();
  // Init. Embedded Signal Processing parameters
  init_esp_parameter(1);
  // Init. event generation and start measurement
  start_measurement();

  _EINT(); // Enable Interrupts
  
  while (1)
  {
#ifdef withUARTComm
    if ((TX_Mode < tx_ch1) || (TX_Mode > tx_ch3)) 
      {LPM0;}  // switch MSP430 into Low Power Mode 0
    else sys_status |= NewValues;

    // process UART receive
    if((UART_Status & LineReceived) != 0)
    {
        Process_UART();
        UART_Status &= ~LineReceived;     // clear flag
        if ( OP_Mode == request_cal)
        {
          TX_Mode = tx_off;
          start_calibration();
        }
        else
        {
             if ( OP_Mode == done) start_measurement();
        }
    }

    // process UART send
    if((sys_status & NewValues) != 0)
    {
       sys_status &= ~NewValues;
       SendData();
    }
#else
    LPM0;  // switch MSP430 into Low Power Mode 0
#endif // withUARTComm
    
#ifdef withDisplay
    DisplayData();
#endif // withDisplay

  } // End of while (1)
} // End of main()

⌨️ 快捷键说明

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