[51单片机]

初学者51单片机定时疑问

[复制链接]
752|6
手机看帖
扫描二维码
随时随地手机跟帖
快鲨1|  楼主 | 2019-1-10 07:26 | 显示全部楼层 |阅读模式
#include<reg52.h>

unsigned int code LedChar[]={
    0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
    0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e
};


void main()
{
    unsigned int sec = 0;
    while(1)
    {
        if(sec<=16)
        {
        P0=LedChar[sec];
    InitTimer0();
        sec++;
        }
        sec=0;
    }
}


void InitTimer0(void)
{
    TMOD = 0x01;
    TH0 = 0x0EE;
    TL0 = 0x00;
    TR0 = 1;
}

错误提示:
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling 静态显示代码.c...
静态显示代码.c(17): warning C206: 'InitTimer0': missing function-prototype
静态显示代码.c(26): error C231: 'InitTimer0': redefinition
静态显示代码.c(31): error C231: 'InitTimer0': redefinition
Target not created.
Build Time Elapsed:  00:00:01



我这个InitTimer0函数是用单片机小精灵算出来的,难道还有错不成?


相关帖子

ayb_ice| | 2019-1-10 08:42 | 显示全部楼层
#include<reg52.h>
void InitTimer0(void);
...

使用特权

评论回复
千岁寒| | 2019-1-10 10:32 | 显示全部楼层
warning C206: 'InitTimer0': missing function-prototype   在main函数之前声明 'InitTimer0'
error C231: 'InitTimer0': redefinition  检查一下别处哪里重复定义了

使用特权

评论回复
首先  TH0赋值错误

使用特权

评论回复
还有调用函数  应该在主函数前面声明

使用特权

评论回复
快鲨1|  楼主 | 2019-1-13 07:07 | 显示全部楼层
谢谢各位的解答!

使用特权

评论回复
cchsprite| | 2019-1-13 09:23 | 显示全部楼层
你这个没有进入定时器中断,只是开定时器而己。这是你想要的?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

45

帖子

0

粉丝