1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*------------------------------------------------------------------------
test3.c - A simple multiple module example, uses itoa() and crc()
routines from other modules in same directory. Compile with:
make -f maketest3
|------------------------------------------------------------------------*/
#if defined(__mcs51)
#include <8052.h>
#endif
#if defined(__ds390)
#include <ds390.h>
#endif
#include <stdio.h>
typedef unsigned char byte;
typedef unsigned int word;
typedef unsigned long l_word;
void uitoa(unsigned int value, char* string, int radix);
void itoa(int value, char* string, int radix);
byte accum_checksum(byte cs, byte val);
char tmpstr[30];
int i;
#if defined(__mcs51) || defined(__ds390)
/*------------------------------------------------------------------------
tx_char - transmit(tx) a char out the serial uart.
|------------------------------------------------------------------------*/
void tx_char(char c)
{
SBUF = c;
while (!TI)
;
TI = 0;
}
/*------------------------------------------------------------------------
my_puts -
|------------------------------------------------------------------------*/
void my_puts(char *str)
{
while (*str)
tx_char(*str++);
}
/*------------------------------------------------------------------------
init_mcs51 -
|------------------------------------------------------------------------*/
void init_mcs51(void)
{
PCON = 0x80; /* power control byte, set SMOD bit for serial port */
SCON = 0x50; /* serial control byte, mode 1, RI active */
TMOD = 0x21; /* timer control mode, byte operation */
TCON = 0; /* timer control register, byte operation */
TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */
TR1 = 1; /* start serial timer */
EA = 1; /* Enable Interrupts */
TI = 0; /* clear this out */
}
#else
/*------------------------------------------------------------------------
my_puts -
|------------------------------------------------------------------------*/
void my_puts(char *str)
{
while (*str)
putchar(*str++); /* putchar() is lib routine which calls simulator trap */
}
#endif
/*------------------------------------------------------------------------
main - Simple test program to send out something to the serial port.
|------------------------------------------------------------------------*/
int main(void)
{
byte ccs;
unsigned int tmp;
#if defined(__mcs51) || defined(__ds390)
init_mcs51();
#endif
ccs = 0x3f;
tmp = (ccs<<7);
my_puts("0x3f<<7 hex=");
uitoa(tmp, tmpstr, 10);
my_puts(tmpstr);
my_puts("\n");
#if 0
byte r,cs,val;
unsigned int tmp;
cs = 0xff;
val = 0;
tmp = ((cs<<7) | (cs>>1)) + val;
printf("tmp=%xH(0x7fff)\n", tmp);
cs = 0xfd;
tmp = ((cs<<7) | (cs>>1)) + val;
printf("tmp=%xH(0x7efe)\n", tmp);
// return (byte)tmp + ((byte) (tmp>>8) & 1);
#endif
my_puts("Test3 - multiple module test\n");
my_puts("1023 decimal=");
uitoa(1023, tmpstr, 10);
my_puts(tmpstr);
my_puts(" hex=");
uitoa(1023, tmpstr, 0x10);
my_puts(tmpstr);
my_puts("\n");
my_puts(" chksum=");
// i = accum_checksum(50, 20);
uitoa(i, tmpstr, 10);
my_puts(tmpstr);
my_puts("\n");
for (;;)
{
}
return 0;
}
|