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

powered by: WebSVN 2.1.0

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