//LCD的口线
sbit E=P3^5
sbit RW=P3^6
sbit RS=P3^7
//8字LED的连接方法
//P0.7,P0.6,P0.5,P0.4,P0.3,P0.2,P0.1,P0.0
//G, F A E B H C D
unsigned char code ledcode[]={0x84,0xf5,0x46,0x54,0x35,0x1c,0x0c,0xd5,
0x04,0x14,0x05,0x2c,0x8e,0x64,0x0e,0x0f}//数码管段码表
unsigned char js100ms,jsgw,jssw,t0100ms,t0sm
void time0(void)
void main(void)
{
E=0 //取消LCD对LED的影响
RW=0
RS=1
js100ms=0x00
jsgw=0x00
jssw=0x00
t0100ms=0x14
t0sm=0x01 //从第一个LED开始显示
TH0=0xee
TL0=0x00
TMOD=0x01
TR0=1
IE=0x82
while(1)
{}
}
void time0(void) interrupt 1
{
TH0=0xee
TL0=0x00
t0100ms--
if(t0100ms==0x00)
{
t0100ms=0x14
js100ms++
if(js100ms==0x0a)
{
js100ms=0x00
jsgw++
if(jsgw==0x0a)
{
jsgw=0x00
jssw++
if(jssw==0x0a)
{jssw=0x00}
}
}
}
t0sm++
if(t0sm==0x04)
{t0sm=0x01}
P0=0xff
switch(t0sm)
{
case 0x01: { P2=0xdfP0=ledcode[js100ms]}break
case 0x02: { P2=0xefP0=ledcode[jsgw]&0xFB}break
case 0x03: { P2=0xf7P0=ledcode[jssw]}break
default: break
}
}
或者汇编
JS100MS EQU 32H 计数器0.1S
JSGW EQU 30H 计数器的个位
JSSW EQU 31H 计数器的十位
T0_100MS EQU 33H 产生1S
LEDSM EQU 34H 现在扫到第几个LED
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP TIME0_1
ORG 0050H
MAIN:
MOV JS100MS,#00H 上电时从00.0开始
MOV JSSW,#00H
MOV JSGW,#00H
MOV T0_100MS,#14H 5MS*20=100MS
MOV LEDSM,#01H
MOV TH0,#0EEH 16位的定时器,定时5MS
MOV TL0,#00H
MOV TMOD,#01H
SETB TR0
MOV IE,#82H 定时器0中断
SJMP $
ORG 0100H
TIME0_1: MOV TH0,#0EEH
MOV TL0,#00H
DJNZ T0_100MS,TODISP
MOV T0_100MS,#14H
INC JS100MS
MOV A,JS100MS
CJNE A,#0AH,TODISP
MOV JS100MS,#00H
INC JSGW
MOV A,JSGW
CJNE A,#0AH,TODISP
MOV JSGW,#00H
INC JSSW
MOV A,JSSW
CJNE A,#0AH,TODISP
MOV JSSW,#00H 溢出99.9则回到00.0
TODISP: MOV P0,#0FFH 在位选时关显示
INC LEDSM
MOV A,LEDSM
CJNE A,#04H,TODISP1
MOV LEDSM,#01H 扫完第三个又从第一个开始
TODISP1: MOV A,LEDSM
CJNE A,#01H,TODISP2
MOV P2,#0DFH
MOV A,JS100MS
MOV DPTR,#LEDCODE
MOVC A,@A+DPTR
AJMP TOP0
TODISP2: CJNE A,#02H,TODISP3
MOV P2,#0EFH
MOV A,JSGW
MOV DPTR,#LEDCODE
MOVC A,@A+DPTR
CLR ACC.2 把H点点亮
AJMP TOP0
TODISP3: MOV P2,#0F7H
MOV A,JSSW
MOV DPTR,#LEDCODE
MOVC A,@A+DPTR
TOP0: MOV P0,A
RETI
8字LED的连接方法
P0.7,P0.6,P0.5,P0.4,P0.3,P0.2,P0.1,P0.0
G, F A E B H C D
LED字段码表
LEDCODE: DB 84H 0
DB 0F5H 1
DB 46H 2
DB 54H 3
DB 35H 4
DB 1CH 5
DB 0CH 6
DB 0D5H 7
DB 04H 8
DB 14H 9
DB 05H A
DB 2CH B
DB 8EH C
DB 64H D
DB 0EH E
DB 0FH F
END
如果发电路可以量身打造哦QQ514586810
以下有一个波形仿真过了,但是下载时有点问题的代码,如果你解决了告诉我哈,谢谢LIBRARY IEEE
USE IEEE.STD_LOGIC_1164.ALL
USE IEEE.STD_LOGIC_unsigned.ALL
USE IEEE.STD_LOGIC_ARITH.ALL
ENTITY PAOBIAO IS
PORT(
CLK,CLR,PAUSE:IN STD_LOGIC
cs1:OUT std_logic_vector(6 DOWNTO 0)
cs2:OUT std_logic_vector(6 DOWNTO 0)
s1:OUT std_logic_vector(6 DOWNTO 0)
s2:OUT std_logic_vector(6 DOWNTO 0)
m1:OUT std_logic_vector(6 DOWNTO 0)
m2:OUT std_logic_vector(6 DOWNTO 0))
END PAOBIAO
ARCHITECTURE PAOBIAO_ARCH OF PAOBIAO IS
signal ics1,ics2,is1,im1:UNSIGNED (3 DOWNTO 0)
signal is2,im2:UNSIGNED (2 DOWNTO 0)
BEGIN
PROCESS(CLK,ics1,ics2,is1,im1,is2,im2)
BEGIN
IF (CLK'EVENT AND CLK='1') THEN
IF CLR='1' THEN ics1<=(others=>'0')ics2<=(others=>'0')is1<=(others=>'0')im1<=(others=>'0')is2<=(others=>'0')im2<=(others=>'0')
ELSIF PAUSE='0' THEN
IF (ics1=9) then ics1<=(others=>'0')
IF (ics2=9) then ics2<=(others=>'0')
IF (is1=9) then is1<=(others=>'0')
IF (is2=5) then is2<=(others=>'0')
IF (im1=9) then im1<=(others=>'0')
IF (im2=5) then ics1<=(others=>'0')ics2<=(others=>'0')is1<=(others=>'0')im1<=(others=>'0')is2<=(others=>'0')im2<=(others=>'0')
ELSE im2<=im2+1END IF
ELSE im1<=im1+1END IF
ELSE is2<=is2+1END IF
ELSE is1<=is1+1END IF
ELSE ics2<=ics2+1END IF
ELSE ics1<=ics1+1END IF
ELSE ics1<=ics1ics2<=ics2is1<=is1im1<=im1is2<=is2im2<=im2
END IF
END IF
CASE ics1 is
WHEN "0000" =>cs1<="1111110"
WHEN "0001" =>cs1<="0110000"
WHEN "0010" =>cs1<="1101101"
WHEN "0011" =>cs1<="1111001"
WHEN "0100" =>cs1<="0110011"
WHEN "0101" =>cs1<="1011011"
WHEN "0110" =>cs1<="1011111"
WHEN "0111" =>cs1<="1110000"
WHEN "1000" =>cs1<="1111111"
WHEN "1001" =>cs1<="1111011"
WHEN OTHERS =>null
END CASE
CASE ics2 is
WHEN "0000" =>cs2<="1111110"
WHEN "0001" =>cs2<="0110000"
WHEN "0010" =>cs2<="1101101"
WHEN "0011" =>cs2<="1111001"
WHEN "0100" =>cs2<="0110011"
WHEN "0101" =>cs2<="1011011"
WHEN "0110" =>cs2<="1011111"
WHEN "0111" =>cs2<="1110000"
WHEN "1000" =>cs2<="1111111"
WHEN "1001" =>cs2<="1111011"
WHEN OTHERS =>null
END CASE
CASE is1 is
WHEN "0000" =>s1<="1111110"
WHEN "0001" =>s1<="0110000"
WHEN "0010" =>s1<="1101101"
WHEN "0011" =>s1<="1111001"
WHEN "0100" =>s1<="0110011"
WHEN "0101" =>s1<="1011011"
WHEN "0110" =>s1<="1011111"
WHEN "0111" =>s1<="1110000"
WHEN "1000" =>s1<="1111111"
WHEN "1001" =>s1<="1111011"
WHEN OTHERS =>null
END CASE
CASE is2 is
WHEN "000" =>s2<="1111110"
WHEN "001" =>s2<="0110000"
WHEN "010" =>s2<="1101101"
WHEN "011" =>s2<="1111001"
WHEN "100" =>s2<="0110011"
WHEN "101" =>s2<="1011011"
WHEN OTHERS =>null
END CASE
CASE im1 is
WHEN "0000" =>m1<="1111110"
WHEN "0001" =>m1<="0110000"
WHEN "0010" =>m1<="1101101"
WHEN "0011" =>m1<="1111001"
WHEN "0100" =>m1<="0110011"
WHEN "0101" =>m1<="1011011"
WHEN "0110" =>m1<="1011111"
WHEN "0111" =>m1<="1110000"
WHEN "1000" =>m1<="1111111"
WHEN "1001" =>m1<="1111011"
WHEN OTHERS =>null
END CASE
CASE im2 is
WHEN "000" =>m2<="1111110"
WHEN "001" =>m2<="0110000"
WHEN "010" =>m2<="1101101"
WHEN "011" =>m2<="1111001"
WHEN "100" =>m2<="0110011"
WHEN "101" =>m2<="1011011"
WHEN OTHERS =>null
END CASE
END PROCESS
END PAOBIAO_ARCH
#include<reg52.h>#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^7
sbit dula=P2^6
sbit key1=P3^4
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71}
uchar bai,shi,ge
void display(uchar,uchar,uchar)
uchar num
void keyscan()
void init()
void delay(uint z)
{
uchar i,j
for(i=zi>0i--)
for(j=110j>0j--)
}
void main()
{
init()
while(1)
{
display(bai,shi,ge)
keyscan()
}
}
void keyscan()
{
if(key1==0)
{
delay(10)
if(key1==0)
{
TR0=0
while(!key1)
TR0=1
}
}
}
void init()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
}
void display(uchar a,uchar b,uchar c)
{
dula=1
P0=table[a]
dula=0
P0=0xff
wela=1
P0=0xfe
wela=0
delay(10)
dula=1
P0=table[b]
dula=0
P0=0xff
wela=1
P0=0xfd
wela=0
delay(10)
dula=1
P0=table[c]
dula=0
P0=0xff
wela=1
P0=0xfb
wela=0
delay(10)
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
num++
if(num==1000)
num=0
bai=num/100
shi=num%100/10
ge=num%10
}
我刚写的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)