1、编程要求:利用 C 语言实现 RTC 实时时钟,并且设置闹钟当闹钟时间到就 LED2 亮,能够 安全读时间时 LED1 亮(灭),且在 BCD 模式下。 2、实现功能:实现实时时钟,完成闹钟功能 3、实验现象:LED1 闪烁,LED2 在闹钟时间到后就亮
1
Cyclone10LP FPGA读写DS1302 RTC实验Verilog逻辑源码Quartus17.1工程文件+文档资料, FPGA为CYCLONE10LP系列中的10CL025YU256C8. 完整的Quartus工程文件,可以做为你的学习设计参考。 通过分析 DS1302 读写时序,可以看出和 SPI 时序类似,只丌过数据输出和输入分时复用了, 本实验利用 SPI Flash 读写实验中已经使用过的 SPI Master 模块来做为 DS1302 的底层读写控制模块, 然后再编写一个 RTC 读写模块。 ds1302_io 模块完成 DS1302 寄存器读写控制,状态机如下图所示。 状态“S_IDLE”空闲状态,收到读写寄存器请求写迚入“S_CE_HIGH”状态,将 CE 拉高,然 后根据请求类型,迚入读(S_READ)戒写状态(S_WRITE)。 “S_WRITE”状态下一个状态迚入写地址状态“S_WRITE_ADDR”,再迚入写数据状态 “S_WRITE_DATA”,完成一个寄存器的写入,最后应答,拉低 CE。 “S_READ”状态下一个状态迚入读地址状态“S_READ_ADDR”,再迚入读数据状态 “S_READ_DATA”,完成一个寄存器的读取,最后应答,拉低 CE。 module top( //sys input clk, input rst_n, output rtc_sclk, output rtc_ce, inout rtc_data, input uart_rx, output uart_tx ); wire[7:0] read_second; wire[7:0] read_minute; wire[7:0] read_hour; wire[7:0] read_date; wire[7:0] read_month; wire[7:0] read_week; wire[7:0] read_year; ds1302_test ds1302_test_m0( .rst (~rst_n), .clk (clk), .ds1302_ce (rtc_ce), .ds1302_sclk (rtc_sclk), .ds1302_io (rtc_data), .read_second (read_second), .read_minute (read_minute), .read_hour (read_hour), .read_date (read_date), .read_month (read_month), .read_week (read_week), .read_year (read_year) ); uart_send uart_send_m0( .clk (clk ), .rst_n (rst_n ), .read_second (read_second ), .read_minute (read_minute ), .read_hour (read_hour ), .read_date (read_date ), .read_month (read_month ), .read_week (read_week ), .read_year (read_year ), .uart_rx (uart_rx ), .uart_tx (uart_tx ) );
FPGA读写DS1302 RTC实验Verilog逻辑源码Quartus工程文件+文档资料, FPGA为CYCLONE4系列中的EP4CE6E22C8. 完整的工程文件,可以做为你的学习设计参考。 module DS1302( input sys_clk , input sys_rst_n , output DS1302_CE , output DS1302_CLK , inout DS1302_IO , output wire seg_c1 , output wire seg_c2 , output wire seg_c3 , output wire seg_c4 , output wire seg_a , output wire seg_b , output wire seg_c , output wire seg_e , output wire seg_d , output wire seg_f , output wire seg_g , output wire seg_h ); /************************************/ reg [3:0] i ;//ִ�в��� reg [4:0] rc1_data ;//������1������ reg [4:0] rc2_data ;//������2������ reg [4:0] rc3_data ;//������3������ reg [4:0] rc4_data ;//������4������ reg [7:0] isStart ;//��ʼ��־ reg [7:0] rData ;//�����ݴ��� reg [7:0] sec_data ;//������ reg [7:0] min_data ;//������ /************************************/ wire Done_Sig ; //�����ź� wire [7:0] Time_Read_Data ; //�����ʱ������ /************************************/ always @ ( posedge sys_clk or negedge sys_rst_n ) begin if ( !sys_rst_n ) begin i <= 4'd0; //ִ�в������� isStart <= 8'd0; //��ʼ��־���� rData <= 8'd0; //�����ݴ������� end else case( i ) 0: if ( Done_Sig ) begin isStart <= 8'd0; i <= i + 1'b1; end else begin isStart <= 8'b1000_0000; rData <= 8'h00; //���ݼĴ���д��00h end 1: if ( Done_Sig ) begin isStart <= 8'd0; i <= i + 1'b1; end
RTC实验
2021-05-05 19:01:28 386KB RTC实验
1