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

📄 main.c

📁 NE-STR750各部分的程序
💻 C
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 03/10/2006 : V0.1
* Description        : Main program body
********************************************************************************
* History:
* 06/20/2007 : V1.1
* The document is modified by New-Embed Co.Ltd(http://wwww.2embed.com) to fit the NE-STR750F board.
* 07/17/2006 : V1.0
* 03/10/2006 : V0.1 
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "75x_lib.h"

u8 ADC10,ADC1;
u16 adc_filter_cnt;
u16 adcdata,adc_result;


#define     SA  0x0400
#define     SB  0x0080
#define     SC  0x0040
#define     SD  0x0010
#define     SE  0x0020
#define     SF  0x0008
#define     SG  0x0100
#define     SH  0x0200

#define     Digit_0  SA | SB | SC | SD | SE | SF
#define     Digit_1       SB | SC
#define     Digit_2  SA | SB      | SD | SE      | SG
#define     Digit_3  SA | SB | SC | SD           | SG
#define     Digit_4       SB | SC           | SF | SG
#define     Digit_5  SA      | SC | SD      | SF | SG
#define     Digit_6  SA      | SC | SD | SE | SF | SG
#define     Digit_7  SA | SB | SC
#define     Digit_8  SA | SB | SC | SD | SE | SF | SG
#define     Digit_9  SA | SB | SC | SD      | SF | SG
#define     Digit_A  SA | SB | SC      | SE | SF | SG
#define     Digit_B            SC | SD | SE | SF | SG
#define     Digit_C  SA           | SD | SE | SF
#define     Digit_D       SB | SC | SD | SE      | SG
#define     Digit_E  SA           | SD | SE | SF | SG
#define     Digit_F  SA                | SE | SF | SG
#define     Digit_SP 0

const  u16  DigitTab[] = {Digit_0,Digit_1,Digit_2,Digit_3,
                       Digit_4,Digit_5,Digit_6,Digit_7,
                       Digit_8,Digit_9,Digit_A,Digit_B,
                       Digit_C,Digit_D,Digit_E,Digit_F,
                       Digit_SP};

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

  /* ST Logo to display on all 122*32 dot matrix */
 
  /* Peripherals InitStructure define */
  GPIO_InitTypeDef    GPIO_InitStructure ;
  EXTIT_InitTypeDef   EXTIT_InitStructure;
  UART_InitTypeDef    UART_InitStructure;
  ADC_InitTypeDef     ADC_InitStructure;
  

  void EIC_Configuration(void);
  void MRCC_Configuration(void);
  void GPIO_Configuration(void); 
  void Display(u8 Digit,u8 position);
 
  ErrorStatus OSC4MStartUpStatus01;

/* Private function prototypes -----------------------------------------------*/
/* Interface functions -------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : main
* Description    : main function, where program start.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void main(void)
{

#ifdef DEBUG
  debug();
#endif

  /* Initialize the demonstration application */
  EIC_Configuration();
  MRCC_Configuration();
  GPIO_Configuration();
/*-------------------------- Initialize Timer 0 ------------------------------*/ 
  
  /* Set TIM0 prescale Reg */
  TIM_SetPrescaler(TIM0, 0X3E7);
  /* Set TIM0 period  */
  TIM_SetPeriod(TIM0, 0xEA5F);
  /* Enable TIM0 update interrupt */
  TIM_ITConfig(TIM0, TIM_IT_Update, ENABLE);
  /* Start TIM0 */
  TIM_Cmd(TIM0, ENABLE);

/*-------------------------- Initialize A/D Convertor ------------------------*/  
  
    /* ADC configuration */
  ADC_InitStructure.ADC_ConversionMode = ADC_ConversionMode_Scan;    // 0x8000->CLR2
  ADC_InitStructure.ADC_ExtTrigger = ADC_ExtTrigger_Disable;         // 0x3FFF->CLR0
  ADC_InitStructure.ADC_AutoClockOff = ADC_AutoClockOff_Disable;     // 0xBFFF->CLR4
  ADC_InitStructure.ADC_SamplingPrescaler = 7;                       // 7->CLR1
  ADC_InitStructure.ADC_ConversionPrescaler = 7;                     // 7->CLR1
  ADC_InitStructure.ADC_FirstChannel = ADC_CHANNEL14;                // 15->FCH of CLR2
  ADC_InitStructure.ADC_ChannelNumber = 1;                           // 1-> NCH of CLR2 
  ADC_Init(&ADC_InitStructure);  

    /* Enable EOC Interrupt */
  ADC_ITConfig(ADC_IT_EOC, ENABLE);
    /* Enable ADC */
  ADC_Cmd(ENABLE);
    /* Start calibration */
//  ADC_StartCalibration(ADC_CalibAverage_Enable);
  ADC_ConversionCmd(ADC_Conversion_Start);

/* ---------------------------------------------------------------------------*/

  /* Configure the UART0 */
  UART_InitStructure.UART_WordLength = UART_WordLength_8D;
  UART_InitStructure.UART_StopBits = UART_StopBits_1;
  UART_InitStructure.UART_Parity = UART_Parity_Odd ;
  UART_InitStructure.UART_BaudRate = 115200;
  UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  UART_InitStructure.UART_Mode = UART_Mode_Tx;
  UART_InitStructure.UART_FIFO = UART_FIFO_Enable; 
  UART_Init(UART0, &UART_InitStructure);
 
  //UART_ITConfig(UART0, UART_IT_Receive, ENABLE); 
  
  /* Enable the UART0 */
  UART_Cmd(UART0, ENABLE);
  
/* -------------------------------------------------------------------------- */  
   
  Display(14,1);   
  while(1)
    {
        Display(ADC10,0);
        Display(ADC1,1);
    }
  
}

