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

📄 jsq1.plm

📁 多个C51的源代码,在KEIL C51上已调试通过
💻 PLM
字号:
/* */
START:  do;       
$INCLUDE(REG51.DCL)
	declare ok bit;
	declare delay byte;
	declare (ms10,ms100,ms_set) byte;
	declare (dl1,dl2) byte;
	DECLARE (MODK,SDFLAG,DATA,LONG,K,ADDRL,n,I,FEND,FDISP) byte;
	DECLARE l(8) byte;
	declare (dat,j) byte at (30h);
	DECLARE ACO(12) BYTE CONSTANT (03h,9fh,25h,0dh,99h,49h,
					  41h,1fh,01h,09h,00h,0ffh);
	declare si literally 'p13',sck literally 'p14'; 
	declare cs literally 'p15',so literally 'p16';
time0:procedure interrupt 1 using 1;
	tr0=0;
	tl0=77h;
	th0=0ech;
	tr0=1;
	ms_set=ms_set+1;
	ms10=ms10+1;
	if ms10>=10 then do;
		ms10=0;
		ms100=ms100+1;
	end;
end time0;
rst_wdog:procedure;  /* 复位看门狗 */
	 cs=1;
	 ;
	 cs=0;
	 ;
	 cs=1;
end rst_wdog;

DISPLAY:PROCEDURE(L0,L10); /*显示子程序*/
	DECLARE (L0,L10) BYTE; /*定义显示二位*/
	N=L10;                 /*最大L10*/
	IF MODK=2 THEN         /**/
	DO;                    /*十位闪动子程序*/
	IF SDFLAG=1 THEN       /**/
	do;                    /**/
	sbuf=0ffh;             /**/
	do while ti=0;         /**/
	   call rst_wdog;
	end;
	sdflag=0;              /*闪动标志置0*/
	end;
	else                   /**/
	do;
	n=aco(n);           /*十位数BCD码译成  码*/
	sbuf=n;             /**/
	do while ti=0;      /**/
	   call rst_wdog;
	end;
	sdflag=1;           /*闪动标志置1*/
	end;
	end;
	if modk<>2 then     /**/
	do;
	n=aco(n);           /**/
	sbuf=n;             /**/
	 do while ti=0;     /**/
	   call rst_wdog;
	 end;
	end;
	n=L0;               /*个位闪动子程序*/
	if modk=1 then      /**/
	do;
	if sdflag=1 then    /**/
	do;
	sbuf=0ffh;          /**/
	do while ti=0;      /**/
		call rst_wdog;
	end;
	sdflag=0;          /**//**/
	end;
	else               /**/
	do;                /**/
	n=aco(n);          /**/
	sbuf=n;            /**/
	do while ti=0;     /**/
		call rst_wdog;
	end;
	sdflag=1;          /**/
	end;
	end;
	if modk<>1 then    /**/
	do;
	n=aco(n);          /*个位BCD码译  码*/
	sbuf=n;            /**/
	do while ti=0;     /**/
	   call rst_wdog;
	end;
	END;
end display;       /**/

outbyt:  procedure(da);       /*写入一字节*/
	declare (i,da) byte;
	j=da;
	do i=0 to 7;
	   sck=0;
	   j=scl(j,1);
	   si=cy;
	   sck=1;
	end;
end outbyt;   

inbyt:  procedure;   /* 读出一字节 */
	declare (i,di) byte;
	j=0;
	 do i=0 to 7;   
	sck=1;
	sck=0;
	cy=so;
	j=scl(j,1);
	 end;
	 dat=j;
end inbyt;

wrenable: procedure;   /* 写入使能不能*/
	sck=0; 
	cs=0;
	;  /* write enable command */
	call outbyt(06h);
	cs=1;
	sck=0;
end wrenable;

wrdisable: procedure;  /* 写入禁止 */
	 sck=0;
	 cs=0;
	 ; /* write disable command */
	 call outbyt(04h);
	 sck=0;
	 cs=1;
end wrdisable;

wrregister: procedure;   /* 写状态寄存器 */
	 sck=0;
	 cs=0;
	 dat=01h;      /* write register command */ 
	 call outbyt(dat);
	 ;     /* 00h--1.4S, 20h--200MS, 10h--600MS, 30h--disable Wdog */
	 call outbyt(00h); /* 看门狗定时设定 */
	 ;
	 sck=0;
	 cs=1;
	 call time(100); /* wait to complete writting cycle */
end wrregister;

rdregister:procedure;  /*  读状态寄存器 */
	 sck=0;
	 cs=0;
	 ;   /* register read command */
	 call outbyt(05h);
	 call inbyt; /* status register read in <DAT> */
	 sck=0;
	 cs=1;
end rdregister;

wbyte:procedure;   /*  字节写入 */
	  declare comm byte;
	  sck=0;
	  cs=0;
	  comm=02h;  /*  write command */
	  call outbyt(comm);
	  call outbyt(addrl);
	  call outbyt(dat);  /*  send one byte data to X25043 */
	  cs=1;
	  sck=0;
	  call time(50);
end wbyte;

rbyte:procedure;  /* 字节读出  */
	  declare comm byte;
	  sck=0;
	  cs=0;
	  comm=03h;     /* read command */
	  call outbyt(comm);
	  call outbyt(addrl);
	  call inbyt;   /* read one byte to <DAT>  */
	  sck=0;
	  cs=1;
end rbyte;

set_disp:procedure(data1,data2);
	declare (data1,data2) byte;
	call rst_wdog;
	sbuf=aco(data2);
	do while ti=0; end; ti=0;
	sbuf=aco(data1);
	do while ti=0; end; ti=0;
end set_disp;
set_time:procedure;
	declare (shut,show) bit;
	declare (ls1,ls2) byte;
	declare (led1,led2) byte;
	addrl=02h; call rbyte; ls1=dat;
	addrl=03h; call rbyte; ls2=dat;
	led1=ls1; led2=ls2;
	call set_disp(led1,led2);
	do while p12=0; call rst_wdog; end;
	shut=0;
	ms10=0; ms100=0;
	do while ms100<65;
		call rst_wdog; call time(200);
		call rst_wdog; call time(200);
		call set_disp(led1,led2);
		if p33=0 then do; call time(150);
			if p33=0 then do;
				do while p12=0; call rst_wdog; end;
				shut=not shut;
				led1=ls1; led2=ls2;
				ms10=0; ms100=0;
			end;
		end;
		if p12=0 then do; call time(150);
			if p12=0 then do;
				do while p12=0; call rst_wdog; end;
				if shut=0 then ls1=ls1+1;
				else ls2=ls2+1;
				if ls1>9 then ls1=0;
				if ls2>9 then ls2=0;
				ms10=0; ms100=0;
			end;
		end;
		if show=0 then do;
			show=1;
			if shut=0 then led1=0bh;
			else led2=0bh;
		end;
		else do; 
			show=0;
			if shut=0 then led1=ls1;
			else led2=ls2;
		end;
	end;
	call wrenable;
	if ok=0 then addrl=02h;
	else addrl=02h;
	dat=ls1;
	call wbyte;
	call wrenable;
	if ok=0 then addrl=03h;
	else addrl=03h;
	dat=ls2;
	call wbyte;
	delay=ls1+ls2*10;       
end set_time;
key1:   procedure;          /*数字增加键子程序*/
	if p12=0 then       /**/
   do;
	ms10=0; ms100=0;
	   do while p12=0;
		 call rst_wdog;
		if ms100>=20 then do;
			call set_time;
			return;
		end;
	   end;

	if modk=1 then      /*如果个位数字闪动*/
	  DO;
		L(1)=L(1)+1;        /*个位数加1*/
		IF L(1)>9 THEN L(1)=0; /*如果个位数大>9,循环是0*/
	  END;
	if modk=2 then         /**/
	  DO;
		 L(2)=L(2)+1;
		 IF L(2)>9 THEN L(2)=0; /**/
	  END;
	call display(L(1),L(2));/**/
	call time(200);
	call rst_wdog;
	call time(200);
	DATA=L(1)+L(2)*10;      /**/
	call wrenable;
	if ok=0 then addrl=00h;
	else addrl=02h;
	dat=l(1);
	call wbyte;
	call wrenable;
	if ok=0 then addrl=01h;
	else addrl=03h;
	dat=l(2);
	call wbyte;
   end;
end key1;               /**/
KEY2:   PROCEDURE;  /*mod */    /**/
	CALL TIME(100);
	  call rst_wdog;
	call time(100);
	IF P33=0 THEN           
	 do;
	do while p33=0;
		call rst_wdog;
	end;
	MODK=MODK+1;            /**/
	IF MODK=3 THEN          /**/
	do;
		modk=0;                 
		DATA=L(1)+L(2)*10;      
		call wrenable;
		if ok=0 then addrl=00h;              
		else addrl=02h;
		dat=l(1);
		call wbyte;
		call wrenable;
		if ok=0 then addrl=01h;
		else addrl=03h;
		dat=l(2);
		call wbyte;
	END;
	   CALL TIME(100);
	   call rst_wdog;
	   call time(100);
	  CALL DISPLAY(L(1),L(2));
	 END;
END KEY2;               
gal:procedure;
	ok=1;
	do while p12=0; call rst_wdog; end;
	l(1)=dl1;l(2)=dl2;
	call display(dl1,dl2);
LOOP1:  
	IF P12=0 THEN CALL KEY1; 
	IF P33=0 THEN CALL KEY2; 
	CALL DISPLAY(L(1),L(2)); 
	CALL TIME(254);      
GOTO LOOP1;               
end gal;
KEY3:   PROCEDURE;              /**/
	declare i byte;
	CALL TIME(120);         
	call rst_wdog;
	call time(120);
	 IF P35=0 THEN           /**/
do;
	DO WHILE P35=0;     /*  无此二句时按下P35键数字连续加上*/
	   call rst_wdog;
	END;                    
  if data>0 then do;
	DATA=DATA-1;            /**/
	L(1)=DATA MOD 10;       /**/
	L(2)=DATA/10;           /**/
	IF DATA=00 THEN        /*数字减少到0时P10囗输出为低*/
	 DO;
	   call display(l(1),l(2));
	   P37=0;                  /**/
	   ms10=0;ms100=0;
	   do while ms100<delay; call rst_wdog; end;
	   P37=1;                  /*P37 囗输出为高*/
	   do i=0 to 10; call time(200); end;
	   ADDRL=00H;              
	   CALL rbyte;              /**/
	   l(1)=dat;
	   addrl=01h;
	   call rbyte;
	   l(2)=dat;
	   DATA=L(1)+L(2)*10;       /**/
	END;
	end;
 END;
 END KEY3;                /**/

MAIN$PROGRAM:                    /**/
	ea=0;
	SCON=00h;                
	PCON=00h;                
	tmod=11h;
	tr0=0;
	tl0=77h;
	th0=0ech;
	tr0=1;
	et0=1;
	enable;
	SCK=0;cs=1;            
	call wrenable; 
	call wrregister; 
	call wrenable;
	/*    call rdregister;  */
	ADDRL=02h;               
	CALL rbyte;               
	dl1=dat;
	addrl=03h;
	call rbyte;
	dl2=dat;
	ok=0;
	if p12=0 then call gal;
	
	ADDRL=00h;               /**/
	CALL Rbyte;               
	l(1)=dat;
		 /******************************************/
	addrl=01h;
	call rbyte;
	l(2)=dat;
		/*******************************************/
	DATA=L(1)+L(2)*10;       /**/
	ADDRL=02h;               
	CALL Rbyte;               
	dl1=dat;
	addrl=03h;
	call rbyte;
	dl2=dat;
	delay=dl1+dl2*10;       
	MODK=0;                  /**/
LOOP:   
	IF P12=0 THEN CALL KEY1; /**/
	IF P33=0 THEN CALL KEY2; /**/
	IF P35=0 THEN CALL KEY3; /**/
	CALL DISPLAY(L(1),L(2)); /**/
	call rst_wdog; 
	CALL TIME(120);          
	call rst_wdog;
	call time(120);
GOTO LOOP;               /**/
END START;               /**/

⌨️ 快捷键说明

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