21ic问答首页 - 求助,函数没写到主函数里,为什么能执行成功
求助,函数没写到主函数里,为什么能执行成功
XCentury2021-02-07
void SMG_Play()该函数没写到主函数里,但是一个错误和警告都没有,而且该函数还执行成功了?为什么??求助
#include <STC15F2K60S2.H>
#include <onewire.h>
unsigned char code SMG_Select_1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
unsigned int temp=0;
unsigned char c=0;
unsigned char b=0;
void SMG_Play();
void SCQ_Set(unsigned char a)
{
switch(a)
{
case 4:P2=(P2&0x1f)|0x80;
break;
case 5:P2=(P2&0x1f)|0xa0;
break;
case 6:P2=(P2&0x1f)|0xc0;
break;
case 7:P2=(P2&0x1f)|0xe0;
break;
case 0:P2=(P2&0x1f)|0x00;
break;
}
}
void Delay_1(unsigned int t)
{
while(t--);
}
void Delay_SMG(unsigned int t)
{
while(t--)
{
SMG_Play();
}
}
void SMG_Set(unsigned char num,unsigned char loc)
{
SCQ_Set(6);
P0=0x01<<loc;
SCQ_Set(7);
P0=num;
}
void DS18B20_Set() //设置温度传感器
{
unsigned char MSB;
unsigned char LSB;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay_SMG(200);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
Delay_SMG(200);
LSB=Read_DS18B20();
MSB=Read_DS18B20();
temp=MSB<<4;
temp |=(LSB>>4);
}
void SMG_Play()
{
SMG_Set(SMG_Select_1[16],0);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[0],1);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[16],2);
Delay_1(100);P0=0xff;
SMG_Set(0xff,3);
Delay_1(100);P0=0xff;
SMG_Set(0xff,4);
Delay_1(100);P0=0xff;
SMG_Set(0xff,5);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[temp/10],6);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[temp%10],7);
Delay_1(100);P0=0xff;
}
void main()
{
P2=0x80;P0=0xff;
P2=0xa0;P0=0x00; //初始化
while(1)
{
DS18B20_Set();
}
}
#include <STC15F2K60S2.H>
#include <onewire.h>
unsigned char code SMG_Select_1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
unsigned int temp=0;
unsigned char c=0;
unsigned char b=0;
void SMG_Play();
void SCQ_Set(unsigned char a)
{
switch(a)
{
case 4:P2=(P2&0x1f)|0x80;
break;
case 5:P2=(P2&0x1f)|0xa0;
break;
case 6:P2=(P2&0x1f)|0xc0;
break;
case 7:P2=(P2&0x1f)|0xe0;
break;
case 0:P2=(P2&0x1f)|0x00;
break;
}
}
void Delay_1(unsigned int t)
{
while(t--);
}
void Delay_SMG(unsigned int t)
{
while(t--)
{
SMG_Play();
}
}
void SMG_Set(unsigned char num,unsigned char loc)
{
SCQ_Set(6);
P0=0x01<<loc;
SCQ_Set(7);
P0=num;
}
void DS18B20_Set() //设置温度传感器
{
unsigned char MSB;
unsigned char LSB;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay_SMG(200);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
Delay_SMG(200);
LSB=Read_DS18B20();
MSB=Read_DS18B20();
temp=MSB<<4;
temp |=(LSB>>4);
}
void SMG_Play()
{
SMG_Set(SMG_Select_1[16],0);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[0],1);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[16],2);
Delay_1(100);P0=0xff;
SMG_Set(0xff,3);
Delay_1(100);P0=0xff;
SMG_Set(0xff,4);
Delay_1(100);P0=0xff;
SMG_Set(0xff,5);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[temp/10],6);
Delay_1(100);P0=0xff;
SMG_Set(SMG_Select_1[temp%10],7);
Delay_1(100);P0=0xff;
}
void main()
{
P2=0x80;P0=0xff;
P2=0xa0;P0=0x00; //初始化
while(1)
{
DS18B20_Set();
}
}
赞0
main -- DS18B20_Set -- Delay_SMG -- SMG_Play
评论
2021-02-07
谢谢,刚刚休息睡了一觉,回来再看清晰多了,之前太累了这么简单都没转过来
赞0
评论
2021-02-08
赞0
评论
2021-02-08
您需要登录后才可以回复 登录 | 注册