Using Visual C/C++ to do 8051 development

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I am working on an 8051 project. The code size has grown very large. I
am currently using code banking which makes compiling and linking of the
code very time consuming. For example to do a re-build take about 2+
minutes using the Keil Compiler. I know that some people have used
Visual C/C++ 6.0 to do 8051 development (these are systems where there
is almost no assembly except for the startup module supplied with the
compiler vendor) in order to speed things up. Do you have any experience
with this? Like maybe writing DLLs to simulate 8051 peripherals? Any
info would be appreciated.

Re: Using Visual C/C++ to do 8051 development
<snip>
Quoted text here. Click to load it

Huh?

Re: Using Visual C/C++ to do 8051 development

Quoted text here. Click to load it


What is your application?  I keep hearing of 8051 projects with so much code
that they need banking but I have no idea what they might be.  Can you
enlighten me?  Just curious.

Ian


Re: Using Visual C/C++ to do 8051 development
snipped-for-privacy@laars.com (Ed) wrote in

Quoted text here. Click to load it

I've used VC6.0 (no C++ of course) to debug complex algs. when I don't
have a good emulator or JTAG debugger available. I've also created test
harnesses in VC6 and plopped 8051-destined statemachines and functions
into the test harness. I've done all this in ISO C in as much as I could
by using #defines to remove issues with Keil C51 extenstions such as data,
idata, xdata etc. Of course using fixed bit types with a win32 and 8051
header file is a requirement. That is, typedef'ing unsigned char as a U8,
signed char as S8, etc.

--
- Mark ->
--

Re: Using Visual C/C++ to do 8051 development
Ed,

    I heard a while back that someone built a bunch of macros to
    _assemble_ 8051 code. I followed a dead link.

    I think you understand that a cross compiler is needed to
    compile to the 8051 family. So as others mentioned, debugging
    code and a familiar editor is all Vc++ will give you.

    hamilton


Ed wrote:
Quoted text here. Click to load it


Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it

I did that once for a 8051 serial terminal with graphic LCD.
The first step was a header that redefines Keil keywords,
such as redefining SFR into an unsigned char and redefining
interrupt into whitespace.

The 'windows' version of the software had some extra files,
doing the blitting of the LCD bitmap to the screen every 0.1
second or so, and used a serial port com thread, which did
not much else than loading the received character into the
SFR and calling the 8051 interrupt function. Likewise, characters
from the PC's keyboard or translated mouseclicks on the screen
where sent to the '8051' function that used to called from
the multiplexed 8051 keyboard scan. The windows software
also scanned the non existing ports for key presses, but never
saw a key pressed of course. And a few conditional compiles
sections were needed, to handle some more obscure things
such as the beeper, which was then handled by sending a
wav-file through the multimedia api. The final result looked
pretty much the same as the real thing, and it was quite
useful. Quite reliable too, in most cases after some heavy
changes and making it all work on the PC, the 8051 code
would run also, after the first rebuild using the Keil compiler.

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)







Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it

You can check the HAL part of the jayacard project :
http://cvs.sourceforge.net/viewcvs.py/jayacard/jayacard/proto/hal/

You will found some technics to simulate 8051 memory and to have C
source code compile under both Keil-C and Visual C++ environment.

This can give you some ideas (our project is simple thought : no
interrupt, no real-time, ...)

Hope this helps !

--
Gilles Dumortier
mailto: snipped-for-privacy@ieee.org or http://www.ObHack.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it


This is a backwards step. Using a Microsoft compiler will SLOW things
down.

1 It can not compile 8051 code. If does not understand the Keil or 8051
extensions.

2 Because of 1 the code will be larger and less efficient

3 Given 1 and 2 you will have to spend time porting the code from MS to
Keil C51 and have more room for errors.

4 The Keil simulator is accurate. The MS simulator pointless for
debugging a C51 program.

5 The MS compiler does not understand banking.

Why would you want to use the wrong tools?

What is the application?


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England    /\/\/\/\/\
/\/\/ snipped-for-privacy@phaedsys.org       www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Re: Using Visual C/C++ to do 8051 development
snipped-for-privacy@laars.com says...
Quoted text here. Click to load it


