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

Subversion Repositories wb_lcd

[/] [wb_lcd/] [trunk/] [myhdl/] [wb_lcd_workspace/] [workspace/] [.metadata/] [.plugins/] [org.eclipse.core.resources/] [.history/] [21/] [40042adf0d29001e18b9b3f1f980bb8f] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jvillar
from myhdl import *
2
 
3
t_TxState = enum('tx_high_setup', 'tx_high_hold', 'tx_oneus', 'tx_low_setup', 'tx_low_hold', 'tx_fortyus', 'tx_done');
4
t_State = enum('display_init', 'init_fifteenms', 'init_one', 'init_two', 'init_three', 'init_four', 'init_five', 'init_six', 'init_seven', 'init_eight', 'display_function_set', 'display_entry_set', 'display_set_display', 'display_clr_display', 'display_pause_setup', 'display_pause', 'display_set_addr1', 'display_char_write1', 'display_set_addr2', 'display_char_write2','display_done')
5
 
6
def delayCounter(clk, reset, count, load, done, width = 13):
7
 
8
    counter = Signal(intbv(0)[width:0])
9
 
10
    @always_comb
11
    def done_logic():
12
        done.next = (counter == 0)
13
 
14
    @always(clk.posedge)
15
    def countdown_logic():
16
        if load:
17
            counter.next = count
18
        else: #elif not done:
19
            counter.next = counter - 1
20
 
21
    return instances()
22
 
23
 
24
 
25
def lcd(clk, reset, dat, addr, we, repaint, busy, SF_D, LCD_E, LCD_RS, LCD_RW):
26
 
27
 
28
    state = Signal(t_State.display_init)
29
    tx_state = Signal(t_TxState.tx_done)
30
    tx_byte = Signal(intbv(0)[8:0])
31
    tx_init = Signal(bool())
32
    tx_done = Signal(bool())
33
    LCD_E0 = Signal(bool())
34
    SF_D0 = Signal(intbv(0)[4:0])
35
    LCD_E1 = Signal(bool())
36
    SF_D1 = Signal(intbv(0)[4:0])
37
    pos = Signal(intbv(0)[9:0])
38
    MEM_LOW1 =0
39
    MEM_HIGH1 =15
40
    MEM_LOW2 =64
41
    MEM_HIGH2 =79
42
 
43
    @always_comb
44
    def busy_and_rw_handlers():
45
        busy.next = (state != t_State.display_done)
46
        LCD_RW.next = 0
47
 
48
    # Memory interface
49
    ram = [Signal(intbv(0)[8:0]) for i in range(67-1)]
50
 
51
    @always(clk.posedge)
52
    def memWrite():
53
        if we:
54
            ram[int(addr)].next = dat
55
 
56
 
57
    #Delay counter
58
    main_delay_load = Signal(bool())
59
    main_delay_value = Signal(intbv(0)[20:0])
60
 
61
    tx_delay_load = Signal(bool())
62
    main_delay_load = Signal(bool())
63
    delay_load = Signal(bool())
64
 
65
    tx_delay_value = Signal(intbv(0)[20:0])
66
    main_delay_value = Signal(intbv(0)[20:0])
67
    delay_value = Signal(intbv(0)[20:0])
68
 
69
    delay_done = Signal(bool())
70
    output_selector  = Signal(bool())
71
    counter = delayCounter(clk, reset, delay_value, delay_load, delay_done, width = 21)
72
 
73
    @always_comb
74
    def conunter_sharing_load():
75
        delay_load.next = tx_delay_load or main_delay_load
76
 
77
    @always_comb
78
    def conunter_sharing_value():
79
        if tx_delay_load:
80
            delay_value.next = tx_delay_value
81
        else:
82
            delay_value.next = main_delay_value
83
 
84
 
85
    # SF_D and LCD_E management for sharing between Init and TX phases.
86
    @always_comb
87
    def output_tx_or_init_select(): # 0 tx; 1 init
88
        output_selector.next = (state == t_State.display_init) | (state == t_State.init_fifteenms) | (state == t_State.init_one) | (state == t_State.init_two) | (state == t_State.init_three) | (state == t_State.init_four) | (state == t_State.init_five) | (state == t_State.init_six) | (state == t_State.init_seven) | (state == t_State.init_eight)
89
 
90
    @always_comb
91
    def output_tx_or_init_mux():
92
        if output_selector: # Init
93
            SF_D.next = SF_D1
94
            LCD_E.next = LCD_E1
95
        else: # TX
96
            SF_D.next = SF_D0
97
            LCD_E.next = LCD_E0
98
 
99
 
100
    @always_comb
101
    def init_transmissions():
102
        tx_init.next = (~tx_done) & ((state == t_State.display_function_set) | (state == t_State.display_entry_set) | (state == t_State.display_set_display) | (state == t_State.display_clr_display) | (state == t_State.display_set_addr1) | (state == t_State.display_char_write1) | (state == t_State.display_set_addr2) | (state == t_State.display_char_write2))
103
        LCD_RS.next = ~(bool(state == t_State.display_function_set) | (state == t_State.display_entry_set) | (state == t_State.display_set_display) | (state == t_State.display_clr_display) | (state == t_State.display_set_addr1) | (state == t_State.display_set_addr2))
104
 
105
    @always(clk.posedge, reset.posedge)
106
    def DisplayFSM():
107
        if reset == 1:
108
            state.next = t_State.display_init
109
            main_delay_load.next = 0
110
            main_delay_value.next = 0
111
            SF_D1.next = 0
112
            LCD_E1.next = 0
113
            tx_byte.next = 0
114
            pos.next = MEM_LOW1
115
        else:
116
            main_delay_load.next = 0;
117
            main_delay_value.next = 0;
118
            if state == t_State.display_init:
119
                tx_byte.next = 0 #00000000
120
 
121
                state.next = t_State.init_fifteenms
122
                main_delay_load.next = 1
123
                main_delay_value.next = 750000
124
 
125
            elif state == t_State.init_fifteenms:
126
                main_delay_load.next = 0
127
 
128
                if delay_done:
129
                    state.next = t_State.init_one;
130
                    main_delay_load.next = 1
131
                    main_delay_value.next = 11
132
 
133
            elif state == t_State.init_one:
134
                main_delay_load.next = 0
135
                SF_D1.next = 3
136
                LCD_E1.next = 1
137
 
138
                if delay_done:
139
                    state.next = t_State.init_two;
140
                    main_delay_load.next = 1
141
                    main_delay_value.next = 205000
142
 
143
            elif state == t_State.init_two:
144
                main_delay_load.next = 0
145
                LCD_E1.next = 0
146
 
147
                if delay_done:
148
                    state.next = t_State.init_three;
149
                    main_delay_load.next = 1
150
                    main_delay_value.next = 11
151
 
152
            elif state == t_State.init_three:
153
                main_delay_load.next = 0
154
                SF_D1.next = 3
155
                LCD_E1.next = 1
156
 
157
                if delay_done:
158
                    state.next = t_State.init_four;
159
                    main_delay_load.next = 1
160
                    main_delay_value.next = 5000
161
 
162
            elif state == t_State.init_four:
163
                main_delay_load.next = 0
164
                LCD_E1.next = 0
165
 
166
                if delay_done:
167
                    state.next = t_State.init_five;
168
                    main_delay_load.next = 1
169
                    main_delay_value.next = 11
170
 
171
 
172
            elif state == t_State.init_five:
173
                main_delay_load.next = 0
174
                SF_D1.next = 3
175
                LCD_E1.next = 1
176
 
177
                if delay_done:
178
                    state.next = t_State.init_six;
179
                    main_delay_load.next = 1
180
                    main_delay_value.next = 2000
181
 
182
            elif state == t_State.init_six:
183
                main_delay_load.next = 0
184
                LCD_E1.next = 0
185
 
186
                if delay_done:
187
                    state.next = t_State.init_seven;
188
                    main_delay_load.next = 1
189
                    main_delay_value.next = 11
190
 
191
            elif state == t_State.init_seven:
192
                main_delay_load.next = 0
193
                SF_D1.next = 2
194
                LCD_E1.next = 1
195
 
196
                if delay_done:
197
                    state.next = t_State.init_eight;
198
                    main_delay_load.next = 1
199
                    main_delay_value.next = 2000
200
 
201
            elif state == t_State.init_eight:
202
                main_delay_load.next = 0
203
                LCD_E1.next = 0
204
 
205
                if delay_done:
206
                    state.next = t_State.display_function_set;
207
 
208
            elif state == t_State.display_function_set:
209
                tx_byte.next = 40 #00101000
210
                if tx_done:
211
                    state.next = t_State.display_entry_set
212
 
213
            elif state == t_State.display_entry_set:
214
                tx_byte.next = 6 #00000110
215
                if tx_done:
216
                    state.next = t_State.display_set_display
217
 
218
            elif state == t_State.display_set_display:
219
                tx_byte.next = 12 #00001100
220
                if tx_done:
221
                    state.next = t_State.display_clr_display
222
 
223
            elif state == t_State.display_clr_display:
224
                tx_byte.next = 1 #00000001
225
                if tx_done:
226
                    state.next = t_State.display_pause_setup
227
                    main_delay_load.next = 1
228
                    main_delay_value.next = 82000
229
 
230
            elif state == t_State.display_pause_setup:
231
                state.next = t_State.display_pause
232
 
233
            elif state == t_State.display_pause:
234
                tx_byte.next = 0 #00000000
235
 
236
                if delay_done:
237
                    state.next = t_State.display_set_addr1;
238
 
239
            elif state == t_State.display_set_addr1:
240
                tx_byte.next = 192 #128 #10000000
241
                if tx_done:
242
                    state.next = t_State.display_char_write1
243
                    pos.next = MEM_LOW1
244
 
245
            elif state == t_State.display_char_write1:
246
                tx_byte.next = ram[pos]
247
                if tx_done:
248
                    if pos == MEM_HIGH1:
249
                        state.next = t_State.display_done #t_State.display_set_addr2;
250
                    else:
251
                        pos.next = pos + 1
252
            elif state == t_State.display_set_addr2:
253
                tx_byte.next = 192 #11000000
254
                if tx_done:
255
                    state.next = t_State.display_char_write2
256
                    pos.next = MEM_LOW2
257
 
258
            elif state == t_State.display_char_write2:
259
                tx_byte.next = ram[pos]
260
                if tx_done:
261
                    if pos == MEM_HIGH2:
262
                        state.next = t_State.display_done;
263
                    else:
264
                        pos.next = pos + 1
265
 
266
            elif state == t_State.display_done:
267
                tx_byte.next = 0 #00000000
268
 
269
                if repaint:
270
                    state.next = t_State.display_function_set
271
                else:
272
                    state.next = t_State.display_done
273
 
274
           # else:
275
 
276
               # raise ValueError("Undefined Display state")
277
 
278
 
279
 
280
    @always(clk.posedge, reset.posedge)
281
    def TxFSM():
282
        if reset == 1:
283
            tx_state.next = t_TxState.tx_done
284
            SF_D0.next = 0
285
            LCD_E0.next = 0
286
        else:
287
            tx_delay_load.next = 0;
288
            tx_delay_value.next = 0;
289
            if tx_state == t_TxState.tx_high_setup:
290
                LCD_E0.next = 0
291
                SF_D0.next = tx_byte[8 : 4]
292
                tx_delay_load.next = 0
293
                if delay_done:
294
                    tx_state.next = t_TxState.tx_high_hold
295
                    tx_delay_load.next = 1
296
                    tx_delay_value.next = 12
297
 
298
            elif tx_state == t_TxState.tx_high_hold:
299
                LCD_E0.next = 1
300
                SF_D0.next = tx_byte[8 : 4]
301
                tx_delay_load.next = 0
302
                if delay_done:
303
                    tx_state.next = t_TxState.tx_oneus
304
                    tx_delay_load.next = 1
305
                    tx_delay_value.next = 50
306
 
307
            elif tx_state == t_TxState.tx_oneus:
308
                LCD_E0.next = 0
309
                tx_delay_load.next = 0
310
                if delay_done:
311
                    tx_state.next = t_TxState.tx_low_setup
312
                    tx_delay_load.next = 1
313
                    tx_delay_value.next = 2
314
 
315
            elif tx_state == t_TxState.tx_low_setup:
316
                LCD_E0.next = 0
317
                SF_D0.next = tx_byte[4 : 0]
318
                tx_delay_load.next = 0
319
                if delay_done:
320
                    tx_state.next = t_TxState.tx_low_hold
321
                    tx_delay_load.next = 1
322
                    tx_delay_value.next = 12
323
 
324
            elif tx_state == t_TxState.tx_low_hold:
325
                LCD_E0.next = 1
326
                SF_D0.next = tx_byte[4 : 0]
327
                tx_delay_load.next = 0
328
                if delay_done:
329
                    tx_state.next = t_TxState.tx_fortyus
330
                    tx_delay_load.next = 1
331
                    tx_delay_value.next = 2000
332
 
333
            elif tx_state == t_TxState.tx_fortyus:
334
                LCD_E0.next = 0
335
                tx_delay_load.next = 0
336
                if delay_done:
337
                    tx_state.next = t_TxState.tx_done
338
                    tx_done.next = 1
339
 
340
            elif tx_state == t_TxState.tx_done:
341
                LCD_E0.next = 0
342
                tx_done.next = 0
343
                tx_delay_load.next = 0
344
                if tx_init:
345
                    tx_state.next = t_TxState.tx_high_setup
346
                    tx_delay_load.next = 1
347
                    tx_delay_value.next = 2
348
           # else:
349
           #     raise ValueError("Undefined TX state")
350
 
351
    return instances()
352
 
353
def main():
354
    width = 20
355
 
356
    count = Signal(intbv(0)[width:0])
357
    clk, reset, we, repaint, busy, LCD_E, LCD_RS, LCD_RW = [Signal(bool(0)) for i in range(8)]
358
    dat = Signal(intbv(0)[32:0])
359
    addr = Signal(intbv(0)[7:0])
360
    SF_D = Signal(intbv(0)[4:0])
361
 
362
    toVerilog(lcd,clk, reset, dat, addr, we, repaint, busy, SF_D, LCD_E, LCD_RS, LCD_RW)
363
#    toVHDL(delayCounter, clk, reset, count, load, done, width)
364
if __name__ == '__main__':
365
    main()
366
 

powered by: WebSVN 2.1.0

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