OpenEdv-开源电子网

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

请大家帮我看一下这个程序哪里有问题,我想用定时器实现方波的输出

[复制链接]

12

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2017-7-19
在线时间
10 小时
发表于 2017-7-20 13:41:24 | 显示全部楼层 |阅读模式
1金钱
#include "delay.h"
#include "sys.h"
#include "timer.h"
//ALIENTEK Mini STM32¿a·¢°å·¶ày′úÂë7
//¶¨ê±Æ÷ÖD¶ÏêμÑé   
//¼¼êõÖ§3Ö£owww.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
int main(void)
{       
            //Ñóê±oˉêy3õê¼»ˉ
        // éèÖÃÖD¶ÏóÅÏè¼¶·Ö×é2
         GPIO_InitTypeDef GPIO_InitStructure;
        TIM3_Int_Init(4999,7199);//10KhzμļÆêyÆμÂ꣬¼Æêyμ½5000Îa500ms  
        //ê1ÄüA6¿ú£¬2¢½øDDÅäÖÃ
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //TIM_CH1
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  //¸′óÃíÆíìêä3ö
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

          int TIM3_IRQHandler();
         GPIO_SetBits(GPIOA,GPIO_Pin_6);
          int TIM3_GetCounter ();
         if (TIM_GetCounter >=300)
         {
                 GPIO_ResetBits(GPIOA,GPIO_Pin_6);
                 
         }
                 
                 
                 
       
         
         
}
以上是主函数,编译后是以下问题
Build target 'Target 1'
compiling main.c...
main.c(22): error:  #268: declaration may not appear after executable statement in block
          int TIM3_IRQHandler();
main.c(24): error:  #268: declaration may not appear after executable statement in block
          int TIM3_GetCounter ();
main.c(25): error:  #42: operand types are incompatible ("uint16_t (*)(TIM_TypeDef *)" and "int")
         if (TIM_GetCounter >=300)
main.c: 0 warnings, 3 errors
"..\OBJ\TIMER.axf" - 3 Error(s), 0 Warning(s).
Target not created.


最佳答案

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

compiling main.c... main.c(23): warning: #223-D: function "TIM3_IRQHandler" declared implicitly TIM3_IRQHandler(); main.c(25): warning: #223-D: function "TIM3_GetCounter" declared implicitly TIM3_GetCounter(); main.c: 2 warnings, 0 errors "main.c" - 0 Error(s), 2 Warning(s).
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

12

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2017-7-19
在线时间
10 小时
 楼主| 发表于 2017-7-20 13:41:25 | 显示全部楼层
苻轩宇1993 发表于 2017-7-20 14:05
你调用函数还带什么函数类型?把“int”去掉,就是把“int TIM3_IRQHandler();”、“int TIM3_GetCounter ( ...

compiling main.c...
main.c(23): warning:  #223-D: function "TIM3_IRQHandler" declared implicitly
         TIM3_IRQHandler();
main.c(25): warning:  #223-D: function "TIM3_GetCounter" declared implicitly
         TIM3_GetCounter();
main.c: 2 warnings, 0 errors
"main.c" - 0 Error(s), 2 Warning(s).
回复

使用道具 举报

2

主题

26

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
203
金钱
203
注册时间
2017-7-6
在线时间
45 小时
发表于 2017-7-20 14:05:46 | 显示全部楼层
你调用函数还带什么函数类型?把“int”去掉,就是把“int TIM3_IRQHandler();”、“int TIM3_GetCounter ();”这两个改为“TIM3_IRQHandler();”、“TIM3_GetCounter ();”。“if (TIM_GetCounter >=300)”这里改为“if (TIM_GetCounter() >=300)”,建议你还是把C语言学好吧!
回复

使用道具 举报

12

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2017-7-19
在线时间
10 小时
 楼主| 发表于 2017-7-20 14:37:14 | 显示全部楼层
苻轩宇1993 发表于 2017-7-20 14:05
你调用函数还带什么函数类型?把“int”去掉,就是把“int TIM3_IRQHandler();”、“int TIM3_GetCounter ( ...

恩恩,那两个问题后来检查的时候都改过来了,可是有两个警告是怎么回事呢?
Build target 'Target 1'
linking...
..\OBJ\TIMER.axf: Error: L6218E: Undefined symbol TIM3_GetCounter (referred from main.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
"..\OBJ\TIMER.axf" - 1 Error(s), 0 Warning(s).
Target not created.
回复

使用道具 举报

2

主题

26

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
203
金钱
203
注册时间
2017-7-6
在线时间
45 小时
发表于 2017-7-20 15:06:39 | 显示全部楼层
你的名字 发表于 2017-7-20 14:37
compiling main.c...
main.c(23): warning:  #223-D: function "TIM3_IRQHandler" declared implicitly
...

检查一下这两个函所在的xxx.c文件,然后看这xxx.h有没有加入到main.c文件上面,即“#include “xxx.h””
回复

使用道具 举报

12

主题

25

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2017-7-19
在线时间
10 小时
 楼主| 发表于 2017-7-20 15:58:11 | 显示全部楼层
谢谢,已经解决了
回复

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-4-25 06:37

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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