Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » SDCC
  • » [Sdcc-user] How to get output from the s51 simulator [RSS Feed]

#1 Dec. 15, 2010 00:59:47

Peter V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] How to get output from the s51 simulator

Needing to test some 8051 code in the simulator lead to needing to be
able to do output from the program via the simulator. Since there doesn't seem
to be anything (that I can find) that does so, I created something and will
document it here for the next person that needs to do this. This uses the
UART in the 8051 to do output via the serial port. The -s option on the
simulator captures that output to a file (which needs to exist, the simulator
won't create one!). You will need to use cygwin on Windows to run the simulator
like this (in a cygwin window):

pe...@pc700 ~/wiznet/nos_test
$ "/cygdrive/c/program files/SDCC"/bin/sdcc --debug test1.c
$ rm out
$ touch out
$ "/cygdrive/c/program files/SDCC"/bin/s51 -s./out test1.ihx
uCsim 0.5.4, Copyright (C) 1997 Daniel Drotos, Talker Bt.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Warning: serial output interface connected to a non-terminal file.
1739 words read from test1.ihx
0> r
Simulation started, PC=0x000000
Stop at 0x000006: (105) User stopped
F 0x000006
0> q
$ cat out
hello world

where test1.c looks like this which mostly initializes the UART and
timer1 as the baud rate generator and defines a putchar() that uses the
serial output to interface with the simulator. Hopefully this is useful to
someone else ...

Peter Van Epp

#include <stdio.h>
#include <w7100.h>

void serial_init(void) {

TMOD &= 0x0f; /* clear timer 1 mode bits */
TMOD |= 0x20; /* timer 1 mode 1 */
PCON |= 0x80; /* set SMOD0 fosc/32 */
TH1 = 0xfc; /* set a baud rate (around 115K) */
TR1 = 1; /* start timer 1 */
SCON = 0x50; /* set the uart mode */
TI = 1; /* indicate the UART is empty! */

void putchar (char c) {

while (!TI)
TI = 0;
SBUF = c;

main() {

printf("hello world\r\n");
return 0;

Sdcc-user mailing list


  • Root
  • » SDCC
  • » [Sdcc-user] How to get output from the s51 simulator [RSS Feed]

Board footer

Moderator control

Enjoy the 12th of December

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support