This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Redefinition

Hi

i wrote the code below for a T89C51CC01 atmel's controller.When i tried to build it, it gives the following error message:(Build target 'Target 1'
compiling xixi.c...
XIXI.C(7): error C231: 'P1': redefinition
XIXI.C(8): error C231: 'P3': redefinition
Target not created)

These errors are caused by the 2 first lines after the include statements(sfr P1 = 0x90; sfr P3 = 0xB0;)



Can anyone help me?
The code:
#include <absacc.h>
#include <string.h>
#include <stdio.h>
#include <REG51CC01.H>


sfr P1 = 0x90;
sfr P3 = 0xB0;

sbit DIPswitch = P1^4;
sbit greenLED = P1^5;

void main (void) {
unsigned char inval;

inval = 0; // initial value for inval

while (1) {
if (DIPswitch == 1) { // check if input P1.4 is high
inval = P1 & 0x0F; // read bit 0 .. 3 from P1
greenLED = 0; // set output P1.5 to low
}
else { // if input P1.4 is low
greenLED = 1; // set output P1.5 to high
}
P3 = (P3 & 0xF0) | inval; // output inval to P3.0 .. P3.3
}
}

  • Hello David,

    within the header file for your target (e.g. REG51CC01.H) all sfr's are defined. You can either include this header or define the used sfr's in your code, but never try both. I recommend to use the header file after you have checked it, because sometimes the names for the registers are different from those used in the manuals for the target device.

    Tim

  • I have no idea what you guys are talking about.

  • "I have no idea what you guys are talking about."

    Which bit don't you understand:

    Do you know what a header file is?

    Do you know what an SFR is?

    Do you understand the concept of defining variables in 'C'?

    Do you understand the 'C' mechanism of #include?

    What is your level of understanding of the 'C' programming language in general?

    What is your level of understanding of the 8051 architecture?

    What is your level of understanding of Keil's C51 and the specifics of using it to write embedded software for the 8051 & derivatives?

  • Don't get me wrong - there's nothing wrong with not knowing these things per se, but we need to know your level of understanding to be able to give answers that you can understand!