#include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit led1=P3^3; sbit led=P1^5; sbit led2=P3^6; sbit fan=P1^6; sbit ptc=P3^4; sbit we1=P2^6; sbit we2=P2^7; sbit we3=P2^1; sbit we4=P2^0; sbit we5=P2^2; sbit fm=P2^5; sbit sw1=P1^0; sbit sw2=P1^4; sbit sw3=P3^5; sbit sw4=P3^7; uchar code duma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e }; uchar counter, time,time_counter, h; uchar i ; void delay(uint z); void delay(uint z) { while (z--); } void display(uchar mshi,uchar mge,uchar sge,uchar sshi,uchar hge,uchar hshi ) { mge=time_counter%10; mshi=time_counter/10; sge=time/10; sshi=time%10; hge=h/10; hshi=h%10; P0=0XFF; we1=0; we2=1; we3=1; we4=1; P0=duma[mge]; delay(100); P0=0XFF; we1=1; we2=0; we3=1; we4=1; P0=duma[mshi]; delay(100); P0=0XFF; we1=1; we2=1; we3=0; we4=1; P0=duma[sshi]; delay(100); P0=0XFF; we1=1; we2=1; we3=1; we4=0; P0=duma[sge]; delay(100); } void keypros() { if(sw1==0) { delay(10); if(sw1==0&&time!=60) { time+=1; fm=0; delay(10000); fm=1; delay(10000); while(!sw1); } } if(sw2==0) { delay(10); if(sw2==0&&time!=0) { time-=1; fm=0; delay(10000); fm=1; delay(10000); while(!sw2); } } if(sw3==0) { delay(10); if(sw3==0) { fm=0; delay(10000); fm=1; delay(10000); TR1=0; led=1; time=0; time_counter=0; fan=1; ptc=1; while(!sw3); } } if(sw4==0) { delay(10); if(sw4==0) { TR1=~TR1; led=~led; fm=0; delay(10000); fm=1; delay(10000); ptc=~ptc; fan=~fan; while(!sw4); } } } void init() { TMOD=0x10; TH1=0x4b; TL1=0x00; TR1=0; } void main() { init(); led2=0; while(1) { keypros(); if(TF1==1) { TF1=0; TH1=0x4b; TL1=0x00; counter++; } if(counter==20) { counter=0; time_counter++; led1=~led1; } if(time_counter==60) { time--; time_counter=0; } if(time==0) { TR1=0; led=1; led1=1; ptc=1; fan=1; time=60; } display(); } } 现 这个是正常显示,,这个程序是60分钟,倒计时,时间可以调,时间到停止输出 LED1,FAN风扇,PTC加热,都停止输出,这个程序是用在艾灸上,谢谢大家指点!有你们真好! |
素还真.____ 发表于 2019-7-10 23:41 WE,就是位选信号。 |
hantu 发表于 2019-7-11 10:11 谢谢,上面的显示函数写成了静态显示了,改了动态就可以了, |
谢谢,知道了,谢谢 |
多只数码管的显示,一是要动态扫描,二是要消影。 |
你这个太乱了,一个注泽都没,wea、web、wec也不知道是什么
你显示完一个数码管,要把位清0,不然一轮下来所有位都在显示,会乱码。 进位不知道你指的什么,counter, time,time_counter, h; 看不出来你这几个变量的具体作用
|
显示乱码我知道了,是数码管是共阳极的,我用的共阴极的表,才导致显示乱码,但这个显示函数怎么写,进位显示数码管, |