OpenCores
URL https://opencores.org/ocsvn/yacc/yacc/trunk

Subversion Repositories yacc

[/] [yacc/] [trunk/] [syn/] [c_src/] [count/] [count_tak.BAK] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tak.sugawa
//Apr.1.2005 for ram16k
2
//count_tak.c
3
 
4
 
5
 
6
 
7
#define print_port 0x3ff0
8
#define print_char_port 0x3ff1
9
#define print_int_port 0x3ff2
10
#define print_long_port 0x3ff4
11
 
12
 
13
 
14
 
15
 
16
#define uart_port               0x03ffc //for 16KRAM
17
#define uart_wport uart_port
18
#define uart_rport uart_port
19
#define int_set_address 0x03ff8 //for 16KRAM
20
 
21
 
22
 
23
char *name[]={
24
   "","one","two","three","four","five","six","seven","eight","nine",
25
   "ten","eleven","twelve","thirteen","fourteen","fifteen",
26
      "sixteen","seventeen","eighteen","nineteen",
27
   "","ten","twenty","thirty","forty","fifty","sixty","seventy",
28
      "eighty","ninety"
29
};
30
void print_uart(unsigned char* ptr)//
31
{
32
        unsigned int uport;
33
        #define WRITE_BUSY 0x0100
34
 
35
 
36
        while (*ptr) {
37
 
38
                do {
39
                  uport=*(volatile unsigned*)   uart_port;
40
                } while (uport & WRITE_BUSY);
41
                *(volatile unsigned char*)uart_wport=*(ptr++);
42
        }
43
        //*(volatile unsigned char*)uart_wport=0x00;//Write Done
44
}
45
 
46
 
47
void putc_uart(unsigned char c)//
48
{
49
        unsigned int uport;
50
 
51
 
52
        do {
53
                  uport=*(volatile unsigned*)   uart_port;
54
        } while (uport & WRITE_BUSY);
55
        *(volatile unsigned char*)uart_wport=c;
56
 
57
}
58
 
59
unsigned char read_uart()//Verilog Test Bench Use
60
{
61
                unsigned uport;
62
                uport= *(volatile unsigned *)uart_rport;
63
                return uport;
64
}
65
 
66
void print(unsigned char* ptr)//Verilog Test Bench Use
67
{
68
 
69
        while (*ptr) {
70
 
71
                *(volatile unsigned char*)print_port=*(ptr++);
72
        }
73
 
74
        *(volatile unsigned char*)print_port=0x00;//Write Done
75
 
76
}
77
 
78
 
79
 
80
 
81
 
82
 
83
char *itoa(unsigned long num)
84
{
85
   static char buf[12];
86
   int i;
87
   buf[10]=0;
88
   for(i=9;i>=0;--i) {
89
      buf[i]=(char)((num%10)+'0');
90
      num/=10;
91
   }
92
   return buf;
93
}
94
 
95
void number_text(unsigned long number)
96
{
97
   int digit;
98
   print_uart(itoa(number));
99
   print_uart(": ");
100
   if(number>=1000000000) {
101
      digit=number/1000000000;
102
      print_uart(name[digit]);
103
      print_uart(" billion ");
104
      number%=1000000000;
105
   }
106
   if(number>=100000000) {
107
      digit=number/100000000;
108
      print_uart(name[digit]);
109
      print_uart(" hundred ");
110
      number%=100000000;
111
      if(number<1000000) {
112
         print_uart("million ");
113
      }
114
   }
115
   if(number>=20000000) {
116
      digit=number/10000000;
117
      print_uart(name[digit+20]);
118
      putc_uart(' ');
119
      number%=10000000;
120
      if(number<1000000) {
121
         print_uart("million ");
122
      }
123
   }
124
   if(number>=1000000) {
125
      digit=number/1000000;
126
      print_uart(name[digit]);
127
      print_uart(" million ");
128
      number%=1000000;
129
   }
130
   if(number>=100000) {
131
      digit=number/100000;
132
      print_uart(name[digit]);
133
      print_uart(" hundred ");
134
      number%=100000;
135
      if(number<1000) {
136
         print_uart("thousand ");
137
      }
138
   }
139
   if(number>=20000) {
140
      digit=number/10000;
141
      print(name[digit+20]);
142
      putc_uart(' ');
143
      number%=10000;
144
      if(number<1000) {
145
         print_uart("thousand ");
146
      }
147
   }
148
   if(number>=1000) {
149
      digit=number/1000;
150
      print_uart(name[digit]);
151
      print_uart(" thousand ");
152
      number%=1000;
153
   }
154
   if(number>=100) {
155
      digit=number/100;
156
      print_uart(name[digit]);
157
      print_uart(" hundred ");
158
      number%=100;
159
   }
160
   if(number>=20) {
161
      digit=number/10;
162
      print_uart(name[digit+20]);
163
      putc_uart(' ');
164
      number%=10;
165
   }
166
   print_uart(name[number]);
167
   putc_uart('\r');
168
   putc_uart('\n');
169
}
170
 
171
void main()
172
{
173
   unsigned long number,i;
174
#ifdef RTL_SIM
175
        print("This program is based on Steve Rhoards-san,author of plasma.\n");
176
 
177
#endif
178
   print_uart("Mult by 3\r\n");
179
 //  for (i=0;i<3;i=i+1)   print_uart("uart port test\n");
180
   number=3;
181
   for(i=0;;++i) {
182
      number_text(number);
183
      number*=3;
184
      #ifdef RTL_SIM
185
        if (i==18){
186
                        print(" ");//flush
187
                print("$finish");
188
 
189
        }
190
          #endif
191
 
192
   }
193
}
194
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.