www.pudn.com > exflag.rar > exflag.c
#include#include #include #include #define uint unsigned int #define uchar unsigned char sbit dircontrol=P1^0; sbit pwmcp=P1^1; sbit ldate =P1^2; sbit clk =P1^3; sbit mplay =P1^4; sbit flow=P1^5; sbit cs595=P1^6; sbit latch=P1^7; sbit key1=P3^2; sbit key2=P3^3; sbit key3=P3^4; sbit key4=P3^5; sbit key5=P3^6; sbit key6=P3^7; sbit light=P2^2; sbit kaiguan1=P2^3; sbit kaiguan2=P2^1; sbit key7=P2^0; uint height; uint temp; uint pwmnum; uint temp,temp1,temp2,temp3,temp4; uchar led[]={0xe7,0x84,0xd3,0xd6,0xb4,0x76,0x77,0xc4,0xf7,0xf6,0xf5,0x37,0x63,0x97,0x73,0x71,0xff}; uchar display[4]; uchar flashbit=255; uchar state=0,tag1=0,tag2=0,tag3=0; uchar times = 0,times1 = 0; void initial(); void up(); void down(); void shegaodu(); void sheshijian(); void heightdis(); void disp(unsigned char *p); void mdelay(unsigned int number); int key1check(); int key4check(); main() { uchar tag = 1; if( kaiguan1 == 0&&kaiguan2 != 0) { height = 1800; heightdis(); mdelay(500); } if(kaiguan2 == 0&&kaiguan1 != 0) { height = 0; heightdis(); mdelay(500); } initial(); shegaodu(); flashbit = 255; TH0 = 0x3C; TL0 = 0xB0; TR0 = 1; sheshijian(); while(tag==1) {if(key5==0) {mdelay(1);while(key5==0);tag=0;} } TH1 = temp4/256; TL1 = temp4%256; TR1 = 1; if(temp4 == 0xF327){mplay = 0;} up(); if(height==1800){flow = 0;} while(state==1) {if(key6==0) {mdelay(1);while(key6==0);state=0;} } TH1 = temp4/256; TL1 = temp4%256; TR1 = 1; flow = 1; down(); while(1); } void initial() { EA = 1; ET0 = 1; ET1 = 1; TMOD = 0x11; TH0 = 0x3C; TL0 = 0xB0; TR0 = 1; } void time1(void) interrupt 3 { TH1 = temp4/256; TL1 = temp4%256; pwmcp=!pwmcp; pwmnum++; } void time0(void) interrupt 1 { TH0 = 0x3C; TL0 = 0xB0; times++; if(times==200) {times=0;tag2=1;TR0=0;} if(tag2==1) {times1++; if(times1==200){times1=0;tag3=1;TR0=0;} } } int key1check() { while(tag2==0) { if(key7==0) { mdelay(1); while(key7==0); tag1=1; light=0; } if(key1==0) {mdelay(1); while(key1==0); flashbit++; //闪烁位加 if(flashbit==4){flashbit=255; } } if(flashbit<4) { if(key2==0) { mdelay(1); while(key2==0); display[flashbit]++; //闪烁位值加 if(display[flashbit]==10) display[flashbit]=0; disp(display); } if(key3==0) {mdelay(1); while(key3==0); display[flashbit]--; //闪烁位值减 if(display[flashbit]==255) display[flashbit]=9; disp(display); } } } temp1=display[0]+display[1]*10+display[2]*100+display[3]*1000; return temp1; } int key4check() { while(tag3==0) { if(key4==0) { mdelay(1); while(key4==0); flashbit++; //闪烁位加 if(flashbit>=4) { flashbit=255; } } if(flashbit<4) { if(key2==0) { mdelay(1); while(key2==0); display[flashbit]++; //闪烁位值加 if(display[flashbit]==16) display[flashbit]=0; disp(display); } if(key3==0) { mdelay(1); while(key3==0); display[flashbit]--; //闪烁位值减 if(display[flashbit]==255) display[flashbit]=15; disp(display); } } } temp3=display[0]+display[1]*16+display[2]*256+display[3]*4096; return temp3; } void heightdis () { cs595=0; display[0] = height%10; display[1] = height%100/10; display[2] = height%1000/100; display[3] = height/1000; disp(display); } void disp(unsigned char *p) { unsigned char i,j,leddata; for(i=0;i<4;i++) { leddata=led[*p]; for(j=0;j<8;j++) { leddata=leddata<<1; ldate=CY; clk=0; clk=1; clk=0; } p++; } latch=0; latch=1; latch=0; } void mdelay(unsigned int number)//延时子程序 { unsigned char temp; for ( ;number!=0;number--) { for(temp=112;temp!=0;temp--) {} } } void up() { dircontrol = 1; do { if (height >= temp2||height >= 1800) { mplay = 1; if(tag1==1) {dircontrol=0;pwmnum=0; while(1) {if(height<=1200) { TR1 = 0; pwmcp = 1; state = 1; break; } else { height = 1800 - (pwmnum * 0.15125); heightdis();} } break; } else { TR1=0; pwmcp=1; state=1; break; } } else { height = pwmnum*0.15125; } heightdis(); } while(1); } void down() { pwmnum=0; if(tag1==1) {while(1) {if(height>=1800) { goto b; } else { dircontrol = 1; height = 1200+ pwmnum * 0.15125; heightdis(); } } } else { b: pwmnum=0; while(1) { if (height <= 0) { TR1=0; pwmcp=1; break; } else { dircontrol = 0; height = temp2 - (pwmnum * 0.15125); } heightdis(); } } } void shegaodu() { cs595=0; display[0] = 0; display[1] = 0; display[2] = 0; display[3] = 0; disp(display); if (key1check() > 0&&key1check() <=1800) { temp2 = key1check(); } else { temp2 = 1800; } } void sheshijian() { cs595=0; display[0] = 0; display[1] = 0; display[2] = 0; display[3] = 0; disp(display); if (key4check() >=0xDBB3&&key4check()<=0xF71F) { temp4 = key4check(); } else temp4 = 0xF327; }