选择“构建主项目”并尝试编译我的项目时,编译器不断显示以下错误消息:
Source.c:64:8: error: 'RB6' undeclared (first use in this function)
我相信这与我的#define 代码行有关,但我不确定:
// Include Commands
#include "xc.h"
#include "lcd.h"
#include <stdio.h>
#include <stdlib.h>
#include "pragma.h"
#include <stdbool.h>
// Define Commands
#define LCD_RS RB7
#define LCD_D0 RB15
#define LCD_D1 RB14
#define LCD_D2 RB13
#define ULTRAECHO RA4
#define ULTRATRIG RB5
#define PIR RB6
#define PIRII RB7
#define MOTOR RB4
#define MOTORII RB12
#define XTAL_FREQ 8000000
void setup() {
// A-Type Registers
TRISA = 0;
// 0 - 5
PORTA = 0;
// B-Type Registers
TRISB = 0;
// 0 - 15
PORTB = 0;
LCD_Cmd(LCD_CLEAR);
__delay_ms(50);
LCD_Begin();
}
void loop() {
int value;
value = 0;
__delay_ms(300);
PORTBbits.RB6 = 1;
PORTBbits.RB7 = 1;
if (PIR == 1 || PIRII == 1) { // Checks both PIR Sensors
PORTBbits.RB8 = 1; // Activates LCD Screen
PORTBbits.RB15 = 1;
PORTBbits.RB14 = 1;
PORTBbits.RB13 = 1;
PORTAbits.RA4 = 1; // Activates ULTRASONIC
PORTBbits.RB5 = 1;
LCD_Cmd(LCD_CLEAR);
(value = value + 1);
}
else {
PORTBbits.RB8 = 0; // No Life Detected
PORTBbits.RB15 = 0;
PORTBbits.RB14 = 0;
PORTBbits.RB13 = 0;
(value = value);
}
{
LCD_Goto(1, 1);
LCD_Print(value);
goto __delay_ms(300);
}
{
if (PORTAbits.RA4 = 1 || PORTBbits.RB5 = 1) {
__bit wait_sensor(); // Activates Timer
uint16_t i = 0;
TMR1 = 0; // Resets Timer
TMR1 = 1;
while (!ULTRAECHO && (i < 1000)) {
i = (TMR1 << 8) | TMR1;
if (i >= 1000)
return 0;
else {
return 1;
}
}
}
__bit get_distance(uint16_t *ticks);
{
uint16_t *ticks = 0;
TMR1 = 0;
while (ULTRAECHO && ('uint16_t *ticks' < 23200))
uint16_t *ticks = (TMR1 << 8) | TMR1; // Read Timer Value
TMR1 = 0;
if (uint16_t *ticks >= 23200)
return 1;
else {
return 0;
}
}
{
OSCCON = 0x70; // Sets Timer and Oscillator Value
T1CON = 0x10;
TMR1 = 0;
__delay_ms(500);
ULTRATRIG = 0; // Toggle Pin to LOW
__delay_us(2);
ULTRATRIG = 1; // Generate 10us Pulse
__delay_us(10);
ULTRATRIG = 0;
if (ULTRAECHO = 1) // Read Pulse from ULTRAECHO
uint16_t distance;
if (get_distance()) { // Distance greater than 400cm
LCD_Goto(2, 1);
LCD_Print(" No Proximity ");
MOTORII = 0;
MOTOR = 0;
}
else {
uint16_t distance = uint16_t distance / 58; // Calculates Distance
LCD_Goto(2, 1);
LCD_Print(distance, " cm ");
MOTORII = 1;
MOTOR = 1;
}
uint16_t distance = uint16_t distance / 58;
if (uint16_t distance <= 20)
MOTORII = 0;
MOTOR = 0;
__delay_ms(500);
goto void setup();
}
}
}
也许我的“定义”命令的位置不正确?还是我忘记了某种代码行?我觉得我想太多了。