EmbDev.net

Forum: FPGA, VHDL & Verilog Keypad saved shifting display in Verilog


von Cm Y. (cmyang)


Attached files:

Rate this post
useful
not useful
I'm designing a number exchange module, and so far I've been able to 
make it display on Seven Segment Display (S-S-D), like if I press 0 it 
shows 0... etc. I'm using 2 sets of 4-bits S-S-D (Common Anode).

Now I want to do like:

    default states : 0000_0000
    Now if I press 1 : 0000_0001
    If I press 2 : 0000_0012
    etc.

Whichever key I press, the display will not erase the already displaying 
number, it will shift it to the left...

And when all 8 S-S-D is full of displaying numbers like: 486C_8763, at 
this moment, when I press a key enter a number, like 1 it should be like 
: 86C8_7631; it should keep shifting to the left.

Here's my attempted code, and only been able to display it on S-S-D, and 
display all S-S-D 0000_0000... still not able to do what's been describe 
above...
1
  module keydata 
2
    (
3
      input clk, //input clk 50MHz
4
      output reg [3:0]keyout=4'b1110, //Default scan value 4bits 
5
      input [3:0]keyin, //Keypad receive value
6
      output reg [7:0]SegOut, //Seven Segment Display output
7
      output reg [15:0]scano //Seven Segment Display Scans
8
    );
9
    
10
    integer z1=0,zz=0; //Registers for frequency dividing
11
    reg dclk; //Divided frequency clock
12
    reg [7:0]bcdz; //register for saving keypad's number value
13
    reg [3:0]scan; //scan states 
14
    
15
     
16
     
17
    always@(posedge clk)
18
    begin
19
     
20
    //---------------------
21
    if(z1==50000)   //frequency divider 
22
        begin
23
        z1<=0;
24
        scan<={scan[2:0],scan[3]}; //scanning pattern shifting resgister
25
        keyout<={keyout[2:0],keyout[3]};  
26
           //keypad column scanning 1110->1101->1011->0111->1110(loop)
27
        end
28
    else
29
        z1<=z1+1;
30
    //---------------------
31
        
32
        
33
    //---------------------
34
    if(zz==10000) //frequency divider for scanning
35
        begin
36
        zz<=0;
37
        dclk<=~dclk;
38
        end
39
    else
40
        zz<=zz+1;
41
    //--------------------- 
42
    end
43
     
44
    always@(posedge dclk)  //Seven Segment Scanning
45
        begin
46
            case(scan)
47
                    0: scano<=scano[3:0];
48
                    1: scano<=scano[7:4];
49
                    2: scano<=scano[11:8];
50
                    3: scano<=scano[15:12];
51
            endcase
52
        end
53
     
54
    always@(posedge dclk) //4x4 Keypad detecting 
55
    begin
56
     
57
     
58
        if (keyout==4'b1110) //Detecting which keyout is currently at scanning
59
            begin
60
            if(keyin==4'b0111) //Tell which key it is
61
                begin
62
                bcdz<=4'b1100;//C //the key's value,save by a register
63
                end
64
            else if(keyin==4'b1011)
65
                begin
66
                bcdz<=4'b1101; //D
67
                end
68
            else if(keyin==4'b1101)
69
                begin
70
                bcdz<=4'b1110; //E
71
                end
72
            else if(keyin==4'b1110)
73
                begin
74
                bcdz<=4'b1111;//F
75
                end
76
            end
77
            
78
        else if (keyout==4'b1101) //Using **else if** to differentiate priorities.
79
            begin
80
            if(keyin==4'b0111)
81
                begin
82
                bcdz<=4'b1000; //8
83
                end
84
            else if(keyin==4'b1011)
85
                begin
86
                bcdz<=4'b1001; //9
87
                end
88
            else if(keyin==4'b1101)
89
                begin
90
                bcdz<=4'b1010; //A
91
                end
92
            else if(keyin==4'b1110)
93
                begin
94
                bcdz<=4'b1011; //B
95
                end
96
            end
97
            
98
        else if (keyout==4'b1011) //4 scanning possibilities
99
            begin
100
            if(keyin==4'b0111)
101
                begin
102
                bcdz<=4'b0100; //4
103
                end
104
            else if(keyin==4'b1011)
105
                begin
106
                bcdz<=4'b0101; //5
107
                end
108
            else if(keyin==4'b1101)
109
                begin
110
                bcdz<=4'b0110; //6
111
                end
112
            else if(keyin==4'b1110)
113
                begin
114
                bcdz<=4'b0111; //7
115
                end
116
            end
117
            
118
        else if (keyout==4'b0111)
119
            begin
120
            if(keyin==4'b0111)
121
                begin
122
                bcdz<=4'b0000; //0
123
                end
124
            else if(keyin==4'b1011)
125
                begin
126
                bcdz<=4'b0001; //1
127
                end
128
            else if(keyin==4'b1101)
129
                begin
130
                bcdz<=4'b0010; //2
131
                end
132
            else if(keyin==4'b1110)
133
                begin
134
                bcdz<=4'b0011; //3
135
                end
136
            end
137
        end
138
     
139
    always@(bcdz) //Seven Segment Decoder
140
    begin
141
      case(bcdz)
142
          0  :  SegOut <=   8'hC0;
143
          1  :  SegOut <=   8'hF9;
144
          2  :  SegOut <=   8'hA4;
145
          3  :  SegOut <=   8'hB0;
146
          4  :  SegOut <=   8'h99;
147
          5  :  SegOut <=   8'h92;
148
          6  :  SegOut <=   8'h82;
149
          7  :  SegOut <=   8'hF8;
150
          8  :  SegOut <=   8'h80;
151
          9  :  SegOut <=   8'h98;
152
          10    :  SegOut <=   8'h88;
153
          11  :  SegOut <=   8'h83;
154
          12  :  SegOut <=   8'hC6;
155
          13  :  SegOut <=   8'hA1;
156
          14  :  SegOut <=   8'h86;
157
          15    :  SegOut <=   8'h8E;
158
          default  :  SegOut <= 8'hFF;
159
      endcase
160
    end
161
    endmodule

: Edited by User
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.