51单片机加74hc595驱动多个数码管静态显示的程序设计

51单片机加74hc595驱动多个数码管静态显示的程序设计,第1张

1、首先数码管分为1位,4位,8位,4位和8位的又分为共阴和共阳数码管。

2、共阳数码管,即阳极全部连接在一起,单片机接口给低电位即可点亮对应的段位。

3、可利用MCS-51系列单片机的芯片AT89C52的P3.4,P3.5,P3.6,P3.7进行计时并在数码管上显示时间,作为按键的入口。

4、共阴数码管,即阴极全部连接在一起,单片机接口给高电位即可点亮对应的段位。

5、其中“开始”按键当开关由上向下拨时开始计时,此时若再拨“开始”按键则数码管暂停;“清零”按键当开关由上向下拨时数码管清零,此时若再拨“开始”按键则又可重新开始计时。

LIBRARY ieee

USE ieee.std_logic_1164.ALL

use ieee.std_logic_arith.all

use ieee.std_logic_unsigned.all

ENTITY color16 IS

PORT(cp,rst:IN std_LOGIC

sel:in std_LOGIC_VECTOR(1 DOWNTO 0)

aout:OUT std_LOGIC_VECTOR(15 DOWNTO 0)

)

END color16

ARCHITECTURE color OF color16 IS

TYPE state_1 IS (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15)

SIGNAL state_2:state_1

BEGIN

pr_1:PROCESS (cp,rst)

BEGIN

IF rst='1' THEN

state_2<=s0

ELSIF cp'event AND cp='1' THEN

CASE state_2 IS

WHEN s0=>state_2<=s1

WHEN s1=>state_2<=s2

WHEN s2=>state_2<=s3

WHEN s3=>state_2<=s4

WHEN s4=>state_2<=s5

WHEN s5=>state_2<=s6

WHEN s6=>state_2<=s7

WHEN s7=>state_2<=s8

WHEN s8=>state_2<=s9

WHEN s9=>state_2<=s10

WHEN s10=>state_2<=s11

WHEN s11=>state_2<=s12

WHEN s12=>state_2<=s13

WHEN s13=>state_2<=s14

WHEN s14=>state_2<=s15

WHEN s15=>state_2<=s0

END CASE

END IF

END PROCESS pr_1

pr_2:PROCESS(sel,state_2)

BEGIN

if sel="00" then

-- when "00" =>

CASE state_2 IS

WHEN s0=>aout<="1000000000000000"

WHEN s1=>aout<="0100000000000000"

WHEN s2=>aout<="0010000000000000"

WHEN s3=>aout<="0001000000000000"

WHEN s4=>aout<="0000100000000000"

WHEN s5=>aout<="0000010000000000"

WHEN s6=>aout<="0000001000000000"

WHEN s7=>aout<="0000000100000000"

WHEN s8=>aout<="0000000010000000"

WHEN s9=>aout<="0000000001000000"

WHEN s10=>aout<="0000000000100000"

WHEN s11=>aout<="0000000000010000"

WHEN s12=>aout<="0000000000001000"

WHEN s13=>aout<="0000000000000100"

WHEN s14=>aout<="0000000000000010"

WHEN s15=>aout<="0000000000000001"

END CASE

elsif sel="01" then

CASE state_2 IS

WHEN s0=>aout<="1000000000000001"

WHEN s1=>aout<="1100000000000011"

WHEN s2=>aout<="1110000000000111"

WHEN s3=>aout<="1111000000001111"

WHEN s4=>aout<="1111100000011111"

WHEN s5=>aout<="1111110000111111"

WHEN s6=>aout<="1111111001111111"

WHEN s7=>aout<="1111111111111111"

WHEN s8=>aout<="1111111001111111"

WHEN s9=>aout<="1111110000111111"

WHEN s10=>aout<="1111100000011111"

WHEN s11=>aout<="1111000000001111"

WHEN s12=>aout<="1110000000000111"

WHEN s13=>aout<="1100000000000011"

WHEN s14=>aout<="1000000000000001"

WHEN s15=>aout<="0000000000000000"

END CASE

-- when "10"=>

elsif sel="10" then

CASE state_2 IS

WHEN s0=>aout<="1100000000000000"

WHEN s1=>aout<="0011000000000000"

WHEN s2=>aout<="0000110000000000"

WHEN s3=>aout<="0000001100000000"

WHEN s4=>aout<="0000000011000000"

WHEN s5=>aout<="0000000000110000"

WHEN s6=>aout<="0000000000001100"

WHEN s7=>aout<="0000000000000011"

WHEN s8=>aout<="0000000000000011"

WHEN s9=>aout<="0000000000001100"

WHEN s10=>aout<="0000000000110000"

WHEN s11=>aout<="0000000011000000"

WHEN s12=>aout<="0000001100000000"

WHEN s13=>aout<="0000110000000000"

WHEN s14=>aout<="0011000000000000"

WHEN s15=>aout<="1100000000000000"

END CASE

-- when "11"=>

elsif sel="11" then

CASE state_2 IS

WHEN s0=>aout<="1111111111111111"

WHEN s1=>aout<="0000000000000000"

WHEN s2=>aout<="1111111111111111"

WHEN s3=>aout<="0000000000000000"

WHEN s4=>aout<="1111111111111111"

WHEN s5=>aout<="0000000000000000"

WHEN s6=>aout<="1111111111111111"

WHEN s7=>aout<="0000000000000000"

WHEN s8=>aout<="1111111111111111"

WHEN s9=>aout<="0000000000000000"

WHEN s10=>aout<="1111111111111111"

WHEN s11=>aout<="0000000000000000"

WHEN s12=>aout<="1111111111111111"

WHEN s13=>aout<="0000000000000000"

WHEN s14=>aout<="1111111111111111"

WHEN s15=>aout<="0000000000000000"

END CASE

end if

END PROCESS pr_2

END color

#include<reg51.h>

unsigned char time=0

void delay(unsigned long w)

{

while(w--)

}

void zuoxunhuan()

{

unsigned char C

for(C=0x80C!=0C>>=1) //左移

{

P1=C

delay(30000)

}

}

void youxunhuan()

{

unsigned char C

for(C=0x01C!=0C<<=1) //右移

{

P1=C

delay(30000)

}

}

void zengti() //递增

{

unsigned int C

for(C=0xFEC!=0C<<=1)

{

P1=~C

delay(30000)

}

}

void jiaoti() //交替

{

P1=0x55

delay(30000)

P1=0xaa

delay(30000)

}

void init_init()

{

EX0=1

EA=1

}

void into_into() interrupt 0 //P3.2外接一个按键底电瓶有效切换程序

{

if((time+=1)==5) time=0

delay(400000)

}

void main()

{

init_init()

while(1)

{

if(time==1) zuoxunhuan()

if(time==2) youxunhuan()

if(time==3) zengti()

if(time==4) jiaoti()

if(time==0)

{

zuoxunhuan()

youxunhuan()

zengti()

jiaoti()

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11416355.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存