这是四位数码管从右从左流动显示,像滚动字幕一样的。用不着矩阵按键哪。
其实程序很简单,没那么复杂。程序如下
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}//共阴段码码,0x00为灭
void delay()//延时子程序
{
uint y
for(y=400y>0y--)
}
void main()
{
uchar n,x
while(1)
{
n++
if(n>50)//n为显示一屏显示次数,n大小可调节流动速度
{
n=0
x++//从下一个位置开始显示
if(x>8)x=0
}
}
}
仿真结果
#include //52系列单片机头文件\x0d\x0a#define uchar unsigned char //宏定义\x0d\x0a#define uint unsigned int\x0d\x0asbit dula=P2^6//申明u1锁存器的锁存端\x0d\x0asbit wela=P2^7// u2\x0d\x0auchar num1,num2\x0d\x0auchar code table[]={ //数组定义\x0d\x0a0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,\x0d\x0a0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}\x0d\x0auchar code aable[]={ //位选数组定义\x0d\x0a0xfe,0xfd,0xfb,0xf7,0xef,0xdf}\x0d\x0avoid delays(uint)//子函数申明\x0d\x0a\x0d\x0a void main() \x0d\x0a{\x0d\x0awhile(1)\x0d\x0a{\x0d\x0a for(num1=0num1//6个数循环显示\x0d\x0a{\x0d\x0awela=1//打开u2锁存端\x0d\x0aP0=aable[num1%6]//送入位选信号\x0d\x0awela=0//关闭u2锁存端\x0d\x0a//delays(1)\x0d\x0adula=1//打开u1锁存端\x0d\x0aP0=table[num1%16]//送入段选信号\x0d\x0adula=0//关闭u1锁存端\x0d\x0adelays(1)\x0d\x0a}\x0d\x0a}\x0d\x0a}\x0d\x0a/*---------主函数-----------------------------------------------*/\x0d\x0a\x0d\x0avoid delays(uint xs)\x0d\x0a{\x0d\x0auint i,j,k\x0d\x0afor(i=xsi>0i--)\x0d\x0afor(j=1000j>0j--)\x0d\x0afor(k=110k>0k--)\x0d\x0a}\x0d\x0a/*----------------延时程序-----------------------------------------------*/欢迎分享,转载请注明来源:内存溢出
评论列表(0条)