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 #pragma section CODE=IRAM,attr=CODE
10 const char ASCII[] = "0123456789ABCDEF";
14 // Initialize UART asynchronous mode
15 // BGR04 = 1666; // 9600 Baud @ 16MHz
16 // BGR04 = 832; // 19200 Baud @ 16MHz
17 BGR04 = 416; // 38400 Baud @ 16MHz
19 // BGR04 = 2083; // 9600 Baud @ 20MHz
20 // BGR04 = 1041; // 19200 Baud @ 20MHz
21 // BGR04 = 520; // 38400 Baud @ 20MHz
23 // BGR04 = 2499; // 9600 Baud @ 24MHz
24 // BGR04 = 1249; // 19200 Baud @ 24MHz
25 // BGR04 = 624; // 38400 Baud @ 24MHz
27 SMR04 = 0x0d; // enable SOT3, Reset, normal mode
28 SSR04 = 0x00; // LSB first
29 PFR19 = (PFR19 & 0xFC) | 0x03; // enable UART: SIN,SOT for async. transfer
30 EPFR19 = 0x00; // enable UART
33 void Putch4(unsigned char ch) /* sends a char */
35 while (SSR04_TDRE == 0); /* wait for transmit buffer empty */
36 TDR04 = ch; /* put ch into buffer */
39 unsigned char Getch4(void) /* waits for and returns incomming char */
46 while(SSR04_RDRF == 0) /* wait for data received */
51 if ((SSR04 & 0xE0) != 0) /* Check for errors PE, ORE, FRE */
53 SCR04_CRE = 1; /* Clear error flags */
56 return (ch); /* return char */
61 void Puts4(const char *Name2) /* Puts a String to UART */
67 for (i=0; i<strlen(Name2); i++) /* go through string */
71 Putch4(Name2[i]); /* send it out */
76 char Echo4(void) /* Echo UART and return ch */
80 Puts4("UART 4 receive: "); // send text to UART
81 ch = RDR04; // readout character
82 Putch4(ch); // send character to UART
89 void Puthex4(unsigned long n, unsigned char digits)
91 unsigned char digit=0,div=0,i;
93 div=(4*(digits-1)); /* init shift divisor */
94 for (i=0;i<digits;i++)
96 digit = ((n >> div)&0xF); /* get hex-digit value */
97 Putch4(digit + ((digit < 0xA) ? '0' : 'A' - 0xA));
98 div-=4; /* next digit shift */
102 void Putdec4(unsigned long x, int digits)
107 if (digits < 0) { /* should be print of zero? */
111 buf[digits]='\0'; /* end sign of string */
113 for (i=digits; i>0; i--) {
114 buf[i-1] = ASCII[x % 10];
120 for (i=0; buf[i]=='0'; i++) { /* no print of zero */
126 Puts4(buf); /* send string */