void TIM1_UP_IRQHandler(void)
{
extern u16 Am,y,Datavalue;
extern double da_w,y1;
DAC_InitTypeDef DAC_InitStructure;
static int iii=0;
if(TIM_GetITStatus(TIM1,TIM_IT_Update)!=RESET)
{
TIM_ClearITPendingBit(TIM1, TIM_FLAG_Update); //清中断标志
TIM1->SR&=~(1<<0);//再清除中断标志位 ~~清不掉啊~~ 寄存器的UIF位一直是打勾的~~
DAC_StructInit(&DAC_InitStructure); //把结构体的成员按初始值填入
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
// DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;//DAC_OutputBuffer_Enable;//
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE); //在通道使能之前PA4,PA5应先配置成模拟输入
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
y1=Am*sin(6.283*iii/100); //用正弦函数计算
y=Am+(int)y1;
if(iii==99)
iii=0;
else
iii=iii+1;
DAC_SetChannel1Data(DAC_Align_12b_R, y); //把要转换的值送入寄存器
DAC_DualSoftwareTriggerCmd(ENABLE); //使能软件触发,更新DAC的值
Datavalue=DAC_GetDataOutputValue(DAC_Channel_1);
}
}
定时器1中断函数,仿真的时候,寄存器的UIF位 一直都是打勾的,
|