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

Subversion Repositories wb_lcd

[/] [wb_lcd/] [trunk/] [myhdl/] [wb_lcd_workspace_ramless/] [workspace/] [.metadata/] [.plugins/] [org.eclipse.core.resources/] [.history/] [24/] [609e8b71d229001e105494278c3b862d] - 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_done', 'display_set_addr', 'display_char_write')
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, 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
 
38
    @always_comb
39
    def busy_and_rw_handlers():
40
        busy.next = (state != t_State.display_done)
41
        LCD_RW.next = 0
42
 
43
    #Delay counter
44
    main_delay_load = Signal(bool())
45
    main_delay_value = Signal(intbv(0)[20:0])
46
 
47
    tx_delay_load = Signal(bool())
48
    main_delay_load = Signal(bool())
49
    delay_load = Signal(bool())
50
 
51
    tx_delay_value = Signal(intbv(0)[20:0])
52
    main_delay_value = Signal(intbv(0)[20:0])
53
    delay_value = Signal(intbv(0)[20:0])
54
 
55
    delay_done = Signal(bool())
56
    output_selector  = Signal(bool())
57
    counter = delayCounter(clk, reset, delay_value, delay_load, delay_done, width = 21)
58
 
59
    @always_comb
60
    def conunter_sharing_load():
61
        delay_load.next = tx_delay_load or main_delay_load
62
 
63
    @always_comb
64
    def conunter_sharing_value():
65
        if tx_delay_load:
66
            delay_value.next = tx_delay_value
67
        else:
68
            delay_value.next = main_delay_value
69
 
70
 
71
    # SF_D and LCD_E management for sharing between Init and TX phases.
72
    @always_comb
73
    def output_tx_or_init_select(): # 0 tx; 1 init
74
        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)
75
 
76
    @always_comb
77
    def output_tx_or_init_mux():
78
        if output_selector: # Init
79
            SF_D.next = SF_D1
80
            LCD_E.next = LCD_E1
81
        else: # TX
82
            SF_D.next = SF_D0
83
            LCD_E.next = LCD_E0
84
 
85
 
86
    @always_comb
87
    def init_transmissions():
88
        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_addr) | (state == t_State.display_char_write))
89
        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_addr))
90
 
91
    @always(clk.posedge, reset.posedge)
92
    def DisplayFSM():
93
        if reset == 1:
94
            state.next = t_State.display_init
95
            main_delay_load.next = 0
96
            main_delay_value.next = 0
97
            SF_D1.next = 0
98
            LCD_E1.next = 0
99
            tx_byte.next = 0
100
        else:
101
            main_delay_load.next = 0;
102
            main_delay_value.next = 0;
103
            if state == t_State.display_init:
104
                tx_byte.next = 0 #00000000
105
 
106
                state.next = t_State.init_fifteenms
107
                main_delay_load.next = 1
108
                main_delay_value.next = 750000
109
 
110
            elif state == t_State.init_fifteenms:
111
                main_delay_load.next = 0
112
 
113
                if delay_done:
114
                    state.next = t_State.init_one;
115
                    main_delay_load.next = 1
116
                    main_delay_value.next = 11
117
 
118
            elif state == t_State.init_one:
119
                main_delay_load.next = 0
120
                SF_D1.next = 3
121
                LCD_E1.next = 1
122
 
123
                if delay_done:
124
                    state.next = t_State.init_two;
125
                    main_delay_load.next = 1
126
                    main_delay_value.next = 205000
127
 
128
            elif state == t_State.init_two:
129
                main_delay_load.next = 0
130
                LCD_E1.next = 0
131
 
132
                if delay_done:
133
                    state.next = t_State.init_three;
134
                    main_delay_load.next = 1
135
                    main_delay_value.next = 11
136
 
137
            elif state == t_State.init_three:
138
                main_delay_load.next = 0
139
                SF_D1.next = 3
140
                LCD_E1.next = 1
141
 
142
                if delay_done:
143
                    state.next = t_State.init_four;
144
                    main_delay_load.next = 1
145
                    main_delay_value.next = 5000
146
 
147
            elif state == t_State.init_four:
148
                main_delay_load.next = 0
149
                LCD_E1.next = 0
150
 
151
                if delay_done:
152
                    state.next = t_State.init_five;
153
                    main_delay_load.next = 1
154
                    main_delay_value.next = 11
155
 
156
 
157
            elif state == t_State.init_five:
158
                main_delay_load.next = 0
159
                SF_D1.next = 3
160
                LCD_E1.next = 1
161
 
162
                if delay_done:
163
                    state.next = t_State.init_six;
164
                    main_delay_load.next = 1
165
                    main_delay_value.next = 2000
166
 
167
            elif state == t_State.init_six:
168
                main_delay_load.next = 0
169
                LCD_E1.next = 0
170
 
171
                if delay_done:
172
                    state.next = t_State.init_seven;
173
                    main_delay_load.next = 1
174
                    main_delay_value.next = 11
175
 
176
            elif state == t_State.init_seven:
177
                main_delay_load.next = 0
178
                SF_D1.next = 2
179
                LCD_E1.next = 1
180
 
181
                if delay_done:
182
                    state.next = t_State.init_eight;
183
                    main_delay_load.next = 1
184
                    main_delay_value.next = 2000
185
 
186
            elif state == t_State.init_eight:
187
                main_delay_load.next = 0
188
                LCD_E1.next = 0
189
 
190
                if delay_done:
191
                    state.next = t_State.display_function_set;
