From: Peter V. E. <va...@sf...> - 2010-12-15 00:58:07
|
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): peter@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 0> r Simulation started, PC=0x000000 q 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() { serial_init(); printf("hello world\r\n"); return 0; } |