找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1498|回复: 6
打印 上一主题 下一主题
收起左侧

单片机程序帮找错,没通过编译,提示在:Delay()哪里

[复制链接]
跳转到指定楼层
楼主
ID:60021 发表于 2017-12-7 15:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<reg52.h>
#define uchar unsigned char                                             
#define uint unsigned int

sbit IR = P2^1;
sbit key1 = P1^1;
sbit key2 = P1^2;

void Delay();
void SendInstructionCode();
void SendCodeZero();
void SendCodeOne();
void UsrCode();
void Key1();
void Key2();
void KeyScan();
void SendKeyCode();

/*******发送引导码函数**********/
void SendInstructionCode()
{  
        TH0 = 0xDC;             //9000us  
        TL0 = 0xD8;   
        TR0 = 1;  
        IR = 0;                //拉低IR  
        while(!(TF0 == 1));    //等待定时器溢出,即使IR持续低电平9000us  
        IR = 1;  
        TF0 = 0;  
        TR0 = 0;  
    TH0 = 0xEE;            //4500us  
        TL0 = 0x6c;  
        TR0 = 1;  
        while(!(TF0 == 1));     //等待定时器溢出,即使IR持续高电平4500us  
        IR = 0;  
        TF0 = 0;  
        TR0 = 0;
}

/*********发送0函数*********/

void SendCodeZero()     
{  
        TH0 = 0xFD;      //560us  
        TL0 = 0xD0;   
        TR0 = 1;  
        IR = 0;  
        while(!(TF0 == 1));  
        IR = 1;  
        TF0 = 0;  
        TR0 = 0;   
        TH0 = 0xFD;      //560us  
        TL0 = 0xD0;  
        TR0 = 1;  
        while(!(TF0 == 1));  
        IR = 0;  
        TF0 = 0;  
        TR0 = 0;
}

/*********发送1函数*********/
void SendCodeOne()   
{
        TH0 = 0xFD;      //560us  
        TL0 = 0xD0;   
        TR0 = 1;  
        IR = 0;
        while(!(TF0 == 1));  
        IR = 1;  
        TF0 = 0;  
        TR0 = 0;   
        TH0 = 0xF9;      //1680us  
        TL0 = 0x70;  
        TR0 = 1;  
        while(!(TF0 == 1));  
        IR = 0;  
        TF0 = 0;  
        TR0 = 0;
}

/*********用户码函数*********/
void UsrCode()   //发送用户码 11111111  00000000
{  
        uchar i;
          for(i=0;i<8;i++)  
        {   
                SendCodeOne();  
        }  
        for(i=0;i<8;i++)  
        {   
                SendCodeZero();  
        }
}

/*********键值1函数********/
void Key1()   //0x3d  0011 1101   ~0x3d  1100 0010
{  
        SendCodeZero();
        SendCodeZero();  
        SendCodeOne();  
        SendCodeOne();
        SendCodeOne();  
        SendCodeOne();
        SendCodeZero();
        SendCodeOne();   
        SendCodeOne();  
        SendCodeOne();  
        SendCodeZero();
        SendCodeZero();
        SendCodeZero();
        SendCodeZero();
        SendCodeOne();
        SendCodeZero();
}

/*********键值2函数********/
void Key2()     //0xe3  1110 0011 ; ~0xe3  0001 1100
{  
        SendCodeOne();
        SendCodeOne();
        SendCodeOne();
        SendCodeZero();
        SendCodeZero();
        SendCodeZero();
        SendCodeOne();
        SendCodeOne();  
        SendCodeZero();
        SendCodeZero();
        SendCodeZero();
        SendCodeOne();
        SendCodeOne();
        SendCodeOne();
        SendCodeZero();
        SendCodeZero();
}

/*********按键扫描函数********/
void KeyScan()  //返回值是按下按键的按键值,没按下返回100,即不发送   
{  
        uchar key = 100;
        uchar keybuf [2]={ 1,1};
        static uchar backup[2]= { 1,1};  
        keybuf [0]= key1;  
        if(keybuf[0] != backup[0])  
        {   
                Delay(100);                     
                if(keybuf[0] == key1)   
                {
                        if(backup[0] == 0)
                    key = 1;   
                }  
        }  
        if(keybuf[1] != backup[1])  
        {   
                Delay(100);   
                if(keybuf[1] == key2)   
                {
                        if(backup[1] == 0)
                    key = 2;   
                }  
        }  
        return key;
}

/*********发送函数********/
void SendKeyCode(uchar key)   
{  
        if(key == 1)  
        {   
                SendInstructionCode();   
                UsrCode();   
                Key1();     
        }  
        if(key == 2)  
        {   
                SendInstructionCode();   
                UsrCode();   
                Key2();  
        }
}

void Delay(uint z)
{
        uint t1,y;
        for(t1=z; t1>0; t1--)
                for(y=110; y>0; y--);  
}

void main()
{  
        uchar key;   
        TMOD = 0x01;   
        while(1)  
        {   
                key = KeyScan();   
                SendKeyCode(key);  
        }
}  

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:60021 发表于 2017-12-7 15:59 | 只看该作者
Build target 'Target 1'
compiling IR_YK01.c...
IR_YK01.C(145): error C267: 'Delay': requires ANSI-style prototype
Target not created
回复

使用道具 举报

板凳
ID:155507 发表于 2017-12-7 16:46 | 只看该作者
试试看


  1. #include<reg52.h>
  2. #define uchar unsigned char                                             
  3. #define uint unsigned int

  4. sbit IR = P2^1;
  5. sbit key1 = P1^1;
  6. sbit key2 = P1^2;

  7. void Delay(uint z);
  8. void SendInstructionCode();
  9. void SendCodeZero();
  10. void SendCodeOne();
  11. void UsrCode();
  12. void Key1();
  13. void Key2();
  14. uchar KeyScan();
  15. void SendKeyCode(uchar key);

  16. /*******发送引导码函数**********/
  17. void SendInstructionCode()
  18. {  
  19.         TH0 = 0xDC;             //9000us  
  20.         TL0 = 0xD8;   
  21.         TR0 = 1;  
  22.         IR = 0;                //拉低IR  
  23.         while(!(TF0 == 1));    //等待定时器溢出,即使IR持续低电平9000us  
  24.         IR = 1;  
  25.         TF0 = 0;  
  26.         TR0 = 0;  
  27.         TH0 = 0xEE;            //4500us  
  28.         TL0 = 0x6c;  
  29.         TR0 = 1;  
  30.         while(!(TF0 == 1));     //等待定时器溢出,即使IR持续高电平4500us  
  31.         IR = 0;  
  32.         TF0 = 0;  
  33.         TR0 = 0;
  34. }

  35. /*********发送0函数*********/

  36. void SendCodeZero()     
  37. {  
  38.         TH0 = 0xFD;      //560us  
  39.         TL0 = 0xD0;   
  40.         TR0 = 1;  
  41.         IR = 0;  
  42.         while(!(TF0 == 1));  
  43.         IR = 1;  
  44.         TF0 = 0;  
  45.         TR0 = 0;   
  46.         TH0 = 0xFD;      //560us  
  47.         TL0 = 0xD0;  
  48.         TR0 = 1;  
  49.         while(!(TF0 == 1));  
  50.         IR = 0;  
  51.         TF0 = 0;  
  52.         TR0 = 0;
  53. }

  54. /*********发送1函数*********/
  55. void SendCodeOne()   
  56. {
  57.         TH0 = 0xFD;      //560us  
  58.         TL0 = 0xD0;   
  59.         TR0 = 1;  
  60.         IR = 0;
  61.         while(!(TF0 == 1));  
  62.         IR = 1;  
  63.         TF0 = 0;  
  64.         TR0 = 0;   
  65.         TH0 = 0xF9;      //1680us  
  66.         TL0 = 0x70;  
  67.         TR0 = 1;  
  68.         while(!(TF0 == 1));  
  69.         IR = 0;  
  70.         TF0 = 0;  
  71.         TR0 = 0;
  72. }

  73. /*********用户码函数*********/
  74. void UsrCode()   //发送用户码 11111111  00000000
  75. {  
  76.         uchar i;
  77.         for(i=0;i<8;i++)  
  78.         {   
  79.                 SendCodeOne();  
  80.         }  
  81.         for(i=0;i<8;i++)  
  82.         {   
  83.                 SendCodeZero();  
  84.         }
  85. }

  86. /*********键值1函数********/
  87. void Key1()   //0x3d  0011 1101   ~0x3d  1100 0010
  88. {  
  89.         SendCodeZero();
  90.         SendCodeZero();  
  91.         SendCodeOne();  
  92.         SendCodeOne();
  93.         SendCodeOne();  
  94.         SendCodeOne();
  95.         SendCodeZero();
  96.         SendCodeOne();   
  97.         SendCodeOne();  
  98.         SendCodeOne();  
  99.         SendCodeZero();
  100.         SendCodeZero();
  101.         SendCodeZero();
  102.         SendCodeZero();
  103.         SendCodeOne();
  104.         SendCodeZero();
  105. }

  106. /*********键值2函数********/
  107. void Key2()     //0xe3  1110 0011 ; ~0xe3  0001 1100
  108. {  
  109.         SendCodeOne();
  110.         SendCodeOne();
  111.         SendCodeOne();
  112.         SendCodeZero();
  113.         SendCodeZero();
  114.         SendCodeZero();
  115.         SendCodeOne();
  116.         SendCodeOne();  
  117.         SendCodeZero();
  118.         SendCodeZero();
  119.         SendCodeZero();
  120.         SendCodeOne();
  121.         SendCodeOne();
  122.         SendCodeOne();
  123.         SendCodeZero();
  124.         SendCodeZero();
  125. }

  126. /*********按键扫描函数********/
  127. uchar KeyScan()  //返回值是按下按键的按键值,没按下返回100,即不发送   
  128. {  
  129.         uchar key = 100;
  130.         uchar keybuf [2]={ 1,1};
  131.         static uchar backup[2]= { 1,1};  
  132.         keybuf [0]= key1;  
  133.         if(keybuf[0] != backup[0])  
  134.         {   
  135.                 Delay(100);                     
  136.                 if(keybuf[0] == key1)   
  137.                 {
  138.                         if(backup[0] == 0)
  139.                         key = 1;   
  140.                 }  
  141.         }  
  142.         if(keybuf[1] != backup[1])  
  143.         {   
  144.                 Delay(100);   
  145.                 if(keybuf[1] == key2)   
  146.                 {
  147.                         if(backup[1] == 0)
  148.                         key = 2;   
  149.                 }  
  150.         }  
  151.         return key;
  152. }

  153. /*********发送函数********/
  154. void SendKeyCode(uchar key)   
  155. {  
  156.         if(key == 1)  
  157.         {   
  158.                 SendInstructionCode();   
  159.                 UsrCode();   
  160.                 Key1();     
  161.         }  
  162.         if(key == 2)  
  163.         {   
  164.                 SendInstructionCode();   
  165.                 UsrCode();   
  166.                 Key2();  
  167.         }
  168. }

  169. void Delay(uint z)
  170. {
  171.         uint t1,y;
  172.         for(t1=z; t1>0; t1--)
  173.         for(y=110; y>0; y--);  
  174. }

  175. void main()
  176. {  
  177.         uchar key;   
  178.         TMOD = 0x01;   
  179.         while(1)  
  180.         {   
  181.                 key = KeyScan();   
  182.                 SendKeyCode(key);  
  183.         }
  184. }  


复制代码
回复

使用道具 举报

地板
ID:258478 发表于 2017-12-7 17:27 | 只看该作者
申明的问题,前面的声明是不带参的,但是你实际的是带参的,不是同一个。
回复

使用道具 举报

5#
ID:258770 发表于 2017-12-7 19:11 | 只看该作者
改下申明
回复

使用道具 举报

6#
ID:235264 发表于 2017-12-7 21:25 | 只看该作者
这个程序有几个问题 一个是你前面申明delay函数时没有传形参 二是你按键扫描函数 你定义的是void型 然而你还return key
回复

使用道具 举报

7#
ID:60021 发表于 2017-12-12 15:55 | 只看该作者
谢谢
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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