⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtt-110.c

📁 本人做的一款LED控制程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <reg52.h>
#include <stdio.h>
#include <INTRINS.H>

#define Uchar unsigned char 
#define Uint unsigned int

Uint Getkey(Uint d,r);
void print(Uint i);
void Readset(void);
void Saveset(void);

sbit I_O = P3^6;

bit Discmd;
bit Clock;
bit CHK_SIGN;
bit DMX_SIGN;
bit Wr;
bit Pclock;
bit Fclock;
bit Tclock;

Uchar disclk;
Uchar Mode ;
Uchar Menu1;
Uchar Menu2;
Uchar Display;
Uint  ADDR_CON;
Uint  Dmxaddr; 
Uchar Power	;
Uchar M_s_com;
Uchar RECDAT;
Uchar Dconter;
Uchar dmxdat[5];
Uchar Dmxmode;
Uchar Year;
Uchar Month;
Uchar Day;
Uchar idata Timer[24];
Uchar Program;
Uint  Speed;
Uchar Fadetime;
Uchar Conter1;
Uint  Conter2;
Uchar Conter3;
Uchar out[3];
Uchar pwm;
Uchar ad;
Uchar Step;
Uchar Maxout;
Uint  Uspeed;
Uchar bdata flag;
Uchar buf[4];

sfr  WDT = 0xa6;
sbit  T1_ON = flag^0;
sbit  T1_OFF = flag^1;
sbit  T2_ON = flag^2;
sbit  T2_OFF = flag^3;
sbit  T3_ON = flag^4;
sbit  T3_OFF = flag^5;
sbit  T4_ON = flag^6;
sbit  T4_OFF = flag^7; 

#include <lcd1602.c>
#include <scan_key.c> 
#include <ds1302.c>
#include <DS18B20.C>
#include <AT24C02.C>

void Dmxout(void){unsigned char i;       
       for(i=0;i<=100;i++)TXD=0;   
       for(i=0;i<=10;i++)TXD=1;
       TB8=1; 	   
       SBUF=0x55;
       while(TI!=1);TI=0;
       for(i=0;i<5;i++){SBUF=dmxdat[i];while(TI!=1);TI=0;}
}


void int0() interrupt 0 using 2 {  	    
	SCAN_KEY();		
	pwm = 0;	
	Fclock = 1;
	if(Mode >= 2){Dmxout();}
	if(key_read != 0){Display = 0;Conter1 = 0;}
	disclk++;
	if(disclk>=100){
		disclk = 0;
		Tclock = 1; 
		Clock = 1;
		if(Conter2 >= Uspeed){
			Pclock = 1;
			Conter2 = 0;
			goto nnn;
		}
		Conter2++;
nnn:	Conter1++;
		if(Conter1==10) {
			Conter1 = 0;
			Display++;
			if(Display > 2) 
				Display = 1;
		}

	}
	if(Dconter == 0) { P3_7 = 0;return;}
	Dconter--;
	Conter3++;
	if(Conter3 == 5){P3_7 = ~P3_7;Conter3 = 0;}
}
void time1() interrupt 3 using 2{	
	pwm--;							  	
	ACC=pwm-out[0];CY = ~CY; P2_5 = CY;
	ACC=pwm-out[1];CY = ~CY; P2_6 = CY;
	ACC=pwm-out[2];CY = ~CY; P2_7 = CY;	
	WDT = 0x1e;
	WDT = 0xe1;
}

Uint Getkey(Uint d,r) {
	if(key_u==1) {key_u = 0; Discmd = 1; Wr = 1; if(d>=r)d=0xffff;d++;}
	if(key_d==1) {key_d = 0; Discmd = 1; Wr = 1; if(d==0)d=r+1;d--;}
	return(d);
} 

void print(Uint i){ 
	Uchar buf [3];
	Uchar b;
	
		sprintf(buf,"%u % u % u",i);
		for(b=0; b<3; b++)DispOneChar(12+b,0,buf[b]);	
}  

