:2.391KB : :1 :2022-10-11 17:34:21
STM8S003透传如果开发者对于本文件有需要的可以参考。
通过STM8S003单片机使用蓝牙透传实现简单物联网
void main(void)
{
CLK_DeInit();
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
TIM4_DeInit();
GPIO_Config();
TIM1_DeInit();
TIM1_PWMSTOP();
TIM4_Config();
uart_init();
asm("rim"); //开总中断
GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_HIGH_FAST);
t=1;
arand=10;
GetBAT();
GUA_ADC1_ReadAverage();
value2=value1;
while (1)
{
Charge();
if(tt)
{
TIM1_PWMSTOP();
time_cnt=0; GetBAT();
GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_HIGH_SLOW);
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_SLOW);
GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);
if(limadd<20)
{lastadd=0; arand ; if(arand>=100){arand=10;} }
else
{
limadd=0; GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);
}
if(GPIOC->IDR & GPIO_PIN_7){ t=1; }
if(!(GPIOA->IDR & GPIO_PIN_1)){CHRG=0;}
else {CHRG=1;}
if(!(GPIOD->IDR & GPIO_PIN_4)){STDBY=0;}
else {STDBY=1;}
break;
}
static uint16_t count_i=0 ,ad0,ad0_max, ad0_last,ad0_min =0;
int ad0_buf_number=1000, power_off_remain_timer = 0;
static uint16_t ad1, ad1_last, ad1_min = 0 , ad1_max = 0;
power_off_remain_timer=7000 - lastaddPower;
pwm_out();
GetAD3();
count_i ;
ad0 =value;
ad0_max = ad0 > ad0_last?ad0:ad0_last;
ad0_min = ad0 < ad0_last?ad0:ad0_last;
ad0_last = ad0;
ad1 = value1;
ad1_max = ad1 > ad1_last?ad1:ad1_last;
ad1_min = ad1 < ad1_last?ad1:ad1_last;
ad1_last = ad1;
if(count_i >= ad0_buf_number)
{
//
if(ad0_max - ad0_min >=45)
{lastadd = 0; flaga=30;lastaddPower=0;}
else
{
flaga=0;
if( power_off_remain_timer > ad0_buf_number)
{power_off_remain_timer -= ad0_buf_number;}
else
{ tt=1; limadd=0; }
}
ad0 = ad0_last =( ad0_last ad0) >> 1;
ad1 = ad1_last =( ad1_last ad1) >> 1;
count_i=0;
//data_flame[9]= ad1_max-ad1_min;
}
if(!(GPIOA->IDR & GPIO_PIN_1)){CHRG=0;}
else {CHRG=1;}
if(!(GPIOD->IDR & GPIO_PIN_4)){STDBY=0;}
else {STDBY=1;}
//GetBAT();
//Battery();
GUA_ADC1_ReadAverage();
ConvertSend();
GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Config();
if(!(GPIOA->IDR & GPIO_PIN_1)){CHRG=0;}
else {CHRG=1;}
if(!(GPIOD->IDR & GPIO_PIN_4)){STDBY=0;}
else {STDBY=1;}
if(time_cnt>=308000){t=0; while(c>0){uart_write(data_flame);c--;} }
else
{
if(m>800)
{
if(flaga>=30)
{
for(acnt=3;acnt<9;acnt )
{
divide=308000/acount[acnt];
if(time_cnt>=divide){timeadd=time_cnt/divide;}
data_flame[acnt]=timeadd;
if(data_flame[acnt]>=acount[acnt])
{data_flame[acnt]=acount[acnt]; }
}
}
uart_write(data_flame);
m=0;
}
}
if(t==0){break;}
if(CHRG==0 && STDBY==1){t=0;break;}
}
}
10-16CC2530实现无线串口透传
10-12STM32将数据包上传到有人透传云代码
10-12STM8S003工程模板
10-11NRF24L01串口透传.uvprojx
10-11串口透传代码
09-24SIMCOM 7600(TCP透传代码)