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

Subversion Repositories igor

[/] [igor/] [trunk/] [processor/] [mc/] [lcdlevel.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 atypic
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
---- Uncomment the following library declaration if instantiating
7
---- any Xilinx primitives in this code.
8
--library UNISIM;
9
--use UNISIM.VComps1nts.all;
10
 
11
entity lcd is
12
  port(
13
  clk, reset, reset_leval : in std_logic;
14
  sw : in std_logic_vector(3 downto 0); -- slide switch
15
  SF_D : out std_logic_vector(3 downto 0);
16
  LCD_E, LCD_RS, LCD_RW, SF_CE0 : out std_logic;
17
  LED : out std_logic_vector(7 downto 0)
18
);
19
end lcd;
20
 
21
architecture behavior of lcd is
22
 
23
type display_state is (init, function_set, s1, entry_set, s2, set_display, s3, clr_display, s4, pause, set_addr, s5, update, s6, done);
24
signal cur_state : display_state := init;
25
 
26
signal SF_D0, SF_D1 : std_logic_vector(3 downto 0);
27
signal LCD_E0, LCD_E1 : std_logic;
28
signal mux : std_logic;
29
 
30
type tx_sequence is (high_setup, high_hold, oneus, low_setup, low_hold, fortyus, done);
31
signal tx_state : tx_sequence := done;
32
signal tx_byte : std_logic_vector(7 downto 0);
33
signal tx_init : std_logic := '0';
34
signal tx_rdy : std_logic := '0';
35
 
36
type init_sequence is (idle, fifteenms, s1, s2, s3, s4, s5, s6, s7, s8, done);
37
signal init_state : init_sequence := idle;
38
signal init_init, init_done : std_logic := '0';
39
 
40
signal i : integer range 0 to 750000 := 0;
41
signal i2 : integer range 0 to 2000 := 0;
42
signal i3 : integer range 0 to 82000 := 0;
43
signal i4 : integer range 0 to 50000000 := 0;
44
 
45
signal num : std_logic_vector(3 downto 0);
46
 
47
signal l_pos : std_logic_vector(4 downto 0);
48
signal var : std_logic_vector(7 downto 0);
49
 
50
constant CHAR_SPACE : std_logic_vector(7 downto 0) := "00100000";
51
constant CHAR_COLON : std_logic_vector(7 downto 0) := "00111010";
52
constant CHAR_0 : std_logic_vector(7 downto 0) := "00110000";
53
constant CHAR_1 : std_logic_vector(7 downto 0) := "00110001";
54
constant CHAR_2 : std_logic_vector(7 downto 0) := "00110010";
55
constant CHAR_3 : std_logic_vector(7 downto 0) := "00110011";
56
constant CHAR_4 : std_logic_vector(7 downto 0) := "00110100";
57
constant CHAR_5 : std_logic_vector(7 downto 0) := "00110101";
58
constant CHAR_6 : std_logic_vector(7 downto 0) := "00110110";
59
constant CHAR_7 : std_logic_vector(7 downto 0) := "00110111";
60
constant CHAR_8 : std_logic_vector(7 downto 0) := "00111000";
61
constant CHAR_9 : std_logic_vector(7 downto 0) := "00111001";
62
constant CHAR_A : std_logic_vector(7 downto 0) := "01000001";
63
constant CHAR_B : std_logic_vector(7 downto 0) := "01000010";
64
constant CHAR_C : std_logic_vector(7 downto 0) := "01000011";
65
constant CHAR_D : std_logic_vector(7 downto 0) := "01000100";
66
constant CHAR_E : std_logic_vector(7 downto 0) := "01000101";
67
constant CHAR_F : std_logic_vector(7 downto 0) := "01000110";
68
constant CHAR_G : std_logic_vector(7 downto 0) := "01000111";
69
constant CHAR_H : std_logic_vector(7 downto 0) := "01001000";
70
constant CHAR_I : std_logic_vector(7 downto 0) := "01001001";
71
constant CHAR_J : std_logic_vector(7 downto 0) := "01001010";
72
constant CHAR_K : std_logic_vector(7 downto 0) := "01001011";
73
constant CHAR_L : std_logic_vector(7 downto 0) := "01001100";
74
constant CHAR_M : std_logic_vector(7 downto 0) := "01001101";
75
constant CHAR_N : std_logic_vector(7 downto 0) := "01001110";
76
constant CHAR_O : std_logic_vector(7 downto 0) := "01001111";
77
constant CHAR_P : std_logic_vector(7 downto 0) := "01010000";
78
constant CHAR_Q : std_logic_vector(7 downto 0) := "01010001";
79
constant CHAR_R : std_logic_vector(7 downto 0) := "01010010";
80
constant CHAR_S : std_logic_vector(7 downto 0) := "01010011";
81
constant CHAR_T : std_logic_vector(7 downto 0) := "01010100";
82
constant CHAR_U : std_logic_vector(7 downto 0) := "01010101";
83
constant CHAR_V : std_logic_vector(7 downto 0) := "01010110";
84
constant CHAR_W : std_logic_vector(7 downto 0) := "01010111";
85
constant CHAR_X : std_logic_vector(7 downto 0) := "01011000";
86
constant CHAR_Y : std_logic_vector(7 downto 0) := "01011001";
87
constant CHAR_Z : std_logic_vector(7 downto 0) := "01011010";
88
 
89
type lcd_char is array(0 to 31) of std_logic_vector(7 downto 0);
90
signal lcd_char_set : lcd_char;
91
-- Signals to top level
92
signal leval_clk : std_logic := '0';
93
signal leval_rst : std_logic;
94
--signal pause is uneeded
95
signal leval_bus_addr : std_logic_vector(31 downto 0);
96
signal leval_bus_data : std_logic_vector(31 downto 0);
97
signal leval_pc : std_logic_vector(15 downto 0) := "0000000000000000";
98
signal leval_rd : std_logic;
99
signal leval_wr : std_logic;
100
 
101
function lcd_bin_to_hex(input : std_logic_vector(3 downto 0))
102
  return std_logic_vector is
103
    variable output : std_logic_vector(7 downto 0);
104
  begin
105
    if input > "1001" then
106
      output := "0100"&(input-"1001");
107
    else
108
      output := "0011"&input;
109
    end if;
110
    return output;
111
  end function;
112
 
113
  -- LEVAL declaration
114
  component leval is
115
     port(
116
       -- Inputs
117
       pause : in std_logic;
118
       rst : in std_logic; -- convert to synchronous
119
       clk : in std_logic;
120
       -- Bus communication
121
       data_bus : inout std_logic_vector(31 downto 0);
122
       addr_bus : out std_logic_vector(25 downto 0);
123
       wait_s : in std_logic;
124
       read     : out std_logic;
125
       write : out std_logic;
126
       led : out std_logic_vector(7 downto 0);
127
       pc_out : out std_logic_vector(12 downto 0));
128
  end component leval;
129
 
130
begin
131
   -- Initiate CPU and connect signal
132
  leval_inst : leval
133
  port map (
134
    pause => '0',
135
    rst => leval_rst,
136
    clk => leval_clk,
137
    data_bus => leval_bus_data,
138
    addr_bus => leval_bus_addr(25 downto 0),
139
    read => leval_rd,
140
    write => leval_wr,
141
    wait_s => sw(1),
142
    pc_out => leval_pc(12 downto 0));
143
 
144
        leval_pc(15 downto 13) <= (others => '0');
145
   leval_bus_addr(31 downto 26) <= (others => '0');
146
        leval_rst <= reset_leval;
147
 
148
  LED <= leval_wr&leval_rd&leval_pc(3 downto 0)&leval_rst&leval_clk;
149
  --LED <= tx_byte; --for diagnostic purposes
150
 
151
 
152
   --- Writing code. Letters on the left side will be written to address on the left side
153
  with l_pos select
154
     var <=
155
       CHAR_P when "00000",
156
       CHAR_C when "00001",
157
      CHAR_COLON when "00010",
158
      lcd_char_set(3) when "00011",
159
      lcd_char_set(4) when "00100",
160
      lcd_char_set(5) when "00101",
161
      lcd_char_set(6) when "00110",
162
      lcd_char_set(7) when "00111",
163
      CHAR_A when "01000",
164
      CHAR_D when "01001",
165
      CHAR_R when "01010",
166
      CHAR_COLON when "01011",
167
      lcd_char_set(12) when "01100",
168
      lcd_char_set(13) when "01101",
169
      lcd_char_set(14) when "01110",
170
      lcd_char_set(15) when "01111",
171
      CHAR_D when "10000",
172
       CHAR_A when "10001",
173
      CHAR_T when "10010",
174
      CHAR_A when "10011",
175
      CHAR_COLON when "10100",
176
      lcd_char_set(21) when "10101",
177
      lcd_char_set(22) when "10110",
178
      lcd_char_set(23) when "10111",
179
      lcd_char_set(24) when "11000",
180
      lcd_char_set(25) when "11001",
181
      lcd_char_set(26) when "11010",
182
      lcd_char_set(27) when "11011",
183
      lcd_char_set(28) when "11100",
184
      lcd_char_set(29) when "11101",
185
      lcd_char_set(30) when "11110",
186
      lcd_char_set(31) when "11111",
187
      "00100000" when others;
188
 
189
  SF_CE0 <= '1'; --disable intel strataflash
190
  LCD_RW <= '0'; --write only
191
 
192
  --when to transmit a command/data and when not to
193
  with cur_state select
194
    tx_init <= '1' when function_set | entry_set | set_display | clr_display | set_addr | update,
195
      '0' when others;
196
 
197
  --control the bus
198
  with cur_state select
199
    mux <= '1' when init,
200
      '0' when others;
201
 
202
  --control the initialization sequence
203
  with cur_state select
204
    init_init <= '1' when init,
205
      '0' when others;
206
 
207
  --register select
208
  with cur_state select
209
    LCD_RS <= '0' when s1|s2|s3|s4|s5,
210
      '1' when others;
211
 
212
  with cur_state select
213
    tx_byte <= "00101000" when s1,
214
      "00000110" when s2,
215
      "00001100" when s3,
216
      "00000001" when s4,
217
      "1"&l_pos(4)&"00"&l_pos(3 downto 0) when s5,
218
      var when s6,
219
      "00000000" when others;
220
 
221
  counter: process(clk, reset)
222
  begin
223
    if(reset = '1') then
224
      i4 <= 0;
225
      num <= "0000";
226
      leval_clk <= '0';
227
      for i in 0 to 31 loop
228
         lcd_char_set(i) <= "00100000";
229
      end loop;
230
    elsif(clk='1' and clk'event and sw(0)='1') then
231
      lcd_char_set(0) <= "0011"&num;
232
       if(i4 = 25000000) then
233
         leval_clk <= not leval_clk;
234
      end if;
235
      if(i4 = 50000000) then
236
         leval_clk <= not leval_clk;
237
        i4 <= 0;
238
        if(num = "1001") then
239
          num <= "0000";
240
        else
241
          num <= num + '1';
242
        end if;
243
      else
244
         i4 <= i4 + 1;
245
      end if;
246
                -- Update chars on LCD
247
      -- Program Counter
248
      lcd_char_set(3) <= lcd_bin_to_hex(leval_pc(15 downto 12));
249
      lcd_char_set(4) <= lcd_bin_to_hex(leval_pc(11 downto 8));
250
      lcd_char_set(5) <= lcd_bin_to_hex(leval_pc(7 downto 4));
251
      lcd_char_set(6) <= lcd_bin_to_hex(leval_pc(3 downto 0));
252
      -- Address Bus
253
      lcd_char_set(12) <= lcd_bin_to_hex(leval_bus_addr(15 downto 12));
254
      lcd_char_set(13) <= lcd_bin_to_hex(leval_bus_addr(11 downto 8));
255
      lcd_char_set(14) <= lcd_bin_to_hex(leval_bus_addr(7 downto 4));
256
      lcd_char_set(15) <= lcd_bin_to_hex(leval_bus_addr(3 downto 0));
257
      -- Data Bus
258
      lcd_char_set(21) <= lcd_bin_to_hex(leval_bus_data(31 downto 28));
259
      lcd_char_set(22) <= lcd_bin_to_hex(leval_bus_data(27 downto 24));
260
      lcd_char_set(23) <= lcd_bin_to_hex(leval_bus_data(23 downto 20));
261
      lcd_char_set(24) <= lcd_bin_to_hex(leval_bus_data(19 downto 16));
262
      lcd_char_set(25) <= lcd_bin_to_hex(leval_bus_data(15 downto 12));
263
      lcd_char_set(26) <= lcd_bin_to_hex(leval_bus_data(11 downto 8));
264
      lcd_char_set(27) <= lcd_bin_to_hex(leval_bus_data(7 downto 4));
265
      lcd_char_set(28) <= lcd_bin_to_hex(leval_bus_data(3 downto 0));
266
    end if;
267
  end process counter;
268
 
269
  --main state machine
270
  display: process(clk, reset)
271
  begin
272
    if(reset='1') then
273
      cur_state <= init;
274
    elsif(clk='1' and clk'event) then
275
      case cur_state is
276
        when init =>
277
          if(init_done = '1') then
278
            cur_state <= function_set;
279
          else
280
            cur_state <= init;
281
          end if;
282
 
283
        when function_set =>
284
          cur_state <= s1;
285
 
286
        when s1 =>
287
          if(tx_rdy = '1') then
288
            cur_state <= entry_set;
289
          else
290
            cur_state <= s1;
291
          end if;
292
 
293
        when entry_set =>
294
          cur_state <= s2;
295
 
296
        when s2 =>
297
          if(tx_rdy = '1') then
298
            cur_state <= set_display;
299
          else
300
            cur_state <= s2;
301
          end if;
302
 
303
        when set_display =>
304
          cur_state <= s3;
305
 
306
        when s3 =>
307
          if(tx_rdy = '1') then
308
            cur_state <= clr_display;
309
          else
310
            cur_state <= s3;
311
          end if;
312
 
313
        when clr_display =>
314
          cur_state <= s4;
315
 
316
        when s4 =>
317
          i3 <= 0;
318
          if(tx_rdy = '1') then
319
            cur_state <= pause;
320
          else
321
            cur_state <= s4;
322
          end if;
323
 
324
        when pause =>
325
          if(i3 = 82000) then
326
            cur_state <= set_addr;
327
            i3 <= 0;
328
          else
329
            cur_state <= pause;
330
            i3 <= i3 + 1;
331
          end if;
332
 
333
        when set_addr =>
334
          cur_state <= s5;
335
 
336
        when s5 =>
337
          if(tx_rdy = '1') then
338
            cur_state <= update;
339
          else
340
            cur_state <= s5;
341
          end if;
342
 
343
        when update =>
344
          cur_state <= s6;
345
 
346
        when s6 =>
347
          if(tx_rdy = '1') then
348
            cur_state <= set_addr;
349
            l_pos <= l_pos + '1';
350
          else
351
            cur_state <= s6;
352
          end if;
353
 
354
        when done =>
355
          cur_state <= done;
356
 
357
      end case;
358
    end if;
359
  end process display;
360
 
361
  with mux select
362
    SF_D <= SF_D0 when '0', --transmit
363
      SF_D1 when others;        --initialize
364
  with mux select
365
    LCD_E <= LCD_E0 when '0', --transmit
366
      LCD_E1 when others; --initialize
367
 
368
  with tx_state select
369
    tx_rdy <= '1' when done,
370
      '0' when others;
371
 
372
  with tx_state select
373
    LCD_E0 <= '0' when high_setup | oneus | low_setup | fortyus | done,
374
      '1' when high_hold | low_hold;
375
 
376
  with tx_state select
377
    SF_D0 <= tx_byte(7 downto 4) when high_setup | high_hold | oneus,
378
      tx_byte(3 downto 0) when low_setup | low_hold | fortyus | done;
379
 
380
 
381
  --specified by datasheet
382
  transmit : process(clk, reset, tx_init)
383
  begin
384
    if(reset='1') then
385
      tx_state <= done;
386
    elsif(clk='1' and clk'event) then
387
      case tx_state is
388
        when high_setup => --40ns
389
          if(i2 = 2) then
390
            tx_state <= high_hold;
391
            i2 <= 0;
392
          else
393
            tx_state <= high_setup;
394
            i2 <= i2 + 1;
395
          end if;
396
 
397
        when high_hold => --230ns
398
          if(i2 = 12) then
399
            tx_state <= oneus;
400
            i2 <= 0;
401
          else
402
            tx_state <= high_hold;
403
            i2 <= i2 + 1;
404
          end if;
405
 
406
        when oneus =>
407
          if(i2 = 50) then
408
            tx_state <= low_setup;
409
            i2 <= 0;
410
          else
411
            tx_state <= oneus;
412
            i2 <= i2 + 1;
413
          end if;
414
 
415
        when low_setup =>
416
          if(i2 = 2) then
417
            tx_state <= low_hold;
418
            i2 <= 0;
419
          else
420
            tx_state <= low_setup;
421
            i2 <= i2 + 1;
422
          end if;
423
 
424
        when low_hold =>
425
          if(i2 = 12) then
426
            tx_state <= fortyus;
427
            i2 <= 0;
428
          else
429
            tx_state <= low_hold;
430
            i2 <= i2 + 1;
431
          end if;
432
 
433
        when fortyus =>
434
          if(i2 = 2000) then
435
            tx_state <= done;
436
            i2 <= 0;
437
          else
438
            tx_state <= fortyus;
439
            i2 <= i2 + 1;
440
          end if;
441
 
442
        when done =>
443
          if(tx_init = '1') then
444
            tx_state <= high_setup;
445
            i2 <= 0;
446
          else
447
            tx_state <= done;
448
            i2 <= 0;
449
          end if;
450
 
451
      end case;
452
    end if;
453
  end process transmit;
454
 
455
  with init_state select
456
    init_done <= '1' when done,
457
      '0' when others;
458
 
459
  with init_state select
460
    SF_D1 <= "0011" when s1 | s2 | s3 | s4 | s5 | s6,
461
      "0010" when others;
462
 
463
  with init_state select
464
    LCD_E1 <= '1' when s1 | s3 | s5 | s7,
465
      '0' when others;
466
 
467
  --specified by datasheet
468
  power_on_initialize: process(clk, reset, init_init) --power on initialization sequence
469
  begin
470
    if(reset='1') then
471
      init_state <= idle;
472
    elsif(clk='1' and clk'event) then
473
      case init_state is
474
        when idle =>
475
          if(init_init = '1') then
476
            init_state <= fifteenms;
477
            i <= 0;
478
          else
479
            init_state <= idle;
480
            i <= i + 1;
481
          end if;
482
 
483
        when fifteenms =>
484
          if(i = 750000) then
485
            init_state <= s1;
486
            i <= 0;
487
          else
488
            init_state <= fifteenms;
489
            i <= i + 1;
490
          end if;
491
 
492
        when s1 =>
493
          if(i = 11) then
494
            init_state<=s2;
495
            i <= 0;
496
          else
497
            init_state<=s1;
498
            i <= i + 1;
499
          end if;
500
 
501
        when s2 =>
502
          if(i = 205000) then
503
            init_state<=s3;
504
            i <= 0;
505
          else
506
            init_state<=s2;
507
            i <= i + 1;
508
          end if;
509
 
510
        when s3 =>
511
          if(i = 11) then
512
            init_state<=s4;
513
            i <= 0;
514
          else
515
            init_state<=s3;
516
            i <= i + 1;
517
          end if;
518
 
519
        when s4 =>
520
          if(i = 5000) then
521
            init_state<=s5;
522
            i <= 0;
523
          else
524
            init_state<=s4;
525
            i <= i + 1;
526
          end if;
527
 
528
        when s5 =>
529
          if(i = 11) then
530
            init_state<=s6;
531
            i <= 0;
532
          else
533
            init_state<=s5;
534
            i <= i + 1;
535
          end if;
536
 
537
        when s6 =>
538
          if(i = 2000) then
539
            init_state<=s7;
540
            i <= 0;
541
          else
542
            init_state<=s6;
543
            i <= i + 1;
544
          end if;
545
 
546
        when s7 =>
547
          if(i = 11) then
548
            init_state<=s8;
549
            i <= 0;
550
          else
551
            init_state<=s7;
552
            i <= i + 1;
553
          end if;
554
 
555
        when s8 =>
556
          if(i = 2000) then
557
            init_state<=done;
558
            i <= 0;
559
          else
560
            init_state<=s8;
561
            i <= i + 1;
562
          end if;
563
 
564
        when done =>
565
          init_state <= done;
566
 
567
      end case;
568
 
569
    end if;
570
  end process power_on_initialize;
571
 
572
end behavior;
573
 

powered by: WebSVN 2.1.0

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