1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
3 /* ELIGIBILITY FOR ANY PURPOSES. */
4 /* (C) Fujitsu Microelectronics Europe GmbH */
5 /*---------------------------------------------------------------------------*/
9 const char ASCII[] = "0123456789ABCDEF";
13 // Initialize UART asynchronous mode
14 // BGR04 = 1666; // 9600 Baud @ 16MHz
15 BGR04 = 832; // 19200 Baud @ 16MHz
16 // BGR04 = 416; // 38400 Baud @ 16MHz
18 // BGR04 = 2083; // 9600 Baud @ 20MHz
19 // BGR04 = 1041; // 19200 Baud @ 20MHz
20 // BGR04 = 520; // 38400 Baud @ 20MHz
22 // BGR04 = 2499; // 9600 Baud @ 24MHz
23 // BGR04 = 1249; // 19200 Baud @ 24MHz
24 // BGR04 = 624; // 38400 Baud @ 24MHz
26 SMR04 = 0x0d; // enable SOT3, Reset, normal mode
27 SSR04 = 0x00; // LSB first
28 PFR19 = (PFR19 & 0xFC) | 0x03; // enable UART: SIN,SOT for async. transfer
29 EPFR19 = 0x00; // enable UART
32 void Putch4(char ch) /* sends a char */
34 while (SSR04_TDRE == 0); /* wait for transmit buffer empty */
35 TDR04 = ch; /* put ch into buffer */
38 char Getch4(void) /* waits for and returns incomming char */
45 while(SSR04_RDRF == 0) /* wait for data received */
50 if ((SSR04 & 0xE0) != 0) /* Check for errors PE, ORE, FRE */
52 SCR04_CRE = 1; /* Clear error flags */
55 return (ch); /* return char */
60 void Puts4(const char *Name2) /* Puts a String to UART */
66 for (i=0; i<strlen(Name2); i++) /* go through string */
70 Putch4(Name2[i]); /* send it out */
75 char Echo4(void) /* Echo UART and return ch */
79 Puts4("UART 4 receive: "); // send text to UART
80 ch = RDR04; // readout character
81 Putch4(ch); // send character to UART
88 void Puthex4(unsigned long n, unsigned char digits)
90 unsigned char digit=0,div=0,i;
92 div=(4*(digits-1)); /* init shift divisor */
93 for (i=0;i<digits;i++)
95 digit = ((n >> div)&0xF); /* get hex-digit value */
96 Putch4(digit + ((digit < 0xA) ? '0' : 'A' - 0xA));
97 div-=4; /* next digit shift */
101 void Putdec4(unsigned long x, int digits)
106 if (digits < 0) { /* should be print of zero? */
110 buf[digits]='\0'; /* end sign of string */
112 for (i=digits; i>0; i--) {
113 buf[i-1] = ASCII[x % 10];
119 for (i=0; buf[i]=='0'; i++) { /* no print of zero */
125 Puts4(buf); /* send string */