0

I am facing this error when try to compile a C program using the SDCC compiler:

The part of programme that is causing error.

include(reg51.h)
define cmdport P3
define dataport P2
define q 100

(following  3 line are causing error.)
sbit at  cmdport^0  rs ;  //register select pin
sbit at  cmdport^1  rw ;  // read write pin
sbit at  cmdport^6  e ;  //enable pin
Toby Jaffey
  • 28,836
  • 19
  • 98
  • 150
Zain
  • 423
  • 2
  • 6
  • 13

2 Answers2

5

Your code is not valid C. It should look like this:

#include <reg51.h>
#define cmdport P3
#define dataport P2
#define q 100

To create sbit definitions for the individual bits in P3 (address 0xB0), you want:

__sbit __at (0xB0) rs; // P3.0
__sbit __at (0xB1) rw; // P3.1
__sbit __at (0xB6) e;  // P3.6

Though, if you look in sdcc/includes/mcs51/8051.h you'll find that there are already generic definitions for P3_0 and so on, allowing you to write:

#define rs P3_0
#define rw P3_1
#define e  P3_6

I'd also recommend that you pick more descriptive names for your bit definitions than rs, rw and e as these may clash with variable names.

Toby Jaffey
  • 28,836
  • 19
  • 98
  • 150
  • i was including like you but i could not add # in question.I also tried __ before sbit and at as they were warned by sdcc as depriciated.i just copy your code nd now my code is working fine.but still i can,t figure out the cause f problem.please let me to know. – Zain Mar 14 '11 at 16:46
  • @Zain Try the SDCC mailing list. That's a much better forum for detailed back and forth discussion – Toby Jaffey Mar 14 '11 at 17:27
0

My guess is that this is an assembly file - you need to run it through an assembler rather than the C compiler.

Many C compilers (especially gcc based ones) will recognise a file with a particular suffix (.s for example) and do the right thing for you - other compilers wont - if you're using a make file that was written for gcc with a different compiler you might find that it makes this mistake

Taniwha
  • 1,646
  • 9
  • 8