標(biāo)題:
單片機(jī)程序幫找錯(cuò),沒(méi)通過(guò)編譯,提示在:Delay()哪里
[打印本頁(yè)]
作者:
wsh62
時(shí)間:
2017-12-7 15:46
標(biāo)題:
單片機(jī)程序幫找錯(cuò),沒(méi)通過(guò)編譯,提示在:Delay()哪里
#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();
/*******發(fā)送引導(dǎo)碼函數(shù)**********/
void SendInstructionCode()
{
TH0 = 0xDC; //9000us
TL0 = 0xD8;
TR0 = 1;
IR = 0; //拉低IR
while(!(TF0 == 1)); //等待定時(shí)器溢出,即使IR持續(xù)低電平9000us
IR = 1;
TF0 = 0;
TR0 = 0;
TH0 = 0xEE; //4500us
TL0 = 0x6c;
TR0 = 1;
while(!(TF0 == 1)); //等待定時(shí)器溢出,即使IR持續(xù)高電平4500us
IR = 0;
TF0 = 0;
TR0 = 0;
}
/*********發(fā)送0函數(shù)*********/
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;
}
/*********發(fā)送1函數(shù)*********/
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;
}
/*********用戶碼函數(shù)*********/
void UsrCode() //發(fā)送用戶碼 11111111 00000000
{
uchar i;
for(i=0;i<8;i++)
{
SendCodeOne();
}
for(i=0;i<8;i++)
{
SendCodeZero();
}
}
/*********鍵值1函數(shù)********/
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函數(shù)********/
void Key2() //0xe3 1110 0011 ; ~0xe3 0001 1100
{
SendCodeOne();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
SendCodeZero();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
SendCodeZero();
SendCodeOne();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
}
/*********按鍵掃描函數(shù)********/
void KeyScan() //返回值是按下按鍵的按鍵值,沒(méi)按下返回100,即不發(fā)送
{
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;
}
/*********發(fā)送函數(shù)********/
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);
}
}
作者:
wsh62
時(shí)間:
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
作者:
angmall
時(shí)間:
2017-12-7 16: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(uint z);
void SendInstructionCode();
void SendCodeZero();
void SendCodeOne();
void UsrCode();
void Key1();
void Key2();
uchar KeyScan();
void SendKeyCode(uchar key);
/*******發(fā)送引導(dǎo)碼函數(shù)**********/
void SendInstructionCode()
{
TH0 = 0xDC; //9000us
TL0 = 0xD8;
TR0 = 1;
IR = 0; //拉低IR
while(!(TF0 == 1)); //等待定時(shí)器溢出,即使IR持續(xù)低電平9000us
IR = 1;
TF0 = 0;
TR0 = 0;
TH0 = 0xEE; //4500us
TL0 = 0x6c;
TR0 = 1;
while(!(TF0 == 1)); //等待定時(shí)器溢出,即使IR持續(xù)高電平4500us
IR = 0;
TF0 = 0;
TR0 = 0;
}
/*********發(fā)送0函數(shù)*********/
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;
}
/*********發(fā)送1函數(shù)*********/
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;
}
/*********用戶碼函數(shù)*********/
void UsrCode() //發(fā)送用戶碼 11111111 00000000
{
uchar i;
for(i=0;i<8;i++)
{
SendCodeOne();
}
for(i=0;i<8;i++)
{
SendCodeZero();
}
}
/*********鍵值1函數(shù)********/
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函數(shù)********/
void Key2() //0xe3 1110 0011 ; ~0xe3 0001 1100
{
SendCodeOne();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
SendCodeZero();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
SendCodeZero();
SendCodeOne();
SendCodeOne();
SendCodeOne();
SendCodeZero();
SendCodeZero();
}
/*********按鍵掃描函數(shù)********/
uchar KeyScan() //返回值是按下按鍵的按鍵值,沒(méi)按下返回100,即不發(fā)送
{
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;
}
/*********發(fā)送函數(shù)********/
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);
}
}
復(fù)制代碼
作者:
ainorah
時(shí)間:
2017-12-7 17:27
申明的問(wèn)題,前面的聲明是不帶參的,但是你實(shí)際的是帶參的,不是同一個(gè)。
作者:
BanBan10032
時(shí)間:
2017-12-7 19:11
改下申明
作者:
voner
時(shí)間:
2017-12-7 21:25
這個(gè)程序有幾個(gè)問(wèn)題 一個(gè)是你前面申明delay函數(shù)時(shí)沒(méi)有傳形參 二是你按鍵掃描函數(shù) 你定義的是void型 然而你還return key
作者:
wsh62
時(shí)間:
2017-12-12 15:55
謝謝
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1