OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2122|回复: 4

别的程序用的同样的led.c灯能亮,这个不能亮是什么原因呢。谢谢

[复制链接]

4

主题

13

帖子

0

精华

新手上路

积分
34
金钱
34
注册时间
2019-11-12
在线时间
6 小时
发表于 2019-12-19 11:08:31 | 显示全部楼层 |阅读模式
5金钱
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "kk.h"
//#include "dac.h"
#include "can.h"
#include "timer.h"

extern u8 canrxbuf[8];
extern u8 canrxid;
extern int x;
extern int t;
int main(void)  
   {
           u8 mode=0;                  //普通模式
           Stm32_Clock_Init(9);               //系统时钟设置
           uart_init(72,115200);            //串口初始化为115200
           delay_init(72);                               //延时初始化
           LED_Init();                                     //初始化与LED连接的硬件接口
//           Dac1_Init();
//           Dac2_Init();
           CAN_Mode_Init(1,8,9,8,mode);//CAN 初始化,波特率 250Kbps    36M/((1+8+9)*8)=250kbps
           KK_Init();                  //OUT初始化
           TIM3_Int_Init(99,7199);      //定时器3  100*7200/72=10ms
           while(1)
                   {
                           if(canrxid==0x23)
                              {
                                          if(canrxbuf[0]==0x04)        //机具下降
                                              {
                                                          KG1=1;
                              t=0;                                   //定时器中断清零                  
                                                          if(t==500)           //5s后停止输出
                                                             {
                                                                         KG1=0;
                                                                         canrxbuf[0]=0x00;
                                                             }
                                                  }
                                          if(canrxbuf[0]==0x08)        //机具上升
                                              {
                                                          KG2=1;
                                                          x=0;                 //定时器中断清零
                                                          if(x==500)
                                                             {
                                                                         KG2=0;
                                                                         canrxbuf[0]=0x00; //重置
                                                             }
                                              }       
                      if(canrxbuf[2]==0x10)
                                              {
                                                          KG3=1;
                                                  }
                      if(canrxbuf[2]==0x00)
                                              {
                                                          KG3=0;
                                              }                                                  
                                  }
                           KG4=1;                          
               delay_ms(200);                                  
              }
   }

最佳答案

查看完整内容[请看2#楼]

找到原因了。我的timer.c的中断函数清零位有问题,已解决,谢谢。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

4

主题

13

帖子

0

精华

新手上路

积分
34
金钱
34
注册时间
2019-11-12
在线时间
6 小时
 楼主| 发表于 2019-12-19 11:08:32 | 显示全部楼层
找到原因了。我的timer.c的中断函数清零位有问题,已解决,谢谢。
回复

使用道具 举报

4

主题

13

帖子

0

精华

新手上路

积分
34
金钱
34
注册时间
2019-11-12
在线时间
6 小时
 楼主| 发表于 2019-12-19 11:10:03 | 显示全部楼层
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "kk.h"
//#include "dac.h"
#include "can.h"
#include "timer.h"

extern u8 canrxbuf[8];
extern u8 canrxid;
extern int x;
extern int t;
int main(void)  
   {
           u8 mode=0;                  //普通模式
           Stm32_Clock_Init(9);               //系统时钟设置
           uart_init(72,115200);            //串口初始化为115200
           delay_init(72);                               //延时初始化
           LED_Init();                                     //初始化与LED连接的硬件接口
//           Dac1_Init();
//           Dac2_Init();
           CAN_Mode_Init(1,8,9,8,mode);//CAN 初始化,波特率 250Kbps    36M/((1+8+9)*8)=250kbps
           KK_Init();                  //OUT初始化
           TIM3_Int_Init(99,7199);      //定时器3  100*7200/72=10ms
           while(1)
                   {
                           if(canrxid==0x23)
                              {
                                          if(canrxbuf[0]==0x04)        //机具下降
                                              {
                                                          KG1=1;
                              t=0;                                   //定时器中断清零                  
                                                          if(t==500)           //5s后停止输出
                                                             {
                                                                         KG1=0;
                                                                         canrxbuf[0]=0x00;
                                                             }
                                                  }
                                          if(canrxbuf[0]==0x08)        //机具上升
                                              {
                                                          KG2=1;
                                                          x=0;                 //定时器中断清零
                                                          if(x==500)
                                                             {
                                                                         KG2=0;
                                                                         canrxbuf[0]=0x00; //重置
                                                             }
                                              }       
                      if(canrxbuf[2]==0x10)
                                              {
                                                          KG3=1;
                                                  }
                      if(canrxbuf[2]==0x00)
                                              {
                                                          KG3=0;
                                              }                                                  
                                  }
                           LED2=!LED2;                          
               delay_ms(200);                                  
              }
   }
重新上传一下。
回复

使用道具 举报

6

主题

1127

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1656
金钱
1656
注册时间
2019-8-15
在线时间
102 小时
发表于 2019-12-19 14:07:01 | 显示全部楼层
帮顶                                               
成功没有捷径
回复

使用道具 举报

4

主题

13

帖子

0

精华

新手上路

积分
34
金钱
34
注册时间
2019-11-12
在线时间
6 小时
 楼主| 发表于 2019-12-19 14:18:56 | 显示全部楼层
重新新建了一个工程,把程序放进去还是不行
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-27 05:25

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表