
1、首先数码管分为1位,4位,8位,4位段郑饥和8位的又分为共阴和共阳数码管。
2、共阳数码管,即阳极全部连接在一起,单片机接口给低电位即可点亮对应的段位。
3、可利用MCS-51系列单片机的芯片AT89C52的P3.4,P3.5,P3.6,P3.7进行计时并在数码管上显示时间,作为按键的入口。
4、共阴数码管,即阴极全部丛尘连接在一起,单片机接口给高电位即可点亮对应的段位。
5、其中“开始”按键当开关握返由上向下拨时开始计时,此时若再拨“开始”按键则数码管暂停;“清零”按键当开关由上向下拨时数码管清零,此时若再拨“开始”按键则又可重新开始计时。
#include "define.h"bit B16ms
bit B1s
uchar SomeLines//行扫描宏逗余计数器
uchar Timecnt
ucharay//停留时间
uchar Speed
uchar SpeedCnt//速度计数器
uchar StayCnt//停留时间计数
uchar Stay
uchar PingCnt//屏数计数器
uchar UD_Line//上滚行计数器
uchar Dots //左移点计数器
uchar Dismode
uchar DST
#include "define.h"
bit B16ms
bit B1s
uchar SomeLines//行扫描计数器
uchar Timecnt
ucharay//停留时间蔽滚
uchar Speed
uchar SpeedCnt//速度计数器
uchar StayCnt//停留时间计数
uchar Stay
uchar PingCnt//屏数计数器
uchar UD_Line//上滚行计指蚂数器
uchar Dots //左移点计数器
uchar Dismode
uchar DST
#include "define.h"
CLS()
{
uchar i,temp
for(i=0i<Lenthi++)
{
temp=XBYTE[DISPADR+(uint)PingCnt*Lenth*Clines+(uint)SomeLines*Lenth+i]
SENDCLK
}
EHOFF
STORE
Select_Line
EHON
SomeLines++
if(SomeLines==16)
{
SomeLines=0
}
if(B1s)
{
B1s=0
StayCnt++
if(Stay==StayCnt)
{
StayCnt=0
PingCnt++
if(PingCnt==(Pings-1))
{
PingCnt=0
Dismode=2
}
}
}
}
UP()
{
uchar i,temp
for(i=0i<Lenthi++)
{
temp=XBYTE[DISPADR+(SomeLines+UD_Line)*(uint)Lenth+i]
SENDCLK
}
EHOFF
STORE
Select_Line
EHON
SomeLines++
if(SomeLines==16)
{
SomeLines=0
}
if(B16ms)
{
B16ms=0
SpeedCnt++
if(SpeedCnt==Speed)
{
SpeedCnt=0
UD_Line++
if(UD_Line==(Clines*(Pings-1)))
{
UD_Line=0
Dismode=1
}
}
}
}
LEFTSHIFT()
{
uchar i,temp
while(PingCnt!=(Pings-1))
{
for(i=0i<(Lenth-Dots/8)i++)
{
temp=XBYTE[DISPADR+(uint)PingCnt*Lenth*Clines+(uint)SomeLines*Lenth+Dots/8+i]
SENDCLK
}
for(i=0i<(Dots/8)i++)
{
temp=XBYTE[DISPADR+(uint)(PingCnt+1)*Lenth*Clines+(uint)SomeLines*Lenth+i]
SENDCLK
}
temp=XBYTE[DISPADR+(uint)(PingCnt+1)*Lenth*Clines+(uint)SomeLines*Lenth+Dots/8]
for(i=0i<(Dots%8)i++)
{
CLK=0CLK=1
}
EHOFF
STORE
Select_Line
EHON
SomeLines++
if(SomeLines==16)
{
SomeLines=0
}
if(B16ms)
{
B16ms=0
SpeedCnt++
if(SpeedCnt==Speed)
{
SpeedCnt=0
Dots++
if(Dots==(Lenth*8))
{
Dots=0
PingCnt++
}
}
}
}
PingCnt=0
Dismode=3
}
Display()
{
switch(Dismode)
{
case 1:CLS()break
case 2:LEFTSHIFT()break
case 3:UP()break
default:break
}
}
Init()
{
uint i
P1=0xFFP3=0xFF
TMOD=0X01
SET_HTIME0_PARA(Fosc,1.0)
TR0=1ET0=1 PT0=0
TORAM
for(i=0i<(uint)Lenth*Clines*Pingsi++)
{
XBYTE[DISPADR+i]=~TAB[i]
}
Dismode=1
Speed=1
Stay=2
EA=1
}
main()
{
Init()
while (1)
{
Display()
}
}
//程序有不足。//
//下面是一个595输出的程序,供参考昌模斗。
//
/********************************************************/
/* */耐磨
/*将显示数据送入74HC595内部移位寄存器 */
/* */
/********************************************************/
void WR_595(uchar temp)
{
uchar j
for (j = 8j >0j--) {
SDATA_595 = (temp &0x80)
SCLK_595 = 0 //上升沿发生移位
temp = temp <<1
SCLK_595 = 1
}
}
/********************************************************/
/* */
/码则*将移位寄存器内的数据锁存到输出寄存器并显示*/
/* */
/********************************************************/
void OUT_595(void)
{
RCK_595 = 1//上升沿将数据送到输出锁存器
_nop_() _nop_()
RCK_595 = 0
}
/********************************************************/
/* */
/*主函数*/
/* */
/********************************************************/
main()
{
uchar tem
uchar i, m
SCLK_595 =0
RCK_595 = 0
oe_595 = 0
for(i = 0i <8i++) {
tem = DAT[i] //取显示数据
WR_595(tem)
OUT_595()
delay(1000)
}
while(1)
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)