--串行数据输出选择模块
u1:process(LCD_SDIS_8BIT,LCD_SDIS_16BIT,LCD_SDIS_24BIT,SPI_MODES)
begin
if SPI_MODES="01" then --选择8bit 串行数据输出
LCD_SDIS<=LCD_SDIS_8BIT;
elsif SPI_MODES="10" then --选择16bit 串行数据输出
LCD_SDIS<=LCD_SDIS_16BIT;
elsif SPI_MODES="11" then --选择24bit 串行数据输出
LCD_SDIS<=LCD_SDIS_24BIT;
else LCD_SDIS<='1';
end if;
end process;
--移位脉冲产生模块
u2:process(CLKS)
begin
if CLKS='1' and CLKS'event then
if counter4="0011" then
counter4<="0000";
shift <='1';
else counter4<=counter4+1;
shift <='0';
end if;
end if;
end process;
--SPI 时钟采集信号和无相移的SPI 基准时钟产生模块
u3:process(CLKS)
begin
if CLKS='1' and CLKS'event then
if counter4s<"11" then
counter4s<=counter4s+1;
else counter4s<="00";
end if;
end if;
LCD_SCLSS<=counter4s(0); --SPI 时钟采集信号
LCD_SCLSSS<=counter4s(1); --无相移的SPI 基准时钟
end process;
--SPI 时钟输出选择模块
u4:process(LCD_SCLSS8,LCD_SCLSS16,LCD_SCLSS24,SPI_MODES)
begin
if SPI_MODES="01" then
LCD_SCLS<=LCD_SCLSS8; --选择8bit SPI 时钟模式
elsif SPI_MODES="10" then
LCD_SCLS<=LCD_SCLSS16; --选择16bit SPI 时钟模式
elsif SPI_MODES="11" then
LCD_SCLS<=LCD_SCLSS24; --选择24bit SPI 时钟模式
else LCD_SCLS<='1';
end if;
end process;
--8bit SPI 时钟采集生成模块
counter8_u:process(LCD_SCLSS)
begin
if SPI_WR='1' then
counter8<="10001";
elsif LCD_SCLSS='1' and LCD_SCLSS'event then
if counter8>0 then
counter8<=counter8-1;
LCD_SCLSS8<=LCD_SCLSSS;
end if;
end if;
end process;
--16bit SPI 时钟采集生成模块
counter16_u:process(LCD_SCLSS)
begin
if SPI_WR='1' then
counter16<="100001";
elsif LCD_SCLSS='1' and LCD_SCLSS'event then
if counter16>0 then
counter16<=counter16-1;
LCD_SCLSS16<=LCD_SCLSSS;
end if;
end if;
end process;
--24bit SPI 时钟采集生成模块
counter24_u:process(LCD_SCLSS)
begin
if SPI_WR='1' then
counter24<="110011";
elsif LCD_SCLSS='1' and LCD_SCLSS'event then
if counter24>0 then
counter24<=counter24-1;
if (counter24="000000")or(counter24="000001")or
(counter24="110011")or(counter24="000010")then
LCD_SCLSS24<='0';
else
LCD_SCLSS24<=LCD_SCLSSS;
end if;
end if;
end if;
end process;
--8bit 数据移位模块
DB8BIT_U:process(shift,SPI_WR,DBINOUTS)
begin
if SPI_WR='1' then
DB8BIT_reg<=DBINOUTS(7 downto 0);
else
if shift='1' and shift'event then
LCD_SDIS_8BIT<=DB8BIT_reg(0);
DB8BIT_reg(6 downto 0)<=DB8BIT_reg(7 downto 1);
end if;
end if;
end process;
--16bit 数据移位模块
DB16BIT_U:process(shift,SPI_WR,DBINOUTS)
begin
if SPI_WR='1' then
DB16BIT_reg(15 downto 0)<=DBINOUTS(15 downto 0);
else
if shift='1' and shift'event then
LCD_SDIS_16BIT<=DB16BIT_reg(0);
DB16BIT_reg(14 downto 0)<=DB16BIT_reg(15 downto 1);
end if;
end if;
end process;
--24bit 数据移位模块
DB24BIT_U:process(shift,SPI_WR,DBINOUTS)
begin
if SPI_WR='1' then
DB24BIT_reg(23 downto 0)<=DBINOUTS(23 downto 0);
else
if shift='1' and shift'event then
LCD_SDIS_24BIT<=DB24BIT_reg(0);
DB24BIT_reg(22 downto 0)<=DB24BIT_reg(23 downto 1);
end if;
end if;
end process;
end;
评论