这是disp.h
#ifndef _DISP_H_
#define _DISP_H_
extern void ddelay(unsigned char i);
///*显示数码*/
#ifdef _DISLED_
void display(unsigned char n,unsigned char s);
#endif
/*根据量程high-low,转换为十进制数*/
#ifdef _DECPV_
extern float DecToPv(unsigned char,float,float);
#endif
///*显示P E*/
#ifdef _DISERR_
extern void displayPErr();
#endif
#ifdef _DISI_
void make_led_inumber(int i_num);
void displayIF(int num);
#else
/** 制作数码管整数数据*/
void make_led_fnumber(float f_num);
void displayIF(float num);
#endif
#endif
disp.c
#include <reg52.h>
#include <intrins.h>
#include "disp.h"
extern unsigned int LED_buf[4];
extern unsigned char code LEDn[15]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,/*0-9*/0xff/*不显示*/,0xbf/*-*/,0x86/*E*/,0x7f/*小数点*/,0x8c/*p*/};
extern unsigned char code LEDs[4]={0xf7/*right*/,0xfb,0xfd,0xfe/*left*/};
void ddelay(unsigned char i)
{
unsigned char j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
#ifdef _DISLED_
void display(unsigned char n,unsigned char s)
{
P2=LEDs[s];
P0=LEDn[n];
}
#endif
#ifdef _DECPV_
/*char型转化为float,根据量程*/
float DecToPv(unsigned char in,float low,float high)
{
float ren;
ren=(high-low)*(float)((float)in/256);
return ren;
}
#endif
#ifdef _DISERR_
void displayPErr()
{
P0=0XFF; //P
P2=LEDs[3];
P0=LEDn[14];
//display(14,3);
ddelay(10);
P0=0XFF; //E
P2=LEDs[2];
P0=LEDn[12];
//display(12,2);
ddelay(10);
}
#endif
#ifdef _DISI_
/** 制作数码管整数数据*/
void make_led_inumber(int i_num)
{
bit s_flag=0;
int sit;
unsigned int i;
if (i_num < 0)
{
s_flag = 1;
i_num = -i_num;
}
// ET0 = 0;
for (i=2, sit=100; i>=1; i--, sit/=10)
{
if (i_num >= sit)
break;
LED_buf[i] = LEDn[10];
i_num -= i_num/sit*sit;
}
for (;i>=1; i--, sit/=10)
{
LED_buf[i] = LEDn[i_num/sit];
i_num -= i_num/sit*sit;
}
LED_buf[0] = LEDn[i_num] & 0x7F;
if (s_flag)
LED_buf[3] = LEDn[11];
else
LED_buf[3] = LEDn[10];
// ET0 = 1;
}
void displayIF(int num)
{
unsigned char Led_n=0;
make_led_inumber(num);
for(Led_n=0;Led_n<=3;Led_n++)
{
P0=0XFF;
P2=LEDs[Led_n];
P0=LED_buf[Led_n];
ddelay(5);
}
}
#else
/** 制作数码管浮点数据*/
void make_led_fnumber(float f_num)
{
bit s_flag=0;
int num;
int sit;
char i, decimal, dot_sit=0;
if (f_num < 0)
{
s_flag = 1;
f_num = -f_num;
}
num = (int)(f_num*100+0.5);
for (decimal=2; decimal>0; decimal--)
{
if (num % 10 != 0)
break;
num /= 10;
}
dot_sit = decimal;
if (f_num >= 100)
dot_sit = 0;
else if (f_num >= 10)
if (decimal >= 1)
dot_sit = 1;
else if (f_num >= 1)
if (decimal >= 2)
dot_sit = 2;
for (i=0; i<dot_sit; i++)
f_num *= 10;
num = (int)(f_num+0.5);
// ET0 = 0;
for (i=2, sit=100; i>=1; i--, sit/=10)
{
if (num >= sit)
break;
if (i == dot_sit)
break;
LED_buf[i] = LEDn[10];
num -= num/sit*sit;
}
for (;i>=1; i--, sit/=10)
{
LED_buf[i] = LEDn[num/sit];
num -= num/sit*sit;
}
LED_buf[0] = LEDn[num];
LED_buf[dot_sit] &= 0x7F;
if (s_flag)
LED_buf[3] = LEDn[11];
else
LED_buf[3] = LEDn[10];
// ET0 = 1;
}
void displayIF(float num)
{
unsigned char Led_n=0;
make_led_fnumber(num);
for(Led_n=0;Led_n<=3;Led_n++)
{
P0=0XFF;
P2=LEDs[Led_n];
P0 = LED_buf[Led_n];
ddelay(5);
}
}
#endif
这是主函数
#include<reg52.h>
#include <intrins.h>
#include "disp.h"
//#define _DISLED_
#define _DISERR_
void main(void)
{
while(1)
{
// float t;
// t= DecToPv(0x0a,0,256);
// display(2,2);
displayPErr();
// displayIF(-22.3);
// display(1,2);
// displayI(-56);
}
}
但是编译提示::
TEST1.C(21): warning C206: 'displayPErr': missing function-prototype
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: DISPLAYPERR
MODULE: test1.obj (TEST1)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
SYMBOL: DISPLAYPERR
MODULE: test1.obj (TEST1)
ADDRESS: 0010H
警示信息如何去掉??? |