- #include"stm8s003k3.h"
- _Bool HOOKSW @PD_ODR:0
- _Bool BUTTON @PD_IDR:3
- _Bool BUTTON1 @PD_IDR:4
- _Bool JIANSHI @PD_ODR:5
- unsigned char temp;
- void GPIO_Init(void)//GPIO初始化
- {
- PD_DDR = 0XE7;//1110 0111
- PD_CR1 = 0XFF;//1111 1111
- PD_CR2 = 0X00;//0000 0000
- }
- void CLK_Init(void)
- {
- CLK_CKDIVR = 0X18
- }
- void tiM1_Init(void)
- {
- TIM1_CR1 = 0X08;
- TIM1_CR2 = 0X00;
- TIM1_IER = 0X01;
- TIM1_PSCRH = 0X4E
- TIM1_PSCRL = 0X20;
- TIM1_ARRH = 0X2E
- TIM1_ARRL = 0XE0;
- }
- void Delay_100ms(unsigned char k
- {
- unsigned int i,j;
- for(i=0;i<k;i++)
- for(j=0;j<14160;j++);
- }
- main()
- {
- _asm("sim");
- GPIO_Init();
- CLK_Init();
- TIM1_Init();
- _asm("rim")
- while(1)
- {
- temp=1
- while((BUTTON&&BUTTON1)!=0)
- if(BUTTON==0
- {
- HOOKSW=1;
- JIANSHI = 1;
- Delay_100ms(10)
- TIM1_CR1|=0X01
- while((BUTTON&&temp)!=0)
- HOOKSW=0;
- JIANSHI = 0;
- Delay_100ms(10)
- }
- else
- if(BUTTON1==0
- {
- JIANSHI = 1;
- HOOKSW=1;
- Delay_100ms(10)
- while(BUTTON1!=0)
- JIANSHI = 0;
- HOOKSW=0;
- Delay_100ms(10)
- }
- }
- }
- <a href="home.php?mod=space&uid=625061" target="_blank">@far</a> <a href="home.php?mod=space&uid=948404" target="_blank">@Interrupt</a> void TIM1_Over_Interrupt(void)
- {
- TIM1_SR1&=0XFE;//TIM1 更新中断标记 软件清零
- temp=0; //全局变量清零
- }
复制代码
MCU上电之后,第一次执行程序,当执行到while((BUTTON&&temp)!=0)按键等待程序时为什么没有经过TIM1延时就直接进入中断改变temp的值了 哪位大神 帮忙看下 谢谢 !!!
解决了 计数器初始化和开启时会产生更新事件 屏蔽 或者产生更新事件强制更新就好了
一周热门 更多>