程序如下:
Main.c文件如下:
#include <pic18.h>
#include "Average.h"
#define uchar unsigned char
#define uint unsigned int
__PROG_CONFIG(1,0x0700);
__PROG_CONFIG(2,0x1f1f);
__PROG_CONFIG(3,0x8100);
__PROG_CONFIG(4,0x0085);
__PROG_CONFIG(5,0x000f);
__PROG_CONFIG(6,0xe00f);
__PROG_CONFIG(7,0x400f); //设置配置位
volatile uchar AD_Array[10];
volatile uchar Current;
/******************************************************************************
* 函 数 名: main()
* 函数功能: 主函数
* 入口参数: 无
* 返 回: 无
*******************************************************************************/
void main()
{
while(1)
{
Current = AVE_Cal(AD_Array);
}
}
Average.c文件如下:
#define uchar unsigned char
#define uint unsigned int
/******************************************************************************
* 函 数 名: AVE_Cal()
* 函数功能: 求平均数
* 入口参数: 求均值数组
* 返 回: 平均值
*******************************************************************************/
uchar AVE_Cal(volatile uchar data[])
{
uchar i, result;
uchar sum = data[0];
for(i=1;i<10;i++)
sum = sum + data[i];
result = sum/10;
return result;
}
Average.h文件如下:
#define uchar unsigned char
#define uint unsigned int
#ifndef _AVERAGE_H_
#define _AVERAGE_H_
/************************声明函数***********************************************/
uchar AVE_Cal(volatile uchar data[])
#endif
PICC18编译完后报错如下:
Error [315] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 7.1 "{" expected
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 8.1 expression syntax
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 9.1 expression syntax
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 10.1 expression syntax
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 11.1 expression syntax
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 12.1 expression syntax
Error [195] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 13.1 expression syntax
Error [314] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 25.1 ";" expected
Warning [343] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 29.1 implicit return at end of non-void function
Error [285] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 30.1 no identifier in declaration
Warning [374] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 30.1 missing basic type; int assumed
Error [314] D:\2. My Project\19.DIGITAL BATTERY\TT\Main.c; 30.1 ";" expected
请各位大仙指正 |