共2条
1/1 1 跳转至页
第一次用C 遇到奇怪的问题 望高手帮忙看看
问
#include <reg52.h>
typedef unsigned char uchar;
//油箱液面检测输入点
sbit p_in_oil_a_1=P1^0;
sbit p_in_oil_a_2=P1^1;
sbit p_in_oil_a_3=P1^2;
sbit p_in_oil_b_1=P1^3;
sbit p_in_oil_b_2=P1^4;
sbit p_in_oil_b_3=P1^5;
//用液信号输入
sbit p_in_oil_flow=P1^6;
//键盘输入
sbit p_in_key1=P0^0;
sbit p_in_key2=P0^1;
sbit p_in_key3=P0^2;
sbit p_in_key4=P0^3;
//报警量输出
sbit p_out_w_pre=P1^7;
sbit p_out_w_pwr=P3^5;
sbit p_out_w_burst=P3^6;
sbit p_out_w_oila=P0^6;
sbit p_out_w_oilb=P0^7;
//控制信号输出
sbit p_out_oila=P0^4;
sbit p_out_oilb=P0^5;
sbit p_out_power_c=P2^6;
//AD转换
sbit p_ad_cs=P3^4;
sbit p_ad_di=P2^2;
sbit p_ad_do=P2^1;
sbit p_ad_clk=P2^0;
//24C01
sbit p_24cx_sda=P2^5;
sbit p_24cx_scl=P2^4;
sbit p_24cx_wr_c=P2^3;
//LED清0
sbit p_clr_led=P2^7;
sbit acc_7=ACC^7;
uchar code ch_data_press_now[256]={0};//未计算出来
void main()
{
void tlc_0832_sCAN();
void tlc_0832_handle();
uchar ch_data_collect[18],ch_data_collect_times,ch_data_press_now;
ch_data_collect_times=18;//初始化采集次数
// 压力采集
tlc_0832_sCAN(&ch_data_collect_times,ch_data_collect);
tlc_0832_handle(&ch_data_collect_times,&ch_data_press_now,ch_data_collect);
}
void tlc_0832_sCAN(times,collect_data)
uchar *times,collect_data[18];
{
uchar i;
*times--;
p_ad_clk=0; //使能 ad
p_ad_cs=0;
p_ad_di=1; // 写控制字到AD,H0为+,单痛道采集
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=1;
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=0;
p_ad_clk=1;
p_ad_clk=0;
p_ad_clk=1;
for(i=0;i++;i<15){ // 采集一个数据点
p_ad_clk=0;
acc_7=p_ad_do;
ACC>>1;
p_ad_clk=1;
}
p_ad_cs=1;
collect_data[*times]=ACC;//保存采集到的数据
}
void tlc_0832_handle(times,press_now,collect_data)
uchar *times,*press_now,collect_data[18];
{
uchar i,j,collect_max=0;
if(*times=0){ //18个点全部采集完?
*times=18;
for(i=17;i--;i>=0){ //对采集到的18个点排序(增序)
for(j=0;j++;j<i){
if(collect_data[i]<collect_data[j]){
collect_max=collect_data[j];
collect_data[j]=collect_data[i];
collect_data[i]=collect_max;
}
}
}
for(i=1;i++;i<17){
collect_data[i] >> 4; //去掉两个极值,然后取平均值
}
collect_max=0;
for(i=1;i++;i<17){
collect_max=collect_max+collect_data[i];
*press_now=ch_data_press_now[collect_max]; //查表并返回当前压力值
}
}
}
Build target 'Target 1'
compiling MAIN.C...
MAIN.C(57): error C267: 'tlc_0832_sCAN': requires ANSI-style prototype
Target not created
为什么会有这个错误啊,在函数调用时C51和标准C有什么不同吗 ??
望各位赐教!!!感激不尽!!!! 答 1: 我找到问题了 呵呵 自己太粗心了 答 2: 没法说你的程序太多语法错误,requires ANSI-style prototype是没有函数声明.
你的程序我重新编译了一下,我也是新手.
你看看能不能用.
#include <reg52.h>
typedef unsigned char uchar;
//ÓÍÏäÒºÃæ¼ì²âÊäÈëµã
sbit p_in_oil_a_1=P1^0;
sbit p_in_oil_a_2=P1^1;
sbit p_in_oil_a_3=P1^2;
sbit p_in_oil_b_1=P1^3;
sbit p_in_oil_b_2=P1^4;
sbit p_in_oil_b_3=P1^5;
//ÓÃÒºÐźÅÊäÈë
sbit p_in_oil_flow=P1^6;
//¼üÅÌÊäÈë
sbit p_in_key1=P0^0;
sbit p_in_key2=P0^1;
sbit p_in_key3=P0^2;
sbit p_in_key4=P0^3;
//±¨¾¯Á¿Êä³ö
sbit p_out_w_pre=P1^7;
sbit p_out_w_pwr=P3^5;
sbit p_out_w_burst=P3^6;
sbit p_out_w_oila=P0^6;
sbit p_out_w_oilb=P0^7;
//¿ØÖÆÐźÅÊä³ö
sbit p_out_oila=P0^4;
sbit p_out_oilb=P0^5;
sbit p_out_power_c=P2^6;
//ADת»»
sbit p_ad_cs=P3^4;
sbit p_ad_di=P2^2;
sbit p_ad_do=P2^1;
sbit p_ad_clk=P2^0;
//24C01
sbit p_24cx_sda=P2^5;
sbit p_24cx_scl=P2^4;
sbit p_24cx_wr_c=P2^3;
//LEDÇå0
sbit p_clr_led=P2^7;
sbit acc_7=ACC^7;
void tlc_0832_sCAN(uchar *times,uchar collect_data[18]);
void tlc_0832_handle(uchar *times,uchar *press_now,uchar collect_data[18]);
uchar code ch_data_press_now[256]={0};//δ¼ÆËã³öÀ´
void main()
{
uchar ch_data_collect[18],ch_data_collect_times,ch_data_press_now;
ch_data_collect_times=18;//³õʼ»¯²É¼¯´ÎÊý
// ѹÁ¦²É¼¯
tlc_0832_sCAN(&ch_data_collect_times,ch_data_collect);
tlc_0832_handle(&ch_data_collect_times,&ch_data_press_now,ch_data_collect);
}
void tlc_0832_sCAN(uchar *times,uchar collect_data[18])
// uchar *times,collect_data[18];
{
uchar i;
times--;
p_ad_clk=0; //ʹÄÜ ad
p_ad_cs=0;
p_ad_di=1; // д¿ØÖÆ×Öµ½AD£¬H0Ϊ+£¬µ¥Í´µÀ²É¼¯
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=1;
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=0;
p_ad_clk=1;
p_ad_clk=0;
p_ad_clk=1;
for(i=0;i++;i<15)
{ // ²É¼¯Ò»¸öÊý¾Ýµã
p_ad_clk=0;
acc_7=p_ad_do;
ACC>>=1;
p_ad_clk=1;
}
p_ad_cs=1;
collect_data[*times]=ACC;//±£´æ²É¼¯µ½µÄÊý¾Ý
}
void tlc_0832_handle(uchar *times,uchar *press_now,uchar collect_data[18])
// uchar *times,*press_now,collect_data[18];
{
uchar i,j,collect_max=0;
if(*times==0)
{ //18¸öµãÈ«²¿²É¼¯Íꣿ
*times=18;
for(i=17;i--;i>=0)
{ //¶Ô²É¼¯µ½µÄ18¸öµãÅÅÐò(ÔöÐò)
for(j=0;j++;j<i)
{
if(collect_data[i]<collect_data[j])
{
collect_max=collect_data[j];
collect_data[j]=collect_data[i];
collect_data[i]=collect_max;
}
}
}
for(i=1;i++;i<17)
{
collect_data[i] >>= 4; //È¥µôÁ½¸ö¼«Öµ,È»ºóȡƽ¾ùÖµ
}
collect_max=0;
for(i=1;i++;i<17)
{
collect_max=collect_max+collect_data[i];
*press_now=ch_data_press_now[collect_max]; //²é±í²¢·µ»Øµ±Ç°Ñ¹Á¦Öµ
}
}
} 答 3: 把函数放在main()前 答 4: 谢谢了
typedef unsigned char uchar;
//油箱液面检测输入点
sbit p_in_oil_a_1=P1^0;
sbit p_in_oil_a_2=P1^1;
sbit p_in_oil_a_3=P1^2;
sbit p_in_oil_b_1=P1^3;
sbit p_in_oil_b_2=P1^4;
sbit p_in_oil_b_3=P1^5;
//用液信号输入
sbit p_in_oil_flow=P1^6;
//键盘输入
sbit p_in_key1=P0^0;
sbit p_in_key2=P0^1;
sbit p_in_key3=P0^2;
sbit p_in_key4=P0^3;
//报警量输出
sbit p_out_w_pre=P1^7;
sbit p_out_w_pwr=P3^5;
sbit p_out_w_burst=P3^6;
sbit p_out_w_oila=P0^6;
sbit p_out_w_oilb=P0^7;
//控制信号输出
sbit p_out_oila=P0^4;
sbit p_out_oilb=P0^5;
sbit p_out_power_c=P2^6;
//AD转换
sbit p_ad_cs=P3^4;
sbit p_ad_di=P2^2;
sbit p_ad_do=P2^1;
sbit p_ad_clk=P2^0;
//24C01
sbit p_24cx_sda=P2^5;
sbit p_24cx_scl=P2^4;
sbit p_24cx_wr_c=P2^3;
//LED清0
sbit p_clr_led=P2^7;
sbit acc_7=ACC^7;
uchar code ch_data_press_now[256]={0};//未计算出来
void main()
{
void tlc_0832_sCAN();
void tlc_0832_handle();
uchar ch_data_collect[18],ch_data_collect_times,ch_data_press_now;
ch_data_collect_times=18;//初始化采集次数
// 压力采集
tlc_0832_sCAN(&ch_data_collect_times,ch_data_collect);
tlc_0832_handle(&ch_data_collect_times,&ch_data_press_now,ch_data_collect);
}
void tlc_0832_sCAN(times,collect_data)
uchar *times,collect_data[18];
{
uchar i;
*times--;
p_ad_clk=0; //使能 ad
p_ad_cs=0;
p_ad_di=1; // 写控制字到AD,H0为+,单痛道采集
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=1;
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=0;
p_ad_clk=1;
p_ad_clk=0;
p_ad_clk=1;
for(i=0;i++;i<15){ // 采集一个数据点
p_ad_clk=0;
acc_7=p_ad_do;
ACC>>1;
p_ad_clk=1;
}
p_ad_cs=1;
collect_data[*times]=ACC;//保存采集到的数据
}
void tlc_0832_handle(times,press_now,collect_data)
uchar *times,*press_now,collect_data[18];
{
uchar i,j,collect_max=0;
if(*times=0){ //18个点全部采集完?
*times=18;
for(i=17;i--;i>=0){ //对采集到的18个点排序(增序)
for(j=0;j++;j<i){
if(collect_data[i]<collect_data[j]){
collect_max=collect_data[j];
collect_data[j]=collect_data[i];
collect_data[i]=collect_max;
}
}
}
for(i=1;i++;i<17){
collect_data[i] >> 4; //去掉两个极值,然后取平均值
}
collect_max=0;
for(i=1;i++;i<17){
collect_max=collect_max+collect_data[i];
*press_now=ch_data_press_now[collect_max]; //查表并返回当前压力值
}
}
}
Build target 'Target 1'
compiling MAIN.C...
MAIN.C(57): error C267: 'tlc_0832_sCAN': requires ANSI-style prototype
Target not created
为什么会有这个错误啊,在函数调用时C51和标准C有什么不同吗 ??
望各位赐教!!!感激不尽!!!! 答 1: 我找到问题了 呵呵 自己太粗心了 答 2: 没法说你的程序太多语法错误,requires ANSI-style prototype是没有函数声明.
你的程序我重新编译了一下,我也是新手.
你看看能不能用.
#include <reg52.h>
typedef unsigned char uchar;
//ÓÍÏäÒºÃæ¼ì²âÊäÈëµã
sbit p_in_oil_a_1=P1^0;
sbit p_in_oil_a_2=P1^1;
sbit p_in_oil_a_3=P1^2;
sbit p_in_oil_b_1=P1^3;
sbit p_in_oil_b_2=P1^4;
sbit p_in_oil_b_3=P1^5;
//ÓÃÒºÐźÅÊäÈë
sbit p_in_oil_flow=P1^6;
//¼üÅÌÊäÈë
sbit p_in_key1=P0^0;
sbit p_in_key2=P0^1;
sbit p_in_key3=P0^2;
sbit p_in_key4=P0^3;
//±¨¾¯Á¿Êä³ö
sbit p_out_w_pre=P1^7;
sbit p_out_w_pwr=P3^5;
sbit p_out_w_burst=P3^6;
sbit p_out_w_oila=P0^6;
sbit p_out_w_oilb=P0^7;
//¿ØÖÆÐźÅÊä³ö
sbit p_out_oila=P0^4;
sbit p_out_oilb=P0^5;
sbit p_out_power_c=P2^6;
//ADת»»
sbit p_ad_cs=P3^4;
sbit p_ad_di=P2^2;
sbit p_ad_do=P2^1;
sbit p_ad_clk=P2^0;
//24C01
sbit p_24cx_sda=P2^5;
sbit p_24cx_scl=P2^4;
sbit p_24cx_wr_c=P2^3;
//LEDÇå0
sbit p_clr_led=P2^7;
sbit acc_7=ACC^7;
void tlc_0832_sCAN(uchar *times,uchar collect_data[18]);
void tlc_0832_handle(uchar *times,uchar *press_now,uchar collect_data[18]);
uchar code ch_data_press_now[256]={0};//δ¼ÆËã³öÀ´
void main()
{
uchar ch_data_collect[18],ch_data_collect_times,ch_data_press_now;
ch_data_collect_times=18;//³õʼ»¯²É¼¯´ÎÊý
// ѹÁ¦²É¼¯
tlc_0832_sCAN(&ch_data_collect_times,ch_data_collect);
tlc_0832_handle(&ch_data_collect_times,&ch_data_press_now,ch_data_collect);
}
void tlc_0832_sCAN(uchar *times,uchar collect_data[18])
// uchar *times,collect_data[18];
{
uchar i;
times--;
p_ad_clk=0; //ʹÄÜ ad
p_ad_cs=0;
p_ad_di=1; // д¿ØÖÆ×Öµ½AD£¬H0Ϊ+£¬µ¥Í´µÀ²É¼¯
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=1;
p_ad_clk=1;
p_ad_clk=0;
p_ad_di=0;
p_ad_clk=1;
p_ad_clk=0;
p_ad_clk=1;
for(i=0;i++;i<15)
{ // ²É¼¯Ò»¸öÊý¾Ýµã
p_ad_clk=0;
acc_7=p_ad_do;
ACC>>=1;
p_ad_clk=1;
}
p_ad_cs=1;
collect_data[*times]=ACC;//±£´æ²É¼¯µ½µÄÊý¾Ý
}
void tlc_0832_handle(uchar *times,uchar *press_now,uchar collect_data[18])
// uchar *times,*press_now,collect_data[18];
{
uchar i,j,collect_max=0;
if(*times==0)
{ //18¸öµãÈ«²¿²É¼¯Íꣿ
*times=18;
for(i=17;i--;i>=0)
{ //¶Ô²É¼¯µ½µÄ18¸öµãÅÅÐò(ÔöÐò)
for(j=0;j++;j<i)
{
if(collect_data[i]<collect_data[j])
{
collect_max=collect_data[j];
collect_data[j]=collect_data[i];
collect_data[i]=collect_max;
}
}
}
for(i=1;i++;i<17)
{
collect_data[i] >>= 4; //È¥µôÁ½¸ö¼«Öµ,È»ºóȡƽ¾ùÖµ
}
collect_max=0;
for(i=1;i++;i<17)
{
collect_max=collect_max+collect_data[i];
*press_now=ch_data_press_now[collect_max]; //²é±í²¢·µ»Øµ±Ç°Ñ¹Á¦Öµ
}
}
} 答 3: 把函数放在main()前 答 4: 谢谢了
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |