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/] [ad/] [70ea26074c28001e1cf7e9db6b36760d] - 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)[7:0])
38
    MEM_LOW1 =0
39
    MEM_LOW2 =15
40
    MEM_HIGH1 =40
41
    MEM_HIGH2 =55
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)[31:0]) for i in range(67)]
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
        else:
115
            main_delay_load.next = 0;
116
            main_delay_value.next = 0;
117
            if state == t_State.display_init:
118
                tx_byte.next = 00000000
119
 
120
                state.next = t_State.init_fifteenms
121
                main_delay_load.next = 1
122
                main_delay_value.next = 750000
123
 
124
            elif state == t_State.init_fifteenms:
125
                main_delay_load.next = 0
126
 
127
                if delay_done:
128
                    state.next = t_State.init_one;
129
                    main_delay_load.next = 1
130
                    main_delay_value.next = 11
131
 
132
            elif state == t_State.init_one:
133
                main_delay_load.next = 0
134
                SF_D1.next = 3
135
                LCD_E1.next = 1
136
 
137
                if delay_done:
138
                    state.next = t_State.init_two;
139
                    main_delay_load.next = 1
140
                    main_delay_value.next = 205000
141
 
142
            elif state == t_State.init_two:
143
                main_delay_load.next = 0
144
                LCD_E1.next = 0
145
 
146
                if delay_done:
147
                    state.next = t_State.init_three;
148
                    main_delay_load.next = 1
149
                    main_delay_value.next = 11
150
 
151
            elif state == t_State.init_three:
152
                main_delay_load.next = 0
153
                SF_D1.next = 3
154
                LCD_E1.next = 1
155
 
156
                if delay_done:
157
                    state.next = t_State.init_four;
158
                    main_delay_load.next = 1
159
                    main_delay_value.next = 5000
160
 
161
            elif state == t_State.init_four:
162
                main_delay_load.next = 0
163
                LCD_E1.next = 0
164
 
165
                if delay_done:
166
                    state.next = t_State.init_five;
167
                    main_delay_load.next = 1
168
                    main_delay_value.next = 11
169
 
170
 
171
            elif state == t_State.init_five:
172
                main_delay_load.next = 0
173
                SF_D1.next = 3
174
                LCD_E1.next = 1
175
 
176
                if delay_done:
177
                    state.next = t_State.init_six;
178
                    main_delay_load.next = 1
179
                    main_delay_value.next = 2000
180
 
181
            elif state == t_State.init_six:
182
                main_delay_load.next = 0
183
                LCD_E1.next = 0
184
 
185
                if delay_done:
186
                    state.next = t_State.init_seven;
187
                    main_delay_load.next = 1
188
                    main_delay_value.next = 11
189
 
190
            elif state == t_State.init_seven:
191
                main_delay_load.next = 0
192
                SF_D1.next = 2
193
                LCD_E1.next = 1
194
 
195
                if delay_done:
196
                    state.next = t_State.init_eight;
197
                    main_delay_load.next = 1
198
                    main_delay_value.next = 2000
199
 
200
            elif state == t_State.init_eight:
201
                main_delay_load.next = 0
202
                LCD_E1.next = 0
203
 
204
                if delay_done:
205
                    state.next = t_State.display_function_set;
206
 
207
            elif state == t_State.display_function_set:
208
                tx_byte.next = 00101000;
209
                if tx_done:
210
                    state.next = t_State.display_entry_set
211
 
212
            elif state == t_State.display_entry_set:
213
                tx_byte.next = 00000110;
214
                if tx_done:
215
                    state.next = t_State.display_set_display
216
 
217
            elif state == t_State.display_set_display:
218
                tx_byte.next = 00001100;
219
                if tx_done:
220
                    state.next = t_State.display_clr_display
221
 
222
            elif state == t_State.display_clr_display:
223
                tx_byte.next = 00000001;
224
                if tx_done:
225
                    state.next = t_State.display_pause_setup
226
                    main_delay_load.next = 1
227
                    main_delay_value.next = 82000
228
 
229
            elif state == t_State.display_pause_setup:
230
                state.next = t_State.display_pause
231
 
232
            elif state == t_State.display_pause:
233
                tx_byte.next = 00000000;
234
 
235
                if delay_done:
236
                    state.next = t_State.display_set_addr1;
237
 
238
            elif state == t_State.display_set_addr1:
239
                tx_byte.next = 00000000;
240
                if tx_done:
241
                    state.next = t_State.display_char_write1
242
                    pos.next = MEM_LOW1
243
 
244
            elif state == t_State.display_char_write1:
245
                tx_byte.next = ram[pos]
246
                if tx_done:
247
                    if pos == MEM_HIGH1:
248
                        state.next = t_State.display_set_addr1;
249
                    else:
250
                        pos.next = pos + 1
251
            elif state == t_State.display_set_addr2:
252
                tx_byte.next = 11000000;
253
                if tx_done:
254
                    state.next = t_State.display_char_write2
255
                    pos.next = MEM_LOW2
256
 
257
            elif state == t_State.display_char_write2:
258
                tx_byte.next = ram[pos]
259
                if tx_done:
260
                    if pos == MEM_HIGH2:
261
                        state.next = t_State.display_done;
262
                    else:
263
                        pos.next = pos + 1
264
 
265
            elif state == t_State.display_done:
266
                tx_byte.next = 00000000;
267
 
268
                if repaint:
269
                    state.next = t_State.display_function_set
270
                else:
271
                    state.next = t_State.display_done
272
 
273
            else:
274
 
275
                raise ValueError("Undefined Display state")
276
 
277
 
278
 
279
    @always(clk.posedge, reset.posedge)
280
    def TxFSM():
281
        if reset == 1:
282
            tx_state.next = t_TxState.tx_done
283
            SF_D0.next = 0
284
            LCD_E0.next = 0
285
        else:
286
            tx_delay_load.next = 0;
287
            tx_delay_value.next = 0;
288
            if tx_state == t_TxState.tx_high_setup:
289
                LCD_E0.next = 0
290
                SF_D0.next = tx_byte[8 : 4]
291
                tx_delay_load.next = 0
292
                if delay_done:
293
                    tx_state.next = t_TxState.tx_high_hold
294
                    tx_delay_load.next = 1
295
                    tx_delay_value.next = 12
296
 
297
            elif tx_state == t_TxState.tx_high_hold:
298
                LCD_E0.next = 1
299
                SF_D0.next = tx_byte[8 : 4]
300
                tx_delay_load.next = 0
301
                if delay_done:
302
                    tx_state.next = t_TxState.tx_oneus
303
                    tx_delay_load.next = 1
304
                    tx_delay_value.next = 50
305
 
306
            elif tx_state == t_TxState.tx_oneus:
307
                LCD_E0.next = 0
308
                tx_delay_load.next = 0
309
                if delay_done:
310
                    tx_state.next = t_TxState.tx_low_setup
311
                    tx_delay_load.next = 1
312
                    tx_delay_value.next = 2
313
 
314
            elif tx_state == t_TxState.tx_low_setup:
315
                LCD_E0.next = 0
316
                SF_D0.next = tx_byte[4 : 0]
317
                tx_delay_load.next = 0
318
                if delay_done:
319
                    tx_state.next = t_TxState.tx_low_hold
320
                    tx_delay_load.next = 1
321
                    tx_delay_value.next = 12
322
 
323
            elif tx_state == t_TxState.tx_low_hold:
324
                LCD_E0.next = 1
325
                SF_D0.next = tx_byte[4 : 0]
326
                tx_delay_load.next = 0
327
                if delay_done:
328
                    tx_state.next = t_TxState.tx_fortyus
329
                    tx_delay_load.next = 1
330
                    tx_delay_value.next = 2000
331
 
332
            elif tx_state == t_TxState.tx_fortyus:
333
                LCD_E0.next = 0
334
                tx_delay_load.next = 0
335
                if delay_done:
336
                    tx_state.next = t_TxState.tx_done
337
                    tx_done.next = 1
338
 
339
            elif tx_state == t_TxState.tx_done:
340
                LCD_E0.next = 0
341
                tx_done.next = 0
342
                tx_delay_load.next = 0
343
                if tx_init:
344
                    tx_state.next = t_TxState.tx_high_setup
345
                    tx_delay_load.next = 1
346
                    tx_delay_value.next = 2
347
            else:
348
                raise ValueError("Undefined TX state")
349
 
350
    return instances()
351
 
352
def main():
353
    width = 20
354
 
355
    count = Signal(intbv(0)[width:0])
356
    clk, reset, we, repaint, busy, LCD_E, LCD_RS, LCD_RW = [Signal(bool(0)) for i in range(8)]
357
    dat = Signal(intbv(0)[32:0])
358
    addr = Signal(intbv(0)[7:0])
359
    SF_D = Signal(intbv(0)[4:0])
360
 
361
    toVerilog(lcd,clk, reset, dat, addr, we, repaint, busy, SF_D, LCD_E, LCD_RS, LCD_RW)
362
#    toVHDL(delayCounter, clk, reset, count, load, done, width)
363
if __name__ == '__main__':
364
    main()
365
 

powered by: WebSVN 2.1.0

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