高级会员

- 积分
- 642
- 金钱
- 642
- 注册时间
- 2017-7-25
- 在线时间
- 129 小时
|

楼主 |
发表于 2018-8-8 13:17:41
|
显示全部楼层
/******************** (C) COPYRIGHT Inchange ********************************
* ÎļtÃû £omain.c
* Ãèêö £oAVAS_Base
* ¿a°æ±¾ £oV1.5.0
* ×÷Õß £oJack/Dì3é
* °æ±¾¸üDÂ: 2017-11-22
* μ÷êÔ·½ê½£oJ-Link-OB
**********************************************************************************/
//í·Îļt
#include "stm32f0xx.h"
#include "sys.h"
#include "usart.h"
#include "gpio.h"
#include "timer.h"
#include "dac.h"
#include "can.h"
#include "adc.h"
#include "sound.h"
#include "app.h"
#include "stmflash.h"
#define Rr 0
#define Dd 1
#define Dd_Run 2
#define Rr_Run 3
void System_Init(void)
{
//NVIC_Config();
GPIO_Config();
//DAC_Config();
//TIM1_Cap_Config();
CAN_Config();
ADC_Config();
//TIM2_Config();
//UART_Config();
Timer_ms_Config();//¶¨ê±¼ä2ms
}
/**
* @file main
* @brief Main program.
* @param None
* @retval None
*/
float Temp_Value=0 ;
uint16_t ADC_Value=0,Resoult_Average=0;
uint8_t changeRr,changeDd;
uint8_t res;
uint16_t cn=0;
uint16_t cn1=0;
uint8_t RrDd;
uint8_t k,j,l;
uint8_t ADC_FlagRD=0x12;//3õÖμ
int main(void)
{
uint8_t i;
uint8_t tx_canbuf_5B1[8]={0xAA,0x14,0x1e,0x1e,0x10,0x14,0x14,0x14}; //μ÷½úéùÑ1¼¶
uint8_t tx_canbuf_1A0_R[8]={0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00}; //Rμμ
uint8_t tx_canbuf_1A0_D[8]={0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00}; //Dμμ
System_Init();
changeRr=0x1e;
changeDd=0x21;
k=0;
l=0;
j=0;
// ADC_FlagRD=0x00;
RrDd=0;
while (1)
{
if(k<1)
{
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_1A0_R, 8, 0x1A0);
k++;
if(k==1)
k=4;
}
switch(RrDd)
{
case 0:
// Temp_Value = (3.3/4096)* Resoult_Average;
if(cn1>500)
{
Temp_Value = (3.3/4096)* Resoult_Average;
// Temp_Value=2.0;
if(Temp_Value)
{
if(Temp_Value>1.82&&Temp_Value<1.90)
{
ADC_FlagRD=0x00;
}
else if(Temp_Value<1.82)
{
ADC_FlagRD=0x01;
}
else if(Temp_Value>1.90)
{
ADC_FlagRD=0x02;
}
Temp_Value=0.00;
Resoult_Average=0;
}
cn1=0;
}
break;
case 1:
// if(RrDd==1)
// {
if(cn>720)
{
Temp_Value = (3.3/4096)* Resoult_Average;
if(Temp_Value)
{
if(Temp_Value>1.370&&Temp_Value<1.6)
{
RrDd=2;
ADC_FlagRD=0x05;
}
else if(Temp_Value<1.370)
{
ADC_FlagRD=0x03;
}
else if(Temp_Value>1.6)
{
ADC_FlagRD=0x04;
}
Temp_Value=0.00;
Resoult_Average=0;
}
cn=0;
}
// }
break;
}
if(ADC_FlagRD==0x00)
{
if(j<1)
{
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_1A0_D, 8, 0x1A0);
j++;
if(j==1)
j=4;
}
RrDd=1;
} else if(ADC_FlagRD==0x01)
{
changeRr=changeRr+1;
tx_canbuf_5B1[3]=changeRr;
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_5B1, 8, 0x5b1);
if(changeRr>0x2f)
{
ADC_FlagRD=0x05;
}
}else if(ADC_FlagRD==0x02)
{
changeRr=changeRr-1;
tx_canbuf_5B1[3]=changeRr;
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_5B1, 8, 0x5b1);
ADC_FlagRD=0x05;
if(changeRr<0x1d)
{
ADC_FlagRD=0x00;
break;
}
}else if(ADC_FlagRD==0x03)
{
changeDd=changeDd+1;
if(changeDd>0x3f)
{
break;
}
tx_canbuf_5B1[3]=changeRr;
tx_canbuf_5B1[4]=changeDd;
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_5B1, 8, 0x5b1);
ADC_FlagRD=0x05;
}else if(ADC_FlagRD==0x04)
{
changeDd=changeDd-1;
if(changeDd<0x1d)
{
break;
}
tx_canbuf_5B1[3]=changeRr;
tx_canbuf_5B1[4]=changeDd;
for(i=0;i<100;i++)
res = CAN_Send_Msg(tx_canbuf_5B1, 8, 0x5b1);
ADC_FlagRD=0x05;
}
// if(ADC_FlagRD==0x05)//ìí¼óoóRμμ¾í2»ÄüÔù¸Ä¶ˉoóìø½øDμμáË£¬»á½øèëËàÑ-»·
// {
// break;
// }
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
|
|