1 /*------------------------------------------------------------------------
2 hi.c - This is a simple program designed to operate on basic MCS51
3 hardware at 11.0592Mhz. It sets up the baudrate to 9600 and sends
4 a "Hi\n" "There\n" message every few seconds. The timer interrupt
7 Its intended to be a simple example for SDCC, a good first
8 program to compile and play with.
10 The simulator can be used to run this program:
11 s51 -Sout=serial.txt hi.ihx (run, stop, quit)
13 Notice that unless we use the --stack-after-data option,
14 the SSEG listed in the map is not accurate, look at the
15 .asm file and search for "sp," to see where it is really
18 6-28-01 Written by Karl Bongers(karl@turbobit.com)
19 |------------------------------------------------------------------------*/
22 typedef unsigned char byte;
23 typedef unsigned int word;
24 typedef unsigned long l_word;
26 //---- most of the following declares are simply to demostrate some
27 // of SDCC's variable storage declaration syntax
29 // volatile keyword is needed for variables shared by interrupt routine
30 // and normal application thread, otherwise things get optimized out.
31 volatile data byte timer;
32 volatile data byte hi_flag;
34 data byte a_data_byte; // normal < 128 bytes of 8031 internal memory.
35 idata byte a_idata_byte; // in +128 byte internal memory of 8032
36 xdata byte a_xdata_byte; // in external memory.
37 xdata at 0x8000 byte mem_mapped_hardware; // example at usage
39 bit my_bit; // mcs51 bit variable, stored in single bit of register space
41 sfr at 0xd8 WDCON; // special function register declaration
42 sbit LED_SYS = 0xb5; // P3.5 is led, example use of sbit keyword
44 code char my_message[] = {"GNU rocks\n"}; // placed in code space
46 void timer0_irq_proc(void) interrupt 1 using 2;
48 /*------------------------------------------------------------------------
49 timer0_int - Timer0 interrupt. Notice we are using register bank 2
51 |------------------------------------------------------------------------*/
52 void timer0_irq_proc(void) interrupt 1 using 2
64 TR0 = 0; /* Stop Timer 0 counting */
66 TL0 = (~(5000)) & 0xff;
67 TR0 = 1; /* Start counting again */
71 /*------------------------------------------------------------------------
72 uart0_int - Interrupt 4 is for the UART, notice we use register bank 1
73 for the interrupt routine.
74 |------------------------------------------------------------------------*/
75 void uart0_int(void) interrupt 4 using 1
85 /*------------------------------------------------------------------------
86 tx_char - transmit(tx) a char out the serial uart.
87 |------------------------------------------------------------------------*/
96 /*------------------------------------------------------------------------
97 tx_str - transmit(tx) a string out the serial uart.
98 |------------------------------------------------------------------------*/
99 void tx_str(char *str)
106 /*------------------------------------------------------------------------
107 stop - a break point in Daniel D's s51 can be set at 65535 memory
108 location to stop the simulation. This routine also shows how to
110 |------------------------------------------------------------------------*/
120 /*------------------------------------------------------------------------
121 main - Simple test program to send out something to the serial port.
122 |------------------------------------------------------------------------*/
125 PCON = 0x80; /* power control byte, set SMOD bit for serial port */
126 SCON = 0x50; /* serial control byte, mode 1, RI active */
127 TMOD = 0x21; /* timer control mode, byte operation */
128 TCON = 0; /* timer control register, byte operation */
130 TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */
131 TR1 = 1; /* start serial timer */
133 TR0 = 1; /* start timer0 */
134 ET0 = 1; /* Enable Timer 0 overflow interrupt IE.1 */
135 EA = 1; /* Enable Interrupts */
137 TI = 0; /* clear this out */
138 SBUF = '.'; /* send an initial '.' out serial port */
140 //ES = 1; /* Enable serial interrupts IE.4 */
148 tx_str("Hi There\n");
154 #ifdef TEST_IDLE_MODE
155 // this was a simple test of the low power sleep mode of a
156 // dallas DS5000 cmos part, to see how much power requirements
157 // dropped in sleep mode.
159 // into idle mode until next interrupt. Draws only 3ma.