void pprint(Uchar x,y, Uchar i) {
	Uchar buf[2];
							
	buf[0] = i >> 4 & 0x0f;
	buf[1] = i & 0xf;   	
	DispOneChar(x,y,buf[0]+0x30);
	DispOneChar(x+1,y,buf[1]+0x30);
}
void displaydate() {
	Uchar  buf[7]; 	
	float  tt ;
	Uint	t;

	if(Clock==1){
	 	Clock = 0;		
		reset_3w();
		wbyte_3w(0xbf);					//以多字节突发方式读取时钟数据
		buf[0] = rbyte_3w();				//秒
		buf[1] = rbyte_3w();				//分
		buf[2] = rbyte_3w();				//小时
		buf[3] = rbyte_3w();				//日期
		buf[4] = rbyte_3w();				//月份
		buf[5] = rbyte_3w();				//星期
		buf[6]  = rbyte_3w();				//年
		reset_3w();	
	
		ePutstr(0,0,"20  -  -   W    ");
		ePutstr(0,1,"  :  :          ");	
		pprint(2,0,buf[6]);
		pprint(5,0,buf[4]);
		pprint(8,0,buf[3]);
		pprint(13,0,buf[5]);
		pprint(0,1,buf[2]);
		pprint(3,1,buf[1]);
		pprint(6,1,buf[0]);
		t=Readtemp();
		if(t & 0x8000 == 1)	{t = ~t;tt = -t*0.0625;goto dist;} 		
		tt=	t*0.0625;			 	
dist:	sprintf(buf,"%fu",tt);
		buf[6] = 11;
		for(buf[5] = 0; buf[5] < 5; buf[5]++)DispOneChar(buf[6]+buf[5],1,buf[buf[5]]);
	}
}

void PDisplay(void) {
	if (Display == 1) 
		displaydate();
	if (Display == 2) {
		if(Clock==1){
			Clock = 0;
			if(Mode == 0) ePutstr(0,0,"Mode:  DMX In   ");
			if(Mode == 1) ePutstr(0,0,"Mode:  Slave    ");
			if(Mode == 2) ePutstr(0,0,"Mode:  Master   ");
			if(Mode == 3) ePutstr(0,0,"Mode:  Timers   ");
			if(ad==0){ad=1;ePutstr(0,1,"Jin Yi Lighting ");return;}					  
			if(ad==1){ad=2;ePutstr(0,1,"Zhe Jiang Nin Bo");return;}
			if(ad==2){ad=0;ePutstr(0,1,"TEL:057488005512");return;}
		}
	} 	
}

Uchar code Password1[]= {7,6,0,7,2,1,};
Uchar code Password2[]= {8,2,0,4,0,8,};
Uchar code Password3[]= {0,4,0,5,1,0,};

void Timerset() {
	Uchar menu = 0 ;
	Uchar tm = 0 ;	
	Uchar r;
	while(1){	
		if(key_e == 1){
			key_e = 0; 
			Discmd=1;
			if (tm >=2 ){tm=0xff;if(menu>=7)menu=0xff;menu++;}tm++;			
		}
		if(key_c == 1){key_c = 0; Menu2 = 0; Discmd=1; return;}
			r = Timer[menu*3+tm];
			if (tm == 0)r = Getkey(r,23);
			if (tm == 1)r = Getkey(r,59);
			if (tm == 2)r = Getkey(r,2);
			Timer[menu*3+tm] = r;
			if (Discmd==1){			
				Uchar a,b;
				
				Discmd =0;						   			
				ePutstr(0,1,"Set ON/OFF Time ");
			    ePutstr(0,0,"T :  :    S:    ");			
				DispOneChar(1,0,menu+0x31);
				a = Timer[menu*3+0]/10;
				b = Timer[menu*3+0]%10;
				DispOneChar(3,0,a+0x30);
				DispOneChar(4,0,b+0x30);
			    a = Timer[menu*3+1]/10;
				b = Timer[menu*3+1]%10;
				DispOneChar(6,0,a+0x30);
				DispOneChar(7,0,b+0x30);
				if(Timer[menu*3+2]==0)ePutstr(12,0,"NULL");
				if(Timer[menu*3+2]==1)ePutstr(12,0,"ON  ");
				if(Timer[menu*3+2]==2)ePutstr(12,0,"OFF ");
				if(tm == 0)Coruscant(4,0);
				if(tm == 1)Coruscant(7,0);
				if(tm == 2)Coruscant(15,0);
			}		  		
	}
}
Uchar Password(void) {
	Uchar Pass[6];
	Uchar x,t,p; 
	
	while(1){
setpass:if(key_e == 1){key_e = 0; if(x>=6)x=0xff;x++;Discmd=1;}
		if(key_c == 1){key_c = 0; Menu2 = 0;for (t=0; t<6; t++) Pass[t]= 0;return(p= 'N');}
		if(x<=5){
			Pass[x] = Getkey(Pass[x],9);
			if(Discmd == 1){
				Discmd = 0;
				ePutstr(0,0,"Password:****** ");
				ePutstr(0,1,"6 Bit 0-9 Number");
				DispOneChar(9+x,0,Pass[x]+0x30);
				Coruscant(9+x,0);
			}
			goto setpass;
		}
		p = 0;		
		for (t=0; t<6; t++){
			if(Pass[t] == Password1[t]) p++;
		}
		if (p==6){for (t=0; t<6; t++) Pass[t]= 0;return('Y');}
	    p = 0;		
		for (t=0; t<6; t++){
			if(Pass[t] == Password2[t]) p++;
		}
		if (p==6){for (t=0; t<6; t++) Pass[t]= 0;return('Y');}
		p = 0;		
		for (t=0; t<6; t++){
			if(Pass[t] == Password3[t]) p++;
		}
		if (p==6){for (t=0; t<6; t++) Pass[t]= 0;return('Y');}
		x =0;Discmd = 1;	     
	} 	 
}
void SetAccredit(void){ 
	Uchar x;
		
	while(1){
 		Uchar a,b;

		if(key_e == 1){key_e = 0; if(x>=2)x=0xff;x++;Discmd=1;}
		if(key_c == 1){key_c = 0; Menu2 = 0;return;}
		if(x == 0) Year = Getkey(Year,99);
		if(x == 1) Month = Getkey(Month,12);
		if(x == 2) Day = Getkey(Day,30);
		if(Discmd == 1){
			Discmd = 0;
			ePutstr(0,0,"Use Up20  -  -  ");
			ePutstr(0,1,"Set Use Date    ");			
			a = Year/10;
			b = Year%10;
			DispOneChar(8,0,a+0x30);
			DispOneChar(9,0,b+0x30);			
			a = Month/10;
			b = Month%10;
			DispOneChar(11,0,a+0x30);
			DispOneChar(12,0,b+0x30);
			a = Day/10;
			b = Day%10;
			DispOneChar(14,0,a+0x30);
			DispOneChar(15,0,b+0x30);
			if(x == 0)Coruscant(9,0);
			if(x == 1)Coruscant(12,0);
			if(x == 2)Coruscant(15,0);
		}	
	}
	
	Menu2 = 0;
}

void Setup (void) {
	
	if(Menu2==0) {
		Menu1 = Getkey(Menu1,9);
		if (key_e==1){key_e = 0; Menu2 = 1; Discmd = 1;}
		if (Menu1==0){ePutstr(0,0,"Mode Setup      ");}
		if (Menu1==1){ePutstr(0,0,"DMX Address     ");}
		if (Menu1==2){ePutstr(0,0,"DMX Channel     ");}
		if (Menu1==3){ePutstr(0,0,"Clock Setup     ");}
		if (Menu1==4){ePutstr(0,0,"Clock Timer     ");}
		if (Menu1==5){ePutstr(0,0,"Accredit Date   ");}
	    if (Menu1==6){ePutstr(0,0,"Program Select  ");}
		if (Menu1==7){ePutstr(0,0,"Speed Adjust    ");}
		if (Menu1==8){ePutstr(0,0,"Fadetime Adjust ");}
		if (Menu1==9){ePutstr(0,0,"Maxout Adjust   ");}
		              ePutstr(0,1,"Select To Setup ");
		return;
    }
		
	if (key_c==1) {key_c = 0; Menu2 = 0;}
		if (Menu1 == 0){Mode = Getkey(Mode,3);
			if(Mode == 0) ePutstr(0,0,"Mode:  DMX In   ");
			if(Mode == 1) ePutstr(0,0,"Mode:  Slave    ");
			if(Mode == 2) ePutstr(0,0,"Mode:  Master   ");
			if(Mode == 3) ePutstr(0,0,"Mode:  Timers   ");
			              ePutstr(0,1,"Set Run Mode    ");
			return;	}
		if (Menu1 == 1){  
			Dmxaddr = Getkey(Dmxaddr,512);						   
			if(Discmd == 1){ 
				ePutstr(0,0,"Start Addr:     ");
				print(Dmxaddr);Discmd = 0;}
				ePutstr(0,1,"DMX Start Addr  ");
				return;	
		}
		if (Menu1 == 2){ 
			Dmxmode = Getkey (Dmxmode,4);
			if(Discmd == 1){ 
				Discmd = 0;
				ePutstr(0,0,"Max Channel:    ");
				ePutstr(0,1,"Set DMX Input CH");
				print(Dmxmode+1);Discmd = 0;}
				return;			
		} 
	 	if (Menu1 == 3){ 			
			if('Y'== Password())initialize_DS1302();
			return;	
		}
		if (Menu1 == 4){
			Timerset();
			return;
		}
		if (Menu1 == 5){
			if('Y'== Password())SetAccredit();
			return;
		}
		if (Menu1 == 6){
			Program = Getkey(Program,15);
			if (Program == 0) ePutstr(0,0,"Static Black    ");
			if (Program == 1) ePutstr(0,0,"Static Red      ");
			if (Program == 2) ePutstr(0,0,"Static Grenn    ");
			if (Program == 3) ePutstr(0,0,"Static Blue     ");
			if (Program == 4) ePutstr(0,0,"Static Yellow   ");
			if (Program == 5) ePutstr(0,0,"Static Purple   ");
			if (Program == 6) ePutstr(0,0,"Static Cyan     ");
			if (Program == 7) ePutstr(0,0,"Static White    ");
			if (Program == 8) ePutstr(0,0,"A:R.G.B.Y.P.C.W.");
			if (Program == 9) ePutstr(0,0,"A:  R. G. B.    ");
			if (Program == 10)ePutstr(0,0,"Roll:  R. G. B. ");
			if (Program == 11)ePutstr(0,0,"A:  G. B. P.    ");
			if (Program == 12)ePutstr(0,0,"Flash: R. G. B. ");
			if (Program == 13)ePutstr(0,0,"Flash: RGBYPCW  ");
			if (Program == 14)ePutstr(0,0,"Roll:  RGBYPCW  ");
			if (Program == 15)ePutstr(0,0,"    Run All     ");
		                      ePutstr(0,1,"Select Program  ");
			return;
		}
	    if (Menu1 == 7){
			Uchar a,b,c;
			
			Speed = Getkey(Speed,3599);
			if (Discmd == 1){
				Discmd = 0;
				if(Speed<=0x3a){
					ePutstr(0,0,"Speed:         S");
					print(Speed+1);
					ePutstr(0,1,"Set Run Speed   ");
					return;
				}
				ePutstr(0,0,"Speed:      .  M");
				a = Speed/60;
				b = a/10;
				c = a%10;
				DispOneChar(10,0,b+0x30);
				DispOneChar(11,0,c+0x30);
				a = Speed%60;
				b = a/10;
				c = a%10;
				DispOneChar(13,0,b+0x30);
				DispOneChar(14,0,c+0x30);
				ePutstr(0,1,"Set Run Speed   ");
			}
			return;
		}
		if (Menu1 == 8){
			Fadetime = Getkey(Fadetime,100) ;
			if (Discmd == 1){
				Discmd = 0;
				ePutstr(0,0,"Fadetime:       ");
				print(Fadetime);
				ePutstr(0,1,"Set Run Fadetime");
			}
			return;
		}
		if (Menu1 == 9){
			Maxout = Getkey(Maxout,255) ;
			if (Discmd == 1){
				Discmd = 0;
				ePutstr(0,0,"Maxout:         ");
				print(Maxout);
				ePutstr(0,1,"Set Brightness  ");
			}
			return;
		}
}
Uchar Checkdate(void) {
	Uchar  yr, mn, date, dy, hr, min, sec;
	
	reset_3w();
	wbyte_3w(0xbf);							//以多字节突发方式读取时钟数据
	sec = BCD2HEX(rbyte_3w());				//秒
	min = BCD2HEX(rbyte_3w());				//分
	hr =  BCD2HEX(rbyte_3w());				//小时
	date = BCD2HEX(rbyte_3w());				//日期
	mn =  BCD2HEX(rbyte_3w());				//月份
	dy =  BCD2HEX(rbyte_3w());				//星期
	yr  = BCD2HEX(rbyte_3w());				//年
	reset_3w();
	if(yr>=Year){
		if(mn>=Month){
			if(date>=Day)
				return('Y');
		}		
	}
	if(yr>=05){
		if(mn>=06)
			return('N');
	}
	return('Y');		
}
Uchar code Ptab1[][3]= {
	000,000,000,
	255,000,000,
	000,255,000,
	000,000,255,
	255,255,000,
	255,000,255,
	000,255,255,
	255,255,255,
};
Uchar code Ptab2[][3]= {	
	000,255,000,
	000,000,255,	
	255,000,255,	
};
Uchar code Ptab3[][3]= {	
	255,000,000,
	000,000,000,
	000,255,000,
	000,000,000,
	000,000,255,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -