#include #define unchar unsigned int ***it D1=P2^0; //将D1位定义为P2.0引脚 ***it D2=P2^1; //将D2位定义为P2.1引脚 ***it D3=P2^2; ***it D4=P2^3; ***it D5=P2^4; ***it A1=P2^2; ***it B1=P2^3; ***it C1=P2^4; ***it key1=P1^7; ***it key2=P1^6; ***it key3=P1^5; ***it key4=P1^4; ***it key5=P3^2; ***it key6=P3^3; ***it pwm=P3^7; ***it xh=P2^7; void Starttime1(void); unchar bai,shi,h1,ge,qian,bai1,qian1,ge1,shi1; unchar k,h,b,e,e1,g,w; unchar code table[]={0x3f,0X06,0x5b,0x4f,0x66,0X6d,0x7d,0x07,0x7f,0x6f}; void display(unchar,unchar,unchar,unchar); void display1(int a); void delay(unchar); void tiaopin(void); void StartTime0(void); void main(void) {EA=1;//开总中断 IT0=1; TR0=0; TR1=0; A1=0; B1=0; C1=0; pwm=0; h=1000; StartTime0(); EX0=1; IT1=1; EX1=1; while(1) {display(qian,bai,shi,ge); display1(e1); } } void display(unchar qian,unchar bai,unchar shi,unchar ge)//频率显示 { A1=0,B1=0,C1=0; P0=table[ge]; delay(5); P0=0xff; A1=1,B1=0,C1=0; P0=table[shi]; delay(5); P0=0xff; A1=0,B1=1,C1=0; P0=table[bai]; delay(5); P0=0xff; A1=1,B1=1,C1=0; P0=table[qian]; delay(5); P0=0xff; } void display1(int e1) { w=e1; bai1=w/100; shi1=w%100/10; ge1=w%10; A1=0,B1=0,C1=1; P0=table[ge1]; delay(5); P0=0xff; A1=1,B1=0,C1=1; P0=table[shi1]; delay(5); P0=0xff; A1=0,B1=1,C1=1; P0=table[bai1]; delay(5); P0=0xff; A1=1,B1=1,C1=1; P0=table[qian1]; delay(5); P0=0xff; } void StartTime0(void) {TMOD=0x12; //使用定时器T0,工作方式1 ET0=1; ET1=1; PT1=1; } void int1(void) interrupt 2 {e++; h=1000; TR0=1; TR1=1; delay(100); while(!key6); } void int0(void) interrupt 0 { TR0=0; TR1=0; tiaopin();//调频 b=100*bai+10*shi+ge; if(b>18) {h=23364/b; TL0=236; TH0=236; //初值 TR0=1; } else {TH1=(65536-1000)/256; //1毫秒初值,h=1000; TL1=(65536-1000)%256; h=500/b; TR1=1; } } void Time1(void) interrupt 3 { TH1=(65536-1000)/256; //1毫秒初值,h=1000; TL1=(65536-1000)%256; k++; if(k==h) {pwm=!pwm; e1=e; e=0; k=0;} } void Time0(void) interrupt 1 {k++; if(k==h) {pwm=!pwm; k=0;} } void tiaopin()//调节方波频率 {TR0=0; TR1=0; while(1) {display(qian,bai,shi,ge); if(key1==0) {delay(5); if(key1==0) {bai++; while(!key1);} if(bai==10) bai=0;} if(key2==0) {delay(1); if(key2==0) {shi++; while(!key2);} if(shi==10) shi=0;} if(key3==0) {delay(1); if(key3==0) {ge++; while(!key3);} if(ge==10) ge=0;} if(key4==0) delay(1); if(key4==0) {delay(100); if(key4==0) break;} } } void delay(unchar t)//延时函数 {unchar i,j; for(i=t;i>0;i--) for(j=5;j>0;j--); } |
更多回帖