/*******************************************************************************
* Function Name  : MRCC_Configuration
* Description    : Initializes the demonstration application.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void MRCC_Configuration(void)
{
  /*-------------------- System Clock Config ---------------------------------*/
  /* MRCC system reset */
  MRCC_DeInit();

  /* Wait for OSC4M start-up */
  OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();

  if(OSC4MStartUpStatus01 == SUCCESS)
  {
    /* Set HCLK to 60MHz */
    MRCC_HCLKConfig(MRCC_CKSYS_Div1);

    /* Set CKTIM to 60MHz */
    MRCC_CKTIMConfig(MRCC_HCLK_Div1);

    /* Set PCLK to 30MHz */
    MRCC_PCLKConfig(MRCC_CKTIM_Div2);

    /* Enable Flash Burst mode */
    CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);

    /* Set CK_SYS to 60 MHz */
    MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
  }


  /*--------------------- I/O Voltage Range ----------------------------------*/
  /* GPIO pins optimized for 3V3 operation */
  MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);

  /*------------------ Peripheral Clock Enable -------------------------------*/
  /* GPIO clock source enable */
  MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
  /* ADC clock source enable */
  MRCC_PeripheralClockConfig(MRCC_Peripheral_ADC, ENABLE);
  /* TIM0, TIM1 and TIM2 clocks sources enable */
  MRCC_PeripheralClockConfig(MRCC_Peripheral_TIM0, ENABLE);
  /* EXTIT clock source enable */
 // MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
    /* Enable the UART0 Clocks */
  MRCC_PeripheralClockConfig(MRCC_Peripheral_UART0, ENABLE);
 
}


/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Initializes the demonstration application.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  /* Configure COM1 and  COM2 */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_1;
  GPIO_Init(GPIO0,&GPIO_InitStructure); 
  /* Configure LedDigit Pins */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3;
  GPIO_Init(GPIO1, &GPIO_InitStructure);
  
    /* Configure LED3 */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIO0,&GPIO_InitStructure);

    /* Configure P1.13 as AIN(14) */  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_Init(GPIO1,&GPIO_InitStructure); 
  
    /* Configure the UART0_Tx as alternate function */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11;
  GPIO_Init(GPIO0, &GPIO_InitStructure);
  
  /* Configure the UART0_Rx as input floating */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_Init(GPIO0, &GPIO_InitStructure);
  
}



/*******************************************************************************
* Function Name  : Display
* Description    : Display digit LED
* Input          : Digit: value to be displayed, 0-16.
*                : Position: 1 or 0, 0 select digit 10, 1 select digit 0
* Output         : None
* Return         : None
*******************************************************************************/
void Display(u8 Digit,u8 position)
{
    u16 i;

    GPIO0->PD &= 0xFFF0;
    Digit &= 0x0F;
    GPIO_Write(GPIO1, DigitTab[Digit]);

    if (position == 0)
        GPIO0->PD |= 0x0004;  // P02= COMM of digit 10
    else
        GPIO0->PD |= 0x0002;  // P01= COMM of digit 1

    for(i=0; i<0x100; i++);
}

/*******************************************************************************
* Function Name  : EIC_Configuration
* Description    : Initializes the demonstration application.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EIC_Configuration(void)
{

   EIC_IRQInitTypeDef  EIC_IRQInitStructure;
  /*---------------------- IRQ Interrupts -----------------------*/
 
  /* Enable and configure the priority of the TIM0 IRQ Channel */
  EIC_IRQInitStructure.EIC_IRQChannel = TIM0_UP_IRQChannel;
  EIC_IRQInitStructure.EIC_IRQChannelPriority = 3;
  EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
  EIC_IRQInit(&EIC_IRQInitStructure);
  
  /* Enable and configure the priority of the ADC Channel */
  EIC_IRQInitStructure.EIC_IRQChannel = ADC_IRQChannel;
  EIC_IRQInitStructure.EIC_IRQChannelPriority = 10;
  EIC_IRQInit(&EIC_IRQInitStructure);  

    /* Enable IRQ output request to CPU */
  EIC_IRQCmd(ENABLE);
  
}


⌨️ 快捷键说明

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