-2

我使用 MPLAB X IDE(一种用于微控制器的软件)来编译我的代码,但由于某种原因,它一直说至少有两个错误(特别是在粗体区域)。我试着寻找,但我仍然不确定为什么会这样,所以任何帮助将不胜感激。

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <math.h>
#include <p18f4620.h>

#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOREN = OFF
#define delay 5
// Prototype Area to place all the references to the routines used in the program
void Init_ADC(void);
unsigned char Get_Full_ADC(void);
void Flash_LED(unsigned char);
void main(void)
{
 unsigned int ADC_Result; // local variable to store the result
 Init_ADC(); // initialize the A2D converter
 TRISB =0x00; // make PORTB as all outputs
 while(1)
 {
 ADC_Result = Get_Full_ADC(); // call routine to measure the A2D port
 Flash_LED(ADC_Result); // call routine to flash the LED based on the delay
 // indicated by ADC_Result
 }
}
void Init_ADC(void)
{
 ADCON0=0x01; // select channel AN0, and turn on the A2D subsystem
 ADCON1=0x0E; // set pin 2 as analog signal, VDD-VSS as reference voltage
// and right justify the result
 ADCON2=0xA9; // Set the bit conversion time (TAD) and acquisition time
}
**unsigned int Get_Full_ADC(void)
{
int result;
 ADCON0bits.GO=1; // Start Conversion
 while(ADCON0bits.DONE==1); // Wait for conversion to be completed (DONE=0)
 result = (ADRESH * 0x100) + ADRESL; // Combine result of upper byte and lower byte into
 return result; // return the most significant 8- bits of the result.
}** 
void Flash_LED(unsigned int ADC_result)
{
unsigned int counter1, counter2;
 LATB = 0x0A; // output to PORTB the pattern 00001010
 // delay loop
 for (counter2=delay; counter2>0; --counter2)
 {
 for (counter1=ADC_result ; counter1>0; -- counter1);
 }
 LATB = 0x05 // output to PORTB the pattern 00000101
// delay loop
 for (counter2=delay; counter2>0; --counter2)
 {
 for (counter1=ADC_result ; counter1>0; -- counter1);
 }
}
4

1 回答 1

7

函数原型(声明)说

unsigned char Get_Full_ADC(void);

但它的定义说

unsigned int Get_Full_ADC(void)

你也有

int result;
...
return result;

所以你永远不会使用一致的类型。编译器会抱怨不匹配的定义。

于 2021-08-24T09:00:38.547 回答