📄 syv.v
字号:
`define b begin
`define e end
////////////////////////////////////////////////////////////////////////////////
// Company: 中北大学
// Engineer: 石岩
//
// Create Date: 15:54:03 05/18/08
// Design Name:
// Module Name: syv
// Project Name:
// Target Device:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
////////////////////////////////////////////////////////////////////////////////
module syv(
global_clk, div_clock,
//--------------------interface with usb mcu--------
data_in, datam25_in, s_m25, datam25_out, hold_m25 , w_m25,
// --------------------lamp test------------------
led1, led2
);
//输入输出引脚定义///////////////////////////////////////////////////////////////////////////////
input global_clk;
output div_clock;
input [7:0]data_in;
input datam25_out;
output datam25_in;
output s_m25;
output w_m25;
output hold_m25;
output led1;
output led2;
//输出引脚映射变量///////////////////////////////////////////////////////////////////////////////////////
reg datam25_in = 0;
reg div_clock = 0;
reg s_m25;
reg led1;
reg led2= 0;
assign hold_m25 = 1;
assign w_m25 = 1;
// assign data_temp[7:0]=data_in[7:0];
//内部全局变量///////////////////////////////////////////////////////////////////////////////////
reg [7:0]data_temp = 0;
reg [9:0]counter_6M = 0;
reg [23:0]resetcount= 0;
reg [4:0]i = 0;
reg [3:0]j = 0;
reg [8:0]k = 0;
reg sys_reset = 0;
reg [5:0]st_wr = 0;
reg [23:0]w_addr24 = 0;
reg div_clock_t = 0;
reg [14:0]count1 = 0;
reg [5:0]count2 = 0;
//复位信号的产生*********************************************************************************
always @ (posedge global_clk) //6M晶振
`b
if ((resetcount <= 24'h00ffff)) //6M晶振全复位期间 约157us
`b
resetcount <= resetcount + 1 ;
// data_temp <=data_in;
sys_reset <= 1 ;
`e
else
`b
resetcount <= resetcount ;
// data_temp<=data_in;
sys_reset <= 0 ;
`e
`e
//计数循环控制*********************************************************************************
always @ (posedge global_clk)
`b
if(sys_reset)
`b
counter_6M <= 0;
div_clock <= 0;
`e
else
`b
if (counter_6M == 312)
`b
counter_6M <= 0;
div_clock <= ~div_clock;
led2 <= ~led2 ;
div_clock_t<= ~div_clock_t;
`e
else
`b
counter_6M <= counter_6M + 1;
`e
`e
`e
always @ (posedge div_clock_t ) //
`b
if(sys_reset)
`b
datam25_in<= 0 ;
st_wr <= 0 ;
s_m25 <= 1;
led1 <= 1;
// led2 <= 0;
w_addr24<= 0 ;
data_temp[7:0]<=0 ;
`e
else
`b
if (st_wr == 0)
`b
s_m25 <= 0; //片选信号拉低
led1 <= 0; //led1====s_m25
st_wr <= 1;
data_temp<=data_in;
`e
if (st_wr == 1) //开始发送写使能指令06H
`b
datam25_in <= 0; // 0
st_wr <= 2;
`e
if (st_wr == 2)
`b
datam25_in <= 0; // 0
st_wr <= 3;
`e
if (st_wr == 3)
`b
datam25_in <= 0; // 0
st_wr <= 4;
`e
if (st_wr == 4)
`b
datam25_in <= 0; // 0
st_wr <= 5;
`e
if (st_wr == 5)
`b
datam25_in <= 0; // 0
st_wr <= 6;
`e
if (st_wr == 6)
`b
datam25_in <= 1; // 4
st_wr <= 7;
`e
if (st_wr == 7)
`b
datam25_in <= 0; // 2
st_wr <= 8;
`e
if (st_wr == 8)
`b
datam25_in <= 0; // 0
st_wr <= 9 ;
`e
if (st_wr == 9)
`b
s_m25 <= 1; //片选信号拉高
led1 <= 1; //led1====s_m25
st_wr <= 10;
`e
if (st_wr == 10)
st_wr <= 11 ;
if (st_wr == 11)
st_wr <= 12 ;
if (st_wr == 12)
st_wr<= 13 ;
if (st_wr == 13)
st_wr <= 14 ;
//------------------- 开始发送擦除C7H ------------
if (st_wr == 14)
`b
datam25_in <= 1;
st_wr<= 15;
`e
if (st_wr == 15)
`b
datam25_in <= 1;
st_wr <= 16;
`e
if (st_wr == 16)
`b
datam25_in<= 0;
st_wr <= 17;
`e
if (st_wr == 17)
`b
datam25_in<= 0;
st_wr <= 18;
`e
if (st_wr == 18)
`b
datam25_in<= 0;
st_wr <= 19;
`e
if (st_wr == 19)
`b
datam25_in <= 1;
st_wr <= 20;
`e
if (st_wr == 20)
`b
datam25_in <= 1;
st_wr <= 21;
`e
if (st_wr == 21)
`b
datam25_in <= 1;
st_wr <= 22;
`e
if (st_wr == 22)
`b
s_m25 <= 1; //片选信号拉高
st_wr <= 23;
`e
if (st_wr == 23)
`b
count1 <= count1+1; //计数
st_wr <= 24;
`e
if (st_wr == 24)
`b
st_wr <= 25;
`e
if (st_wr == 25)
`b
st_wr <= 26;
`e
if (st_wr == 26)
`b
st_wr <= 27;
`e
if (st_wr == 27)
`b
st_wr <= 28;
`e
if (st_wr == 28)
`b
st_wr <= 29;
`e
if (st_wr == 29)
`b
st_wr <= 30 ;
`e
if (st_wr == 30)
`b
if (count1<30000)
st_wr <= 22 ; //等待21s 每一状态0.1ms
else
st_wr <= 31 ;
`e
//------------------- 开始发送页编程指令02H ------------
if (st_wr == 31)
`b
s_m25 <= 0; //片选信号拉低
led1 <= 0; //led1====s_m25
st_wr<= 32;
`e
if (st_wr == 32)
`b
datam25_in <= 1; //输入写允许位置1指令
st_wr <= 33;
`e
if (st_wr == 33)
`b
s_m25 <= 1; //片选信号拉高
led1 <= 1; //led1====s_m25
st_wr <= 34;
`e
if (st_wr == 34)
st_wr <= 35;
if (st_wr == 35)
st_wr <= 36;
if (st_wr == 36)
st_wr <= 37;
if (st_wr == 37)
st_wr <= 38;
if (st_wr == 38)
st_wr <= 39;
if (st_wr == 39)
`b
s_m25 <= 0; //片选信号拉低
led1 <= 0; //led1====s_m25
st_wr <= 40;
`e
if (st_wr == 40) //开始发送页编程指令02H
`b
datam25_in <= 0; // 0
st_wr <= 41;
`e
if (st_wr == 41)
`b
datam25_in <= 0; // 0
st_wr <= 42;
`e
if (st_wr == 42)
`b
datam25_in <= 0; // 0
st_wr <= 43;
`e
if (st_wr == 43)
`b
datam25_in <= 0; // 0
st_wr <= 44;
`e
if (st_wr == 44)
`b
datam25_in <= 0;
st_wr <= 45; // 0
`e
if (st_wr == 45)
`b
datam25_in <= 0; // 0
st_wr <= 46;
`e
if (st_wr == 46)
`b
datam25_in <= 1; // 2
st_wr <= 47 ;
`e
if (st_wr == 47)
`b
datam25_in <= 0; // 0
st_wr <= 48;
`e
if (st_wr == 48) // 输入3字节地址 ;
`b
if(i<24)
`b
datam25_in<= w_addr24[i];
i<=i+1 ;
st_wr <=48 ;
`e
else
st_wr <=49 ;
`e
if (st_wr == 49) // 输入一字节数据
`b
if (j<8)
`b
datam25_in<= data_temp[j];
j=j+1 ;
st_wr <=49 ;
`e
else
st_wr <=50 ;
`e
if (st_wr == 50) // 输入一页数据256BYTE
if (k<256)
`b
data_temp<=data_temp+1 ;
k<=k+1 ;
st_wr <=49 ;
`e
else
st_wr <=51 ;
if (st_wr == 51)
`b
s_m25 <= 1; //片选信号拉高
led1 <= 1; //led1====s_m25
st_wr <= 52;
`e
if (st_wr == 52)
if (count2<60) //延时6ms 每一状态0.1ms
`b
count2<=count2+1 ;
st_wr <= 52;
`e
else
st_wr <= 53;
if (st_wr == 53)
st_wr <= 0;
/* if (st_wr == 54)
st_wr <= 55;
if (st_wr == 55)
st_wr <= 56;
if (st_wr == 56)
st_wr <= 57;
if (st_wr == 57)
st_wr <= 40;
if (st_wr == 40)
st_wr <= 41;
if (st_wr == 41)
st_wr <= 42;
if (st_wr == 42)
st_wr <= 43;
if (st_wr == 43)
st_wr <= 44;
if (st_wr == 44)
st_wr <= 45;
if (st_wr == 45)
st_wr <= 46;
if (st_wr == 46)
st_wr <= 47;
if (st_wr == 47)
st_wr <= 48;
if (st_wr == 48)
st_wr <= 49;
if (st_wr == 49)
st_wr <= 50;
if (st_wr == 50)
`b
st_wr <= 51;
//----------------读m25p80---------------------------------
if (st_wr == 51)
`b
st_wr <= 52;
//----------------延时---------------------------------
if (st_wr == 30)
`b
st_wr <= 100 ;
`e
`e */
`e
`e
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -