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

How to use extern sbit declare?

I declare a variable unsigned char bdata Kde in a.c.

[in file a.c]

unsigned char bdata Kde;

Than I want to use the variable inb.c.
[in file b.c]
#include <stdio.h>
.....
extern unsigned char bdata Kde;
sbit testbit=Kde^1;
void main(void)
{......}

:error C141:.......a.c:syntax error near 'sbit'

why?

Parents
  • "I thought that sbits required a upper data space (e.g. DATA address 128 - 255) address to be assigned to them."

    It is with trepidation that I dare to suggest that you're wrong there, Mark.

    This was one of the first stumbling blocks which I fell over when I started using Keil - if you search back a couple of years, I probably moaned about it here!
    (probably along the lines, "you can tell it catches lots of people out by the way there's a special section in the manual!")

    Anyway, as I understand it, sbit is the means that Keil uses to give a name to a specific bit (hey - maybe I just hit on the meaning of the 's' there!) - whether it's in a hardware register, or a bdata variable.
    Effectively, sbit forms the definition of a bit "variable"

    bit, on the other hand, does not define the location of the "variable" - it simply says, "this is a single bit"

    Therefore, an extern must always use bit rather than sbit; repeating the sbit definition causes (if I remember correctly) a "multiple definition" Linker error.

Reply
  • "I thought that sbits required a upper data space (e.g. DATA address 128 - 255) address to be assigned to them."

    It is with trepidation that I dare to suggest that you're wrong there, Mark.

    This was one of the first stumbling blocks which I fell over when I started using Keil - if you search back a couple of years, I probably moaned about it here!
    (probably along the lines, "you can tell it catches lots of people out by the way there's a special section in the manual!")

    Anyway, as I understand it, sbit is the means that Keil uses to give a name to a specific bit (hey - maybe I just hit on the meaning of the 's' there!) - whether it's in a hardware register, or a bdata variable.
    Effectively, sbit forms the definition of a bit "variable"

    bit, on the other hand, does not define the location of the "variable" - it simply says, "this is a single bit"

    Therefore, an extern must always use bit rather than sbit; repeating the sbit definition causes (if I remember correctly) a "multiple definition" Linker error.

Children