-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPIC16F54.v
231 lines (201 loc) · 4.52 KB
/
PIC16F54.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: Yuechuan Xue
//
// Create Date: 2015/07/09 14:26:01
// Design Name:
// Module Name: PIC16F54
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module PIC16F54(rst, clk, porta_in, portb_in, porta_out, portb_out,
porta_tris, portb_tris, wdtmr, tmr0_inc, option_out);
input rst;
input clk;
input [3:0] porta_in;
input [7:0] portb_in;
output [3:0] porta_out;
output [7:0] portb_out;
output [3:0] porta_tris;
output [7:0] portb_tris;
input wdtmr;
input tmr0_inc;
output [7:0] option_out;
reg PCH;
reg [7:0] PCL;
wire [8:0] PC;
assign PC = {PCH, PCL};
wire [8:0] PC_next;
wire [7:0] PCL1;
wire PCL_wr;
wire push, pop;
wire [8:0] stack_psh, stack_pop;
wire [11:0] Instr;
wire [4:0] f5 = Instr[4:0];
wire [7:0] K8 = Instr[7:0];
parameter INDF_adrs = 5'b00000000; // vitual address
wire [4:0] f_adrs;
wire [7:0] f_in_data;
wire [7:0] f_out_data;
wire [4:0] FSR;
wire C;
wire C_new, DC_new, Z_new;
wire [7:0] op_A_wire, op_B_wire;
wire [7:0] ALU_out;
reg [7:0] W;
wire [7:0] W_next;
wire SLEEP, CLRWDT;
wire OPTION_wr, TRISA_wr, TRISB_wr;
wire MOVWF, CLR, SUBWF, RLF, SWAPF;
wire [7:0] bit_mask;
wire Bit_Op, K8A_sel, K8W_sel;
wire [1:0] Op_Mux_L, Op_Mux_A, ALU_out_Mux;
wire Z_en, DC_en, C_en;
wire W_wr, f_wr;
Seqnc Seqnc_01
(
.rst(rst),
.Instr(Instr),
.PC(PC),
.f_in_data(f_in_data),
.PCL_wr(PCL_wr),
.Z(Z_new),
.PCL1(PCL1),
.PC_next(PC_next),
.push(push),
.pop(pop),
.stack_psh(stack_psh),
.stack_pop(stack_pop)
);
Stack Stack_01
(
.clk(clk),
.push(push),
.pop(pop),
.in(stack_psh),
.out(stack_pop)
);
// not sure ...
always @(posedge clk) {PCH, PCL} <= PC_next;
Prog_ROM Prog_ROM_01
(
.clk(clk),
.adrs(PC_next),
.data(Instr)
);
Decoder Decoder_01
(
// Input
.Instr(Instr),
// Output
.OPTION(OPTION_wr),
.SLEEP(SLEEP),
.CLRWDT(CLRWDT),
.TRIS1(TRISA_wr),
.TRIS2(TRISB_wr),
.MOVWF(MOVWF),
.CLR(CLR),
.SUBWF(SUBWF),
.RLF(RLF),
.SWAPF(SWAPF),
.BTFSS(), //not used here anymore
.RETLW(), //not used here anymore
.CALL(), //not used here anymore
.GOTO(), //not used here anymore
.bit_mask(bit_mask),
.Bit_Op(Bit_Op),
.K8A_sel(K8A_sel),
.K8W_sel(K8W_sel),
.Op_Mux_L(Op_Mux_L), // 0: 或 1: 与 2: 异或 3: 取反
.Op_Mux_A(Op_Mux_A), // 0: f加W 1: f减W 2: f增1 3: f减1
.ALU_out_Mux(ALU_out_Mux), // 0: Throu 1: Shift 2: Logic 3: Adder
.FSZ(), // not used here anymore
.Z_en(Z_en), // -> Reg_File
.DC_en(DC_en), // -> Reg_File
.C_en(C_en), // -> Reg_File
.STT_en(), // not used here anymore
.Stack_1_wr(), // not used here anymore
.W_wr(W_wr), //
.f_wr(f_wr),
.f_rd() //not used here anymore
);
// f_adrs == INDF_adrs : Indirect Addressing
// f_adrs == 2'h01 ~ 2'hFF : Direct Addressing
assign f_adrs = (f5 == INDF_adrs) ? FSR : f5;
Reg_File Reg_File_01 (
// Input
.rst(rst),
.clk(clk),
.tmr0_inc(tmr0_inc),
.C_en(C_en),
.DC_en(DC_en),
.Z_en(Z_en),
.SLEEP(SLEEP),
.CLRWDT(CLRWDT),
.wdtmr(wdtmr),
.f_wr(f_wr),
.f_adrs(f_adrs),
.C_new(C_new),
.DC_new(DC_new),
.Z_new(Z_new),
.f_in_data(f_in_data),
.PCL1(PCL1),
.porta_in(porta_in),
.portb_in(portb_in),
.f_out_data(f_out_data),
.PORTB(portb_out),
.PORTA(porta_out),
// Output
.FSR(FSR),
.C(C),
.PCL_wr(PCL_wr)
);
assign op_A_wire = K8A_sel ? K8 : f_out_data;
assign op_B_wire = Bit_Op ? bit_mask : W;
ALU8 ALU8_01
(
.clr(CLR),
.swap_n_mov(SWAPF),
.rlf_n_rrf(RLF),
.op_mux_l(Op_Mux_L),
.op_mux_a(Op_Mux_A),
.sub(SUBWF),
.out_mux(ALU_out_Mux),
.C_in(C),
.op_A1(f_out_data),
.op_B1(W),
.op_A(op_A_wire),
.op_B(op_B_wire),
.ALU_out(ALU_out),
.C_new(C_new),
.DC_new(DC_new),
.Z_new(Z_new)
);
assign f_in_data = MOVWF ? W : ALU_out;
assign W_next = K8W_sel? K8 : ALU_out;
always @(posedge clk)
if (W_wr) W <= W_next;
else W <= W;
Reg_Misc Reg_Misc_01
(
.rst(rst),
.clk(clk),
.TRISA_wr(TRISA_wr),
.TRISB_wr(TRISB_wr),
.OPTION_wr(OPTION_wr),
.W(W),
.TRISA(porta_tris),
.TRISB(portb_tris),
.OPTION(option_out)
);
endmodule