Imported Upstream version 2.9.0
[debian/cc1111] / device / examples / ds390 / test390 / test390.c
1 /*
2 A simple test app for ds390 compiler work
3 */
4
5 #include <8052.h>
6
7 typedef unsigned char byte;
8 typedef unsigned int word;
9 typedef unsigned long l_word;
10
11 code char my_message[] = {"Testing 123\n"};
12 volatile byte hi_flag = 1;
13 volatile byte timer = 0;
14
15 /****
16   Note(Bug?): stock mcs51 will find this in library routines,
17   For -mds390 compile,
18   if this is not here linker does not link in
19   anything and does not complain or fail the link.
20 *****/
21 unsigned char _sdcc_external_startup ()
22 {
23   return 0;
24 }
25
26 /*------------------------------------------------------------------------
27   timer0_int - Timer0 interrupt.  Notice we are using register bank 2
28     for this interrupt.
29 |------------------------------------------------------------------------*/
30 void timer0_irq_proc(void) interrupt 1 using 2
31 {
32   if (timer != 0)
33   {
34     --timer;
35   }
36   else
37   {
38     hi_flag = 1;
39     timer = 250;
40   }
41
42   TR0 = 0; /* Stop Timer 0 counting */
43   TH0 = (~(5000)) >> 8;
44   TL0 = (~(5000)) & 0xff;
45   TR0 = 1; /* Start counting again */
46 }
47
48 #if 0
49 /*------------------------------------------------------------------------
50   uart0_int - Interrupt 4 is for the UART, notice we use register bank 1
51     for the interrupt routine.
52 |------------------------------------------------------------------------*/
53 void uart0_int(void) interrupt 4 using 1
54 {
55   if (RI)
56   {
57     c = SBUF;
58     RI = 0;
59   }
60 }
61 #endif
62
63 /*------------------------------------------------------------------------
64   tx_char - transmit(tx) a char out the serial uart.
65 |------------------------------------------------------------------------*/
66 void tx_char(char c)
67 {
68   SBUF = c;
69   while (!TI)
70     ;
71   TI = 0;
72 }
73
74 /*------------------------------------------------------------------------
75   tx_str - transmit(tx) a string out the serial uart.
76 |------------------------------------------------------------------------*/
77 void tx_str(char *str)
78 {
79   
80   while (*str)
81     tx_char(*str++);
82 }
83
84 /*------------------------------------------------------------------------
85   main - Simple test program to send out something to the serial port.
86 |------------------------------------------------------------------------*/
87 void main(void)
88 {
89   PCON = 0x80;  /* power control byte, set SMOD bit for serial port */
90   SCON = 0x50;  /* serial control byte, mode 1, RI active */
91   TMOD = 0x21;  /* timer control mode, byte operation */
92   TCON = 0;     /* timer control register, byte operation */
93
94   TH1 = 0xFA;   /* serial reload value, 9,600 baud at 11.0952Mhz */
95   TR1 = 1;      /* start serial timer */
96
97   TR0 = 1;      /* start timer0 */
98   ET0 = 1;      /* Enable Timer 0 overflow interrupt IE.1 */
99   EA = 1;       /* Enable Interrupts */
100
101   TI = 0;       /* clear this out */
102   SBUF = '.';   /* send an initial '.' out serial port */
103   hi_flag = 1;
104   //ES = 1;                           /* Enable serial interrupts IE.4 */
105
106   tx_str(my_message);
107
108   for (;;)
109   {
110     if (hi_flag)
111     {
112       tx_str("Hi There\n");
113       hi_flag = 0;
114     }
115   }
116
117 }
118