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

📄 main.c.bak

📁 完成数据的采集
💻 BAK
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
 *
 *    Used with ICCARM and AARM.
 *
 *    (c) Copyright IAR Systems 2007
 *
 *    File name   : main.c
 *    Description : Define main module
 *
 *    History :
 *    1. Date        : 19, July 2006
 *       Author      : Stanimir Bonev
 *       Description : Create
 *
 *  This example project shows how to use the IAR Embedded Workbench
 * for ARM to develop code for the IAR STM32-SK board. It shows basic
 * use of parallel I/O, timer, interrupt controller, ADC and interface to
 * a LCD HD44780 compatible module.
 *  It show the position of the potentiometer in percents (ADC Channel 15).
 *
 *  Jumpers:
 *   PWR_SEL - depending of power source
 *
 *    $Revision: 19278 $
 **************************************************************************/
#define   EXT
#define   MCP2515
#define	  FILE_MAIN
 
#include"ytep.h"
#include"ytepfunction.h"
const Int16U TEMP_TAB[]={
  
	//0x0f2,	// -29.00		190.6521
	//0x0f1,	// -28.00		178.6479
	//0x0f0,	// -27.00		167.4788
	0x0ef,	// -26.00		157.0812
	0x0ee,	// -25.00		147.3972
	0x0ed,	// -24.00		138.3733
	0x0ec,	// -23.00		129.9605
	0x0eb,	// -22.00		122.1136
	0x0ea,	// -21.00		114.7911
	0x0e9,	// -20.00		107.9547
	0x0e8,	// -19.00		101.5693
	0x0e6,	// -18.00		95.6023
	0x0e5,	// -17.00		90.0238
	0x0e4,	// -16.00		84.8062
	0x0e2,	// -15.00		79.9239
	0x0e1,	// -14.00		75.3534
	0x0df,	// -13.00		71.0730
	0x0dd,	// -12.00		67.0625
	0x0dc,	// -11.00		63.3032
	0x0da,	// -10.00		59.7781
	0x0d8,	// -9.00		56.4710
	0x0d6,	// -8.00		53.3673
	0x0d4,	// -7.00		50.4533
	0x0d2,	// -6.00		47.7163
	0x0d0,	// -5.00		45.1444
	0x0ce,	// -4.00		42.7268
	0x0cc,	// -3.00		40.4534
	0x0ca,	// -2.00		38.3146
	0x0c7,	// -1.00		36.3019
	0x0c5,	// 0.00		34.4069
	0x0c3,	// 1.00		32.6223
	0x0c0,	// 2.00		30.9408
	0x0be,	// 3.00		29.3561
	0x0bb,	// 4.00		27.8619
	0x0b9,	// 5.00		26.4525
	0x0b6,	// 6.00		25.1228
	0x0b3,	// 7.00		23.8678
	0x0b0,	// 8.00		22.6828
	0x0ae,	// 9.00		21.5635
	0x0ab,	// 10.00		20.5060
	0x0a8,	// 11.00		19.5065
	0x0a5,	// 12.00		18.5615
	0x0a2,	// 13.00		17.6678
	0x09f,	// 14.00		16.8222
	0x09d,	// 15.00		16.0219
	0x09a,	// 16.00		15.2643
	0x097,	// 17.00		14.5468
	0x094,	// 18.00		13.8672
	0x091,	// 19.00		13.2231
	0x08e,	// 20.00		12.6126
	0x08b,	// 21.00		12.0337
	0x088,	// 22.00		11.4847
	0x085,	// 23.00		10.9637
	0x082,	// 24.00		10.4693
	0x07f,	// 25.00		10.0000
	0x07c,	// 26.00		9.5543
	0x079,	// 27.00		9.1310
	0x076,	// 28.00		8.7287
	0x074,	// 29.00		8.3464
	0x071,	// 30.00		7.9829
	0x06e,	// 31.00		7.6372
	0x06b,	// 32.00		7.3084
	0x068,	// 33.00		6.9956
	0x066,	// 34.00		6.6978
	0x063,	// 35.00		6.4144
	0x061,	// 36.00		6.1444
	0x05e,	// 37.00		5.8873
	0x05b,	// 38.00		5.6423
	0x059,	// 39.00		5.4089
	0x057,	// 40.00		5.1863
	0x054,	// 41.00		4.9741
	0x052,	// 42.00		4.7717
	0x050,	// 43.00		4.5786
	0x04d,	// 44.00		4.3943
	0x04b,	// 45.00		4.2185
	0x049,	// 46.00		4.0506
	0x047,	// 47.00		3.8902
	0x045,	// 48.00		3.7371
	0x043,	// 49.00		3.5908
	0x041,	// 50.00		3.4509
	0x03f,	// 51.00		3.3173
	0x03d,	// 52.00		3.1895
	0x03b,	// 53.00		3.0673
	0x03a,	// 54.00		2.9504
	0x038,	// 55.00		2.8386
	0x036,	// 56.00		2.7316
	0x035,	// 57.00		2.6291
	0x033,	// 58.00		2.5311
	0x031,	// 59.00		2.4372
	0x030,	// 60.00		2.3472
	0x02f,	// 61.00		2.2611
	0x02d,	// 62.00		2.1785
	0x02c,	// 63.00		2.0994
	0x02a,	// 64.00		2.0235
	0x029,	// 65.00		1.9508
	0x028,	// 66.00		1.8810
	0x027,	// 67.00		1.8141
	0x025,	// 68.00		1.7499
	0x024,	// 69.00		1.6883
	0x023,	// 70.00		1.6292
	0x022,	// 71.00		1.5724
	0x021,	// 72.00		1.5179
	0x020,	// 73.00		1.4656
	0x01f,	// 74.00		1.4153
	0x01e,	// 75.00		1.3670
	0x01d,	// 76.00		1.3206
	0x01c,	// 77.00		1.2759
	0x01b,	// 78.00		1.2330
	0x01b,	// 79.00		1.1918
	0x01a,	// 80.00		1.1522
	0x019,	// 81.00		1.1140
	0x018,	// 82.00		1.0773
	0x018,	// 83.00		1.0420
	0x017,	// 84.00		1.0080
	0x016,	// 85.00		0.9753
	0x015,	// 86.00		0.9438
	0x015,	// 87.00		0.9135
	0x014,	// 88.00		0.8843
	0x014,	// 89.00		0.8562
	0x013,	// 90.00		0.8291
	0x012,	// 91.00		0.8030
	0x012,	// 92.00		0.7778
	0x011,	// 93.00		0.7536
	0x011,	// 94.00		0.7302
	0x010,	// 95.00		0.7076
	0x010,	// 96.00		0.6859
	0x0f,	// 97.00		0.6649
	0x0f,	// 98.00		0.6447
	0x0f,	// 99.00		0.6252
	0x0e,	// 100.00		0.6063
	0x0e,	// 101.00		0.5882
	0x0d,	// 102.00		0.5706
	0x0d,	// 103.00		0.5537
	0x0d,	// 104.00		0.5373
	0x0c,	// 105.00		0.5215
	0x0c,	// -30.00		203.5600
        0x0B,	// -30.00		203.5600
        0x0B,	// -30.00		203.5600
};
/*************************************************************************
 * Function Name: Timer0IntrHandler
 * Parameters: none
 *
 * Return: none
 *
 * Description: Timer 0 interrupt handler
 *
 *************************************************************************/
/*************************************************************************
 * Function Name: Clk_Init
 * Parameters: Int32U Frequency
 * Return: Int32U
 *
 * Description: Init clock system
 *
 *************************************************************************/
void Clk_Init (void)
{
  // 1. Clocking the controller from internal HSI RC (8 MHz)
  RCC_HSICmd(ENABLE);
  // wait until the HSI is ready
  while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

  // 2. Enable ext. high frequency OSC
  RCC_HSEConfig(RCC_HSE_ON);
  // wait until the HSE is ready
  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
  // 3. Init PLL
  RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // 72MHz
  RCC_PLLCmd(ENABLE);
  // wait until the PLL is ready
  while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
  // 4. Set system clock dividers
  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
  RCC_ADCCLKConfig(RCC_PCLK2_Div8);
  RCC_PCLK2Config(RCC_HCLK_Div1);//APB2
  RCC_PCLK1Config(RCC_HCLK_Div2);//APB1
  RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHB

#ifdef EMB_FLASH
  // 5. Init Embedded Flash
  // Zero wait state, if 0 < HCLK 24 MHz
  // One wait state, if 24 MHz < HCLK 56 MHz
  // Two wait states, if 56 MHz < HCLK 72 MHz
  // Flash wait state
  FLASH_SetLatency(FLASH_Latency_2);
  // Half cycle access
  FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
  // Prefetch buffer
  FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
#endif // EMB_FLASH
  // 5. Clock system from PLL
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}
/************************************************************************/
// Pos = (GetADC1Channel(ADC_Channel_15)*100);
/************************************************************************/
Int16U GetADC1Channel(Int8U chanel)
{
  // Configure channel
  ADC_RegularChannelConfig(ADC1, chanel, 1, ADC_SampleTime_55Cycles5);

  // Start the conversion
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  // Wait until conversion completion
  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);

  // Get the conversion value
  return ADC_GetConversionValue(ADC1);
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void InitADC1(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef   ADC_InitStructure;

  // ADC init
  // ADC Deinit
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  ADC_DeInit(ADC1);

  // RC5 - analog input
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
  GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)GPIO_Mode_AIN;
  GPIO_Init (GPIOC, &GPIO_InitStructure);

  // ADC Structure Initialization
  ADC_StructInit(&ADC_InitStructure);

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  // Enable the ADC
  ADC_Cmd(ADC1, ENABLE);

  // ADC calibration
  // Enable ADC1 reset calibaration register
  ADC_ResetCalibration(ADC1);
  // Check the end of ADC1 reset calibration register
  while(ADC_GetResetCalibrationStatus(ADC1) == SET);

  // Start ADC1 calibaration
  ADC_StartCalibration(ADC1);
  // Check the end of ADC1 calibration
  while(ADC_GetCalibrationStatus(ADC1) == SET);

}



void  ADC_TEMP(Int16U *p)
{
	Int16U	a,c;
	Int32U  b;
        static	Int16U  ADC_COUNT;
	static	Int16U	TAD[8];
	a=GetADC1Channel(ADC_Channel_13);

⌨️ 快捷键说明

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