完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
10个回答
|
|
我觉得是代码初始化的问题吧,按道理来说,程序执行一开始先初始化一下数码管,比如什么都不显示,或者其他
|
|
|
|
使用共阳极数码管,代码初始化中P0=0xff,同样会出现数码管G段和DP段显示,同时在软件调试模式下,从0到1变化的1000ms内,数码管动态显示全部显示数字8.,我觉得是中断显示时无法调用main函数里的数字显示语句,这里我也没找到原因,应该是调用的问题,例如当数字开始是0的时候,ledbur【0】=0%10,但是这个取余显示8.这个乱码
|
|
|
|
unsigned char ledbuf[]=
{0xff,0xff,0xff,0xff,0xff,0xff}; 改为 unsigned char ledbuf[]= {0x3f,0x3f,0x3f,0x3f,0x3f,0x3f}; |
|
|
|
|
|
说一下是怎么解决的?
|
|
|
|
|
|
|
|
别,不是大神,我是新版主中的新手!
|
|
|
|
很不错
|
|
|
|
1 数码管显示1和2,同时LED每秒闪烁
#include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; ***it LED1 = P1^0; uchar counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display() { wei= 1; P0= 0xfe;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[1]; duan= 0; delay(1); wei = 1; P0= 0xfd;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[2]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; LED1= ~LED1; } display(); } } 实现秒表0-60循环 #include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; ***it LED1 = P1^0; uchar counter, time_counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display(uchar i) { ucharshi,ge; shi= i / 10; //求模 ge= i % 10; //求余 wei= 1; P0= 0xfe;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[shi]; duan= 0; delay(1); wei = 1; P0= 0xfd;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[ge]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; LED1= ~LED1; time_counter++; } if(time_counter== 60) time_counter= 0; display(time_counter); } } 数码管0-59显示,到60时流水灯循环显示 #include #include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; uchar ledflow = 0x7f; uchar counter, time_counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display(uchar i) { ucharshi,ge; shi= i / 10; //求模 ge= i % 10; //求余 P0= 0xff; //清除断码 wei= 1; P0= 0xbf;//点亮第7位数码管 wei= 0; duan= 1; P0= leddata[shi]; duan= 0; delay(1); P0 = 0xff; wei= 1; P0= 0x7f;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[ge]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; time_counter++; } if(time_counter== 60) { wei = 1; P0= 0xff;//关闭数码管显示 wei= 0; TR1= 0; P1= ledflow; ledflow= _cror_(ledflow,1); delay(500); }1 数码管显示1和2,同时LED每秒闪烁 #include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; ***it LED1 = P1^0; uchar counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display() { wei= 1; P0= 0xfe;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[1]; duan= 0; delay(1); wei = 1; P0= 0xfd;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[2]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; LED1= ~LED1; } display(); } } 实现秒表0-60循环 #include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; ***it LED1 = P1^0; uchar counter, time_counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display(uchar i) { ucharshi,ge; shi= i / 10; //求模 ge= i % 10; //求余 wei= 1; P0= 0xfe;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[shi]; duan= 0; delay(1); wei = 1; P0= 0xfd;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[ge]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; LED1= ~LED1; time_counter++; } if(time_counter== 60) time_counter= 0; display(time_counter); } } 数码管0-59显示,到60时流水灯循环显示 #include #include #define uchar unsigned char #define uint unsigned int ***it wei = P2^7; ***it duan = P2^6; uchar ledflow = 0x7f; uchar counter, time_counter; unsigned char leddata[]={ 0x3F, //"0" 0x06, //"1" 0x5B, //"2" 0x4F, //"3" 0x66, //"4" 0x6D, //"5" 0x7D, //"6" 0x07, //"7" 0x7F, //"8" 0x6F, //"9" 0x77, //"A" 0x7C, //"B" 0x39, //"C" 0x5E, //"D" 0x79, //"E" 0x71, //"F" 0x76, //"H" 0x38, //"L" 0x37, //"n" 0x3E, //"u" 0x73, //"P" 0x5C, //"o" 0x40, //"-" 0x00, //熄灭 0x00 //自定义 }; void delay(uint z) { uintx,y; for(x= z;x > 0;x--) for(y= 120; y > 0; y--); } void display(uchar i) { ucharshi,ge; shi= i / 10; //求模 ge= i % 10; //求余 P0= 0xff; //清除断码 wei= 1; P0= 0xbf;//点亮第7位数码管 wei= 0; duan= 1; P0= leddata[shi]; duan= 0; delay(1); P0 = 0xff; wei= 1; P0= 0x7f;//点亮第一位数码管 wei= 0; duan= 1; P0= leddata[ge]; duan= 0; delay(1); } void main() { TMOD= 0x10;//定时器1 工作模式1 16位模式定时器 TH1= 0x4b; TL1= 0xfe; //定时50ms TR1= 1; //启动定时器 while(1) { if(TF1== 1) { TF1= 0; TH1= 0x4b; TL1= 0xfe; //初始化值,定时50ms counter++; } if(counter== 20) { counter= 0; time_counter++; } if(time_counter== 60) { wei = 1; P0= 0xff;//关闭数码管显示 wei= 0; TR1= 0; P1= ledflow; ledflow= _cror_(ledflow,1); delay(500); } else display(time_counter); } } else display(time_counter); } } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
6248 浏览 3 评论
7515 浏览 1 评论
7755 浏览 0 评论
Protues中自己封装的芯片元件无Program File、Clock Frequency选项怎么解决,求求大神了!
9563 浏览 1 评论
基于51单片机的车辆倒车雷达报警系统,HC-SR04超声波测距,全套资料
1280 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 01:51 , Processed in 0.885625 second(s), Total 94, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号