51单片机4个数码管显示程序
#include<REG51.H>charled_mod[]={0x76,0x86};voiddelay(unsignedinttime);voidmain(){char...
#include<REG51.H>
char led_mod[]={0x76,0x86};
void delay (unsigned int time);
void main(){
char led_point=0;
while(1){
P3=5-led_point;
P2=led_mod[led_point];
led_point=1-led_point;
delay(30);
}
}
void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
这个是两个动态数码管显示的程序,,4个的怎么编写,,显示1234, 展开
char led_mod[]={0x76,0x86};
void delay (unsigned int time);
void main(){
char led_point=0;
while(1){
P3=5-led_point;
P2=led_mod[led_point];
led_point=1-led_point;
delay(30);
}
}
void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
这个是两个动态数码管显示的程序,,4个的怎么编写,,显示1234, 展开
4个回答
展开全部
#include<reg52.h> //52系列单片机头文件
#define uchar unsigned char //宏定义
#define uint unsigned int
sbit dula=P2^6; //申明u1锁存器的锁存端
sbit wela=P2^7; // u2
uchar num1,num2;
uchar code table[]={ //数组定义
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code aable[]={ //位选数组定义
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delays(uint); //子函数申明
void main()
{
while(1)
{
for(num1=0;num1<48;num1++) //6个数循环显示
{
wela=1; //打开u2锁存端
P0=aable[num1%6]; //送入位选信号
wela=0; //关闭u2锁存端
// delays(1);
dula=1; //打开u1锁存端
P0=table[num1%16]; //送入段选信号
dula=0; //关闭u1锁存端
delays(1);
}
}
}
/*---------主函数-----------------------------------------------*/
void delays(uint xs)
{
uint i,j,k;
for(i=xs;i>0;i--)
for(j=1000;j>0;j--)
for(k=110;k>0;k--);
}
/*----------------延时程序-----------------------------------------------*/
#define uchar unsigned char //宏定义
#define uint unsigned int
sbit dula=P2^6; //申明u1锁存器的锁存端
sbit wela=P2^7; // u2
uchar num1,num2;
uchar code table[]={ //数组定义
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code aable[]={ //位选数组定义
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delays(uint); //子函数申明
void main()
{
while(1)
{
for(num1=0;num1<48;num1++) //6个数循环显示
{
wela=1; //打开u2锁存端
P0=aable[num1%6]; //送入位选信号
wela=0; //关闭u2锁存端
// delays(1);
dula=1; //打开u1锁存端
P0=table[num1%16]; //送入段选信号
dula=0; //关闭u1锁存端
delays(1);
}
}
}
/*---------主函数-----------------------------------------------*/
void delays(uint xs)
{
uint i,j,k;
for(i=xs;i>0;i--)
for(j=1000;j>0;j--)
for(k=110;k>0;k--);
}
/*----------------延时程序-----------------------------------------------*/
展开全部
#include<REG51.H>
char led_mod[] = { 0xf9, 0xa4, 0xb0, 0x99 }; /*共阳数码管显示编码*/
char led_bit[] = { 0x01, 0x02, 0x04, 0x08 }; /*位选信号编码*/
void delay (unsigned int time);
void main()
{
char led_point = 0;
while(1)
{
/* 共阳数码管 */
P3 = 0x00; /*关位选,防止显示混乱*/
P2 = led_mod[led_point]; /*送显示编码*/
P3 = led_bit[led_point]; /*开位选*/
/* 共阴数码管 */
/* P3 = 0xff; /*关位选,防止显示混乱*/
/* P2 = ~led_mod[led_point]; /*送显示编码*/
/* P3 = ~led_bit[led_point]; /*开位选*/
led_point++; /*4位循环标志*/
if ( led_point == 4 )
led_point = 0;
delay(4); /*延时点亮4ms*/
/*人的视觉停留效果,要求扫描周期不超过18ms为最佳*/
}
}
/* 延时函数,延时 time ms */
void delay(unsigned int time)
{
unsigned char j;
for( ; time>0; time-- )
for( j=0; j<125; j++ );
}
追问
你这个是什么程序,后面有每步的解释?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<REG51.H>
char led_mod[]={0xf9,0xa4,0xb0,0x99};
void delay (unsigned int time);
void main(){
char led_point=0;
while(1){
switch(led_point)
{
case 0:P3=0x08;P2=led_mod[led_point];break;
case 1:P3=0x04;P2=led_mod[led_point];break;
case 2:P3=0x02;P2=led_mod[led_point];break;
case 3:P3=0x01;P2=led_mod[led_point];break;
default:break;
}
delay(5);
led_point++;
led_point%=4
}
}
void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
char led_mod[]={0xf9,0xa4,0xb0,0x99};
void delay (unsigned int time);
void main(){
char led_point=0;
while(1){
switch(led_point)
{
case 0:P3=0x08;P2=led_mod[led_point];break;
case 1:P3=0x04;P2=led_mod[led_point];break;
case 2:P3=0x02;P2=led_mod[led_point];break;
case 3:P3=0x01;P2=led_mod[led_point];break;
default:break;
}
delay(5);
led_point++;
led_point%=4
}
}
void delay(unsigned int time){
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay(uchar z)
{ uchar x,y;
for(x=z;x>0;x--)
for(y=0;y<1250;y++);
}
void main()
{
uchar i,j;
while(1)
{
for(j=0;j<8;j++)
{
P2=table1[j];
wei=1;
wei=1;
wei=0;
P2=table[j]; duan=1; delay(10);
P2=0;
duan=0; } } }
void delay(uchar z)
{ uchar x,y;
for(x=z;x>0;x--)
for(y=0;y<1250;y++);
}
void main()
{
uchar i,j;
while(1)
{
for(j=0;j<8;j++)
{
P2=table1[j];
wei=1;
wei=1;
wei=0;
P2=table[j]; duan=1; delay(10);
P2=0;
duan=0; } } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询