基于SOPC的数字钟

发布时间 : 星期日 文章基于SOPC的数字钟更新完毕开始阅读

use ieee.std_logic_unsigned.all;

entity minsec is

port (CLK, RST,EN:in std_logic;

cq0,cq1:out std_logic_vector(3 downto 0); full:out std_logic); end minsec;

architecture one of minsec is begin

process(CLK, RST,EN)

variable cqi0,cqi1:std_logic_vector(3 downto 0); variable carry:integer;

begin

if RST='1'then cqi0:=(others=>'0');

elsif CLK'event and CLK='1' then if EN='1' then

if cqi0<9 then carry:=0; cqi0:=cqi0+1; else carry:=1; cqi0:=(others=>'0'); end if;

if carry=1 then

if cqi1<5 then cqi1:=cqi1+1;full<='0';

elsif cqi0=0 then cqi1:=(others=>'0'); full<='1'; end if; end if; end if; end if;

cq0<=cqi0; cq1<=cqi1; end process; end one; ⒊小时计时到24清零。

library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity hour is

port (CLK,RST,EN:in std_logic;

cq0,cq1:out std_logic_vector(3 downto 0)); end hour;

architecture one of hour is

begin

process(CLK,RST,EN)

variable cqi0,cqi1:std_logic_vector(3 downto 0); variable carry,full:integer; begin

if RST='1'then cqi0:=(others=>'0'); elsif CLK'event and CLK='1' then if EN='1' then

if full=1 then cqi0:=(others=>'0'); cqi1:=(others=>'0');

elsif cqi0<9 then carry:=0; cqi0:=cqi0+1; elsif cqi0=9 then carry:=1; cqi0:=(others=>'0');

end if;

if full=0 and carry=1 then cqi1:=cqi1+1; end if; end if; end if;

if cqi0=3 and cqi1=2 then full:=1 ; else full:=0; end if;

cq0<=cqi0; cq1<=cqi1; end process; end one;

⒋合成的时钟计时模块。

⒌SOPC BUILDER生成的CPU系统符号。

⒍合成的FPGA部分。

四、软件程序main.c

#include \#include \

#include \#include \#include \

#include \#include \

alt_u8

duan[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; void display();

void display() {

alt_u8 i,led;

int sec_l,sec_h,min_l,min_h,hour_l,hour_h;

sec_l=IORD_ALTERA_AVALON_PIO_DATA(SEC_SINGLE_BASE); sec_h=IORD_ALTERA_AVALON_PIO_DATA(SEC_TEN_BASE); min_l=IORD_ALTERA_AVALON_PIO_DATA(MIN_SINGLE_BASE); min_h=IORD_ALTERA_AVALON_PIO_DATA(MIN_TEN_BASE);

hour_l=IORD_ALTERA_AVALON_PIO_DATA(HOUR_SINGLE_BASE); hour_h=IORD_ALTERA_AVALON_PIO_DATA(HOUR_TEN_BASE);

for(i=0;i<5;i++) {

IOWR_ALTERA_AVALON_PIO_DATA(WEI_SEL_BASE, i); switch(i)

{

case 0:led=duan[sec_l];break; case 1:led=duan[sec_h];break; case 2:led=duan[min_l];break; case 3:led=duan[min_h];break; case 4:led=duan[hour_l];break; case 5:led=duan[hour_h];break; default:led=duan[10];break; }

IOWR_ALTERA_AVALON_PIO_DATA(DUAN_SEL_BASE, led); usleep(30); } }

int main() {

int it;

it=IORD_ALTERA_AVALON_PIO_DATA(TNTERRUPT_BASE); while (1)

{

if (it==1) {

display(); } }

return 0; }

联系合同范文客服:xxxxx#qq.com(#替换为@)