angmall 发表于 2019-5-26 20:07 您的有点问题 因为while(1)跳不出循环 所以编的有点问题 |
wulin 发表于 2019-5-26 14:13 谢谢 值得学习 |
给你改了,对比一下就知道哪里错了。
|
wusir 发表于 2019-5-26 08:51 #include<reg51.h> sbit a=P3^3; sbit b=P3^4; sfr P2M0=0xf3; sfr P2M1=0xff; unsigned char code Tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned char int_time; unsigned char second; void delay() { unsigned char i; for(i=0;i<200;i++); } void DisplaySecond(unsigned char k) { P2=0x08; P1=Tab[k%10]; delay(); P2=0x04; P1=Tab[k/10]; delay(); } void main() { second=0; while(1) { if(a==0) { second=12; } if(b==0) { second=13; } DisplaySecond(second); } } |
为什么 不能显示12和13呢 |
不改变其它位状态的方法 void DisplaySecond(unsigned char k) { P2&=0xf3;//清0 P2.2、P2.3 P2|=0x08;//赋值P2.2、P2.3 P1=Tab[k%10]; delay(); P2&=0xf3;//清0 P2.2、P2.3 P2|=0x04;//赋值P2.2、P2.3 P1=Tab[k/10]; delay(); } |
貌似可以引入一个中间函数,通过与、或逻辑关系运算,最终得到你想要 的结果“只想用2.2;2.3,不影响其他口” |