求教,STM8程序下载不进去???能下载进去 能调试 就是下载后断电在上电 就不能实现功能了。就是下面的代码。我用的STtoolset。
#include "stm8s103f.h"
#include "math.h"
#define N 128
int AD_buf[N];
//int ad_buf[N];
int *pdata;
unsigned int cunt=0;
double sum=0;
unsigned int flag=0;
//int max=0;
//int min=1000;
void output(int data)
{
int mid1;
int mid2;
double average;
int y;
unsigned char i;
// int a=1,b=2,c=3;
//double d=1;
// pdata=&b;
average=sum/N;
//y=(max-min)/32;
mid1=average+5;
mid2=average-5;
//if(ad_buf[i]>mid1)
//PA_ODR=0x08;
//else if(ad_buf[i]<mid2)
//PA_ODR=0x00;
// if(*pdata>d)
if(*pdata>mid1)
//PA_ODR=~PA_ODR;
PA_ODR=0x08;
//else if(*pdata<c)
//PA_ODR=0x00;
else if (*pdata<mid2)
//PA_ODR=~PA_ODR;
PA_ODR=0x00;
// if(AD_buf[cunt-1]>max) max=AD_buf[cunt-1];
// else if (AD_buf[cunt-1]>min) min=AD_buf[cunt-1];
sum=sum+data-*pdata;
*pdata=data;
pdata++;
if(pdata==(AD_buf+N))
pdata=AD_buf;
/* sum=sum+data-ad_buf[i];
ad_buf[i]=data;
i++;
if(i=N)
ad_buf=AD_buf;*/
}
void filter(int data)
{
AD_buf[cunt++]=data;
sum+=data;
//if(AD_buf[cunt-1]>max) max=AD_buf[cunt-1];
// else if (AD_buf[cunt-1]>min) min=AD_buf[cunt-1];
if(cunt==N)
{
pdata=AD_buf;
//ad_buf=AD_buf;
flag=1;
}
}
@far @interrupt void TIM1_UPD_OVF_IRQHandler (void)
{
//volatile
int AD_Value;
unsigned char j;
TIM1_SR1 = 0x00;
//PA_ODR=~PA_ODR;
//ADC_CR1 |= 0x01;
j = 6;
while(j--)
ADC_CR1 |= 0x01;
while(!(ADC_CSR & 0x80));
AD_Value = ((((unsigned int)ADC_DRH)<<2)+ADC_DRL);
if(flag==1)
output(AD_Value);
else filter(AD_Value);
}
void CLK_Init(void)
{ CLK_ICKR=0x01;
CLK_CKDIVR = 0x08;
}
void GPIO_Init(void)
{
PA_DDR = 0x08;
PA_CR1 = 0x08;
PA_CR2 = 0x00;
}
void ADC_Init(void)
{
//CLK_PCKENR2 |=0X8;
ADC_CR2 |= 0x00;
ADC_CR1 = 0x21;
ADC_CSR = 0x04;
ADC_TDRL = 0x20;
}
void TIM1_init(void)
{
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0xF9;
TIM1_ARRH = 0x00;
TIM1_ARRL = 0x01;
TIM1_CR1 = 0x01;
TIM1_IER = 0x01;
}
void main(void)
{
_asm("sim");
CLK_Init();
GPIO_Init();
ADC_Init();
TIM1_init();
_asm("rim");
while(1)
{
}
} |