2 MINUTES?
That doesn't even give me enough time to get another cup of coffee.
When it takes 25 minutes to do a complete build, then you can start
looking for speedups.

--Gene

Re: Using Visual C/C++ to do 8051 development
In comp.arch.embedded

Quoted text here. Click to load it

I agree Gene, this guy is spoiled.  A full rebuild on my project takes
about 18 minutes then another 7 to burn the image into flash to test.  It
sure makes you think hard about your changes.

Re: Using Visual C/C++ to do 8051 development
I think it's best you stick to Keil, and probably optimize your code
if possible. I don't think there is much sence in trying to use Visual C++
for your application.

Mickey



Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it

To others in this thread, you assumed he wanted to use VC to compile
to 8051. I beleive he wants to compile standard C in VC and simulate
the target system to get the thing debugged, then recompile for his
target.

To ed,

I suspect you are thinking in too complex terms. Just move your code
to VC, and start compiling it. If you have a few assembly routines,
just create a stub for them. Your first problem is going to be overcoming
the incompatibilities between these two compilers. There will be some,
perhaps a lot if you have used a lot of non-standard features of the Keil
compiler.

Now that just gets you a clean VC compile.

Next, you want to simulate the system as best you can. You are going to
need a routine, in C, that performs every hardware operation you want
to do on your target. These routines are either going to do nothing, or
print an indication for you, or whatever you can handle. For example, if
you have an LCD display on the unit, then you can have the LCD
display write routine output in a window on the PC instead.

Typically on the projects I have done like this, we open up a window
and fill it with a lot of status buttons and readouts to represent the
target. For instance, if the unit has a button, you make a button
object in the window, there is a indicator light, that gets a little
light on/off graphic, etc.

Luck.



Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it

This is a waste of time. Standard C is not very efficient on the 8051
especially if he is banking already


Quoted text here. Click to load it

Then you are doomed to failure.

Quoted text here. Click to load it

As Keil is used for 80% of the worlds 8051 C projects the Keil *IS* the
standard.

MS VC is hardly "Standard C"

Quoted text here. Click to load it

Which is on no use on a 51.... How do you do BData?  work with SFR's
etc?

This project uses code banking. You can't do that in VC.


Quoted text here. Click to load it

Use the Keil simulator.

Quoted text here. Click to load it

Or use the peripherals in the simulator... why are you suggesting a
solution that is hard work and less accurate?

Quoted text here. Click to load it

These can also be don in the Keil sim.

Quoted text here. Click to load it

Just like in the Keil Sim but less accurate.

Why go back many steps?


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England    /\/\/\/\/\
/\/\/ snipped-for-privacy@phaedsys.org       www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it
the
experience

So Keil wrote a 8051 C compiler nobody wants/needs ?

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)



Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it
I think it has about 80% of the market.

Please explain how you access and use XDATA, CODE, IDATA & BTATA in ISO-
C.  

How do you use and access SFR's in ISO-C?

How do you write interrupts functions  in ISO-C?

How do you do re-entrant functions in Keil C  using only ISO-c?

How do you do 8 bit emuns in ISO-C?

How do you place variable as specific addresses in ISO C?

The architecture requires various extensions.

Besides you were not advocating the use of standard C anyway.

Regards
   Chris


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England    /\/\/\/\/\
/\/\/ snipped-for-privacy@phaedsys.org       www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it
I
there
the

The idea was to use Visual C as a temporary platform to develop
the application at hand. Which is in fact quite possible for
some 8051 applications, using a header that redefines Keil
keywords.

I did it for one project, and it worked quite well. I would
not claim that you can write all the software this way, and
some of the works still needs to be done with the Keil, using
the ICE on the real thing.

I just wouldn't call it a 'waste of time' per se. One area
where it works great is writing a user interface, for instance.


--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)







Re: Using Visual C/C++ to do 8051 development

Quoted text here. Click to load it

I don't get this at all. How is a Win32 user interface going to get you
anywhere on an 8051? If you mean an RS232 to terminal interface or keypad
and LCD or... it would take more time to write emulators for the UARTs,
oscillators, SFR's etc than it would to write and debug natively.

Bob

Re: Using Visual C/C++ to do 8051 development

Quoted text here. Click to load it

Emulator for the UART, left the write part out for brevity.
As you can see it's a sort of a mix of 8051 stuff and
windows API. I cleaned it up a bit, in a rush, as there
was more stuff in, such as to mimic leds on the PC application
window, and some error handling.


The communication thread:

DWORD CommThread(DWORD dwParam)
{
  while(TRUE)
  { read_serial() // reads *and* processes data from PC's serial port

    if((P4_4==1) && S0BUF)
    { Stufftosend[0]=1;
      Stufftosend[1]=S0BUF;
      write_serial();
      TI = 1;
      SerialComInterrupt();   // call the 8051 interrupt handler
    }
  }
  return 0;
}

And this read the PC's serial port and transfers the character
to the 8051 interrupt code:

int read_serial(void)
{ DWORD dwREAD1;
  DWORD dwErrors;
  COMSTAT comStat;
  BOOL bResult;
  DWORD dwcharsREAD1;
  DWORD idx;

  if (hComm == INVALID_HANDLE_VALUE) return FALSE; // port not available
  bResult = ReadFile(hComm, (LPVOID)&ComRecBuf[0], COMINBUFSIZE, &dwREAD1,
NULL);

  if(!bResult)
  { ClearCommError(hComm, &dwErrors, &comStat);
    //PrintfToBuf(SELDEBUG, "RS232 read-error, code=%lx\r\n", dwErrors);
  }
  else
  {
    if(dwREAD1>0)
    { // raise dtr line
      // EscapeCommFunction( hComm, SETDTR);

      if(port==TERMINALCOM) // data from terminal
      { dwcharsREAD1 = dwREAD1;
        ComRecBuf[dwREAD1]=0;
        idx = 0;
//        OkMsgBox("Timer", "string>%s<", &ComRecBuf[0]);
        idx = 0;
        while(dwcharsREAD1)
        { RI = 1;
          S0BUF = ComRecBuf[idx];
          SerialComInterrupt();
          dwcharsREAD1--;
          idx++;
        }
      }
      // set dtr line back
      //EscapeCommFunction( hComm, CLRDTR);
    }
  }
  return(dwREAD1);
}

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)








Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it


There are a lot of advantages to simulating new hardware on the PC, or other
workstation platform. First and foremost, you can develop the software before
the hardware shows up. Second, the PC is a better and faster platform, although
since most compilers cross from the PC anyways, that is pretty much a moot
point. Third, developing against emulated modules takes a lot of the timing,
miswires and other hardware trivial out of the picture, so that you can get
software correct functionally before trying to get it to work with the
target hardware. Forth, it gives everyone a development system at zero cost
per station, since all they need is the PC and the software. Fifth, it makes
automatic regression testing easier, since all of the ins and outs of the
program can be automatically verified, and thats an advantage that exists
even after hardware is correct and shipping. Sixth, it simplifies debugging
in general, since the environment is virtual and predictable. For example,
many real world hardware interaction bugs tend to be intermittent. A simulator
can tightly control the run and produce the same run every time. Seventh,
simulators that closely resemble the hardware tend to find hardware design
issues that nobody thought of, in time to get the hardware put right before
a lot of money is spent on manufacturing boards and ICs. Eigth, many hardware
simulators provide hooks so that real code can be run against them. For example,
verilog simulators can be arranged to link to C programs to form a test
bench of the final system. Simulating the hardware and software together
like that is how you get hardware that is correct on the first build.



Re: Using Visual C/C++ to do 8051 development
Quoted text here. Click to load it


I agree with all of this. So use the Keil 8051 simulator. IT is a very
good sim that is very accurate and it handles most of the peripherals of
most of the 51 family.

Why change from a full implementation of the target language and a good
sim to a non-standard version of C that is not correct for the
architecture and a less accurate or complete sim?

BTW compare the results of MS-C and Keil C using Plum-Hall and Paranoia
and see what I mean.  

However if you have a decent ICE for the part it is no contest. Use the
Keil C51 and the ICE. This is the only way to pick up an intermittent
bug.


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England    /\/\/\/\/\
/\/\/ snipped-for-privacy@phaedsys.org       www.phaedsys.org \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Site Timeline