192
 
193
            elif state == t_State.display_function_set:
194
                tx_byte.next = 40 #00101000
195
                if tx_done:
196
                    state.next = t_State.display_entry_set
197
 
198
            elif state == t_State.display_entry_set:
199
                tx_byte.next = 6 #00000110
200
                if tx_done:
201
                    state.next = t_State.display_set_display
202
 
203
            elif state == t_State.display_set_display:
204
                tx_byte.next = 12 #00001100
205
                if tx_done:
206
                    state.next = t_State.display_clr_display
207
 
208
            elif state == t_State.display_clr_display:
209
                tx_byte.next = 1 #00000001
210
                if tx_done:
211
                    state.next = t_State.display_pause_setup
212
                    main_delay_load.next = 1
213
                    main_delay_value.next = 82000
214
 
215
            elif state == t_State.display_pause_setup:
216
                state.next = t_State.display_pause
217
 
218
            elif state == t_State.display_pause:
219
                tx_byte.next = 0 #00000000
220
 
221
                if delay_done:
222
                    state.next = t_State.display_done;
223
 
224
            elif state == t_State.display_done:
225
                tx_byte.next = 0 #00000000
226
 
227
                if we:
228
                    state.next = t_State.display_set_addr
229
                else:
230
                    state.next = t_State.display_done
231
 
232
            elif state == t_State.display_set_addr:
233
                tx_byte.next = 128+addr #10000000
234
                if tx_done:
235
                    state.next = t_State.display_char_write
236
 
237
            elif state == t_State.display_char_write:
238
                tx_byte.next = dat
239
                if tx_done:
240
                    state.next = t_State.display_done;
241
           # else:
242
               # raise ValueError("Undefined Display state")
243
 
244
 
245
 
246
    @always(clk.posedge, reset.posedge)
247
    def TxFSM():
248
        if reset == 1:
249
            tx_state.next = t_TxState.tx_done
250
            SF_D0.next = 0
251
            LCD_E0.next = 0
252
        else:
253
            tx_delay_load.next = 0;
254
            tx_delay_value.next = 0;
255
            if tx_state == t_TxState.tx_high_setup:
256
                LCD_E0.next = 0
257
                SF_D0.next = tx_byte[8 : 4]
258
                tx_delay_load.next = 0
259
                if delay_done:
260
                    tx_state.next = t_TxState.tx_high_hold
261
                    tx_delay_load.next = 1
262
                    tx_delay_value.next = 12
263
 
264
            elif tx_state == t_TxState.tx_high_hold:
265
                LCD_E0.next = 1
266
                SF_D0.next = tx_byte[8 : 4]
267
                tx_delay_load.next = 0
268
                if delay_done:
269
                    tx_state.next = t_TxState.tx_oneus
270
                    tx_delay_load.next = 1
271
                    tx_delay_value.next = 50
272
 
273
            elif tx_state == t_TxState.tx_oneus:
274
                LCD_E0.next = 0
275
                tx_delay_load.next = 0
276
                if delay_done:
277
                    tx_state.next = t_TxState.tx_low_setup
278
                    tx_delay_load.next = 1
279
                    tx_delay_value.next = 2
280
 
281
            elif tx_state == t_TxState.tx_low_setup:
282
                LCD_E0.next = 0
283
                SF_D0.next = tx_byte[4 : 0]
284
                tx_delay_load.next = 0
285
                if delay_done:
286
                    tx_state.next = t_TxState.tx_low_hold
287
                    tx_delay_load.next = 1
288
                    tx_delay_value.next = 12
289
 
290
            elif tx_state == t_TxState.tx_low_hold:
291
                LCD_E0.next = 1
292
                SF_D0.next = tx_byte[4 : 0]
293
                tx_delay_load.next = 0
294
                if delay_done:
295
                    tx_state.next = t_TxState.tx_fortyus
296
                    tx_delay_load.next = 1
297
                    tx_delay_value.next = 2000
298
 
299
            elif tx_state == t_TxState.tx_fortyus:
300
                LCD_E0.next = 0
301
                tx_delay_load.next = 0
302
                if delay_done:
303
                    tx_state.next = t_TxState.tx_done
304
                    tx_done.next = 1
305
 
306
            elif tx_state == t_TxState.tx_done:
307
                LCD_E0.next = 0
308
                tx_done.next = 0
309
                tx_delay_load.next = 0
310
                if tx_init:
311
                    tx_state.next = t_TxState.tx_high_setup
312
                    tx_delay_load.next = 1
313
                    tx_delay_value.next = 2
314
           # else:
315
           #     raise ValueError("Undefined TX state")
316
 
317
    return instances()
318
 
319
def main():
320
    width = 20
321
 
322
    count = Signal(intbv(0)[width:0])
323
    clk, reset, we, busy, LCD_E, LCD_RS, LCD_RW = [Signal(bool(0)) for i in range(7)]
324
    dat = Signal(intbv(0)[32:0])
325
    addr = Signal(intbv(0)[7:0])
326
    SF_D = Signal(intbv(0)[4:0])
327
 
328
    toVerilog(lcd, clk, reset, dat, addr, we, busy, SF_D, LCD_E, LCD_RS, LCD_RW)
329
    toVHDL(lcd, clk, reset, dat, addr, we, busy, SF_D, LCD_E, LCD_RS, LCD_RW)
330
 
331
if __name__ == '__main__':
332
    main()
333
 

powered by: WebSVN 2.1.0

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