gpt4 book ai didi

c - 由于需要结构/union ,microC 构建失败

转载 作者:太空宇宙 更新时间:2023-11-04 08:09:08 24 4
gpt4 key购买 nike

这是我的 main.c 程序,由于“需要结构/union ”而导致构建失败。我正在使用 pic 13f877a 微 Controller 。如果有人能告诉我此构建失败的原因,我将非常感激。还有另一个警告说“36.1 函数声明为隐式 int”。这也是什么意思?

#include<htc.h>
#define _XTAL_FREQ 4000000
__CONFIG(0X3F39);

void main(){
int a;
TRISB = 0b00010000; //RB4 as Input PIN (ECHO)
TRISC = 0b00000000; //C as Output PINs (LED)
T1CON = 0b00010000; //Initialize Timer Module

while(1){
TMR1H = 0; //Sets the Initial Value of Timer
TMR1L = 0; //Sets the Initial Value of Timer
PORTC = 0b00000000;
PORTB.F0 = 1; //TRIGGER HIGH
Delay_us(10); //10uS Delay
PORTB.F0 = 0; //TRIGGER LOW

while(!PORTB.F4){
T1CON.F0 = 1;
}
while(PORTB.F4){
T1CON.F0 = 0;
}

a = (TMR1L | (TMR1H<<8)); //Reads Timer Value
a = a/58; //Converts Time to Distance
a = a + 1; //Distance Calibration
if(a>=2 && a<=400){
//with in the range
PORTC = 0b11111111;
} else {
//out of range
PORTC = 0b00000000;
}
Delay_ms(400);
}
}

Build C:\Users\user\Desktop\SmartDustbin for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe

Make: The target "C:\Users\user\Desktop\main.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\user\Desktop\main.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [196] C:\Users\user\Desktop\main.c; 15.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 16.1 function declared implicit int
Error [196] C:\Users\user\Desktop\main.c; 17.10 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 19.16 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 20.10 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 22.15 struct/union required
Error [196] C:\Users\user\Desktop\main.c; 23.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 36.1 function declared implicit int

********** Build failed! **********

最佳答案

您声称使用的是 MicroC,但构建输出中的命令行清楚地表明您实际上使用的是 HI-Tech C 9.81,它已过时并被 Microchip 的 XC8 取代。 HI-Tech C 不允许像 MicroC 那样访问 SFR 中的单个位,就好像它们是结构成员一样。您只能以完整字节的形式访问寄存器,并且需要自己执行位操作。例如,行:

 PORTB.F0 = 1;   

需要变成:

PORTB |= (1 << 0);

这是在 C 中设置单个位的常用方法。它将 1 位移到所需位置,然后将其或运算到目标字节,而不改变其他位。如果您还不了解这一点,请谷歌一下 C 中的位操作。

function declared implicit int 错误源于未声明函数 delay_usdelay_ms。 HI-tech C 使用宏的__delay_ms__delay_us。此外,在使用延迟宏之前,您需要使用 PIC 的工作频率(以 Hz 为单位)定义 _XTAL_FREQ

关于c - 由于需要结构/union ,microC 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40689293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com