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

powered by: WebSVN 2.1.0

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