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

📄 et.c

📁 Electronic Timer for controlling device
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************/
/******** Program Description : Electronic Timer Program *******/
/***************** Programmer : Amit Kumar Das *****************/
/*************** Program Date : 21st March 2009 ****************/
/*************** Program Time : 05:30 PM ***********************/
/************ Microcontroller : AT89S52 ************************/
/******** Operating Frequency : 12.0MHz ************************/
/***************************************************************/      

#include <reg51.h>
#include <string.h>

sbit rs = P2^7;     // declare P2.7 as rs pin
sbit en = P2^5;     // declare p2.5 as enable pin
sbit rw = P2^6;     // declare p2.6 as read/write pin
sbit b = P0^7;      // busy flag 

sbit outbit = P2^0; // ouput for relay
sbit start = P3^3;

sbit tenmin = P1^0;
sbit twentymin = P1^1;
sbit thirtymin = P1^2;
sbit fortymin = P1^3;
sbit fiftymin = P1^4;
sbit sixtymin = P1^5;
sbit nintymin = P1^6;
sbit onetwentymin = P1^7;
sbit onefiftymin = P3^0;
sbit oneeightymin = P3^1;


void writecmd(unsigned char a)
{
 busy();   // check for LCD is busy or not
 rs = 0;   // clear rs pin for command
 rw = 0;   // clear rw pin to write
 P0 = a;   // send command character
 en = 1;   // strob LCD
 en = 0;
}
void writedat(unsigned char b)
{
 busy();   // check for LCD is busy or not
 rs = 1;   // set rs pin for data
 rw = 0;   // clear rw pin to write
 P0 = b;   // send data character
 en = 1;   // strob LCD
 en = 0; 
}
void busy()
{
 en = 0;   // disable display
 P0 = 0xFF;  // configur P0 as input
 rs = 0;   // clear rs pin for command
 rw = 1;   // set rw pin to read
 while(b==1)
 {
  en=0;   // strob LCD till P0.7 is 1
  en=1;
 }
 en=0;
}
void writestr(unsigned char *s)
{
 unsigned char l,i;
 l = strlen(s);               // get the length of string
 for(i=1;i<l;i++)
 {
  writedat(*s);              // write every char one by one
  s++;  
 }
}
   
void MSDelay(unsigned int itime)

	{
		unsigned int i,j;
		for(i=0;i<itime;i++)
		for(j=0;j<1275;j++);
	}
	 
void main(void)

 {
    	P0=0x00;                     // P0 and P2 as output ports
    	P2=0x00;					 // LCD controls output
		P1=0xFF;					 
		P3=0xFF;
		writecmd(0x38);              // initialize 5X7 matrix LCD
    	writecmd(0x0E);    
    	writecmd(0x82);				 // move cursor to first line 2nd pos
		writecmd(0x01);              // clear memory and home cursor
    	writestr("Electronic Timer ");  // write message in first line  
		writecmd(0xC1);              // clear memory and home cursor
    	writestr("Initializing.. ");  // write message in first line  
		MSDelay(500);
here:	writecmd(0x01);
		writecmd(0x82);
		writestr("Enter Time: ");
		
  while(1)
  {

  while(tenmin==1)
   {
      writecmd(0xC3);
	  writestr("10 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto ten;
   }
   else goto here;	  
   }
   while(twentymin==1)
   {
      writecmd(0xC3);
	  writestr("20 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto twenty;
   }
   else goto here;	  
   }
  while(thirtymin==1)
   {
      writecmd(0xC3);
	  writestr("30 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto thirty;
   }
   else goto here;	  
   }
  while(fortymin==1)
   {
      writecmd(0xC3);
	  writestr("40 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto forty;
   }
   else goto here;	  
   }
   while(fiftymin==1)
   {
      writecmd(0xC3);
	  writestr("50 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto fifty;
   }
   else goto here;	  
   }
   while(sixtymin==1)
   {
      writecmd(0xC3);
	  writestr("60 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto sixty;
   }
   else goto here;	  
   }
   while(nintymin==1)
   {
      writecmd(0xC3);
	  writestr("90 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto ninty;
   }
   else goto here;	  
   }
   while(onetwentymin==1)
   {
      writecmd(0xC3);
	  writestr("120 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto onetwenty;
   }
   else goto here;	  
   }
   while(onefiftymin==1)
   {
      writecmd(0xC3);
	  writestr("150 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto onefifty;
   }
   else goto here;	  
   }
   while(oneeightymin==1)
   {
      writecmd(0xC3);
	  writestr("180 Minutes ");
   if(start==1)
   {
   outbit=1;
   writecmd(0x01);
   writecmd(0x82);
   writestr("Time Left: ");
   goto oneeighty;
   }
   else goto here;	  
   }

 oneeighty: writecmd(0xC1);              
    	    writestr("180 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("179 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("178 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("177 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("176 Minutes "); 
	    	MSDelay(500);
  			writecmd(0xC1);              
    	    writestr("175 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("174 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("173 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("172 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("171 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("170 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("169 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("168 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("167 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("166 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("165 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("164 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("163 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("162 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("161 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("160 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("159 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("158 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("157 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("156 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("155 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("154 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("153 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("152 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("151 Minutes "); 
	    	MSDelay(500);
 onefifty:	writecmd(0xC1);              
            writestr("150 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("149 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("148 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("147 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("146 Minutes "); 
	    	MSDelay(500);
 			writecmd(0xC1);              
    	    writestr("145 Minutes "); 
	    	MSDelay(500);
  			writecmd(0xC1);              
    	    writestr("144 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("143 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("142 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("141 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("140 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("139 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("138 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("137 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("136 Minutes "); 
	    	MSDelay(500);
			writecmd(0xC1);              
    	    writestr("135 Minutes "); 
	    	MSDelay(500);

⌨️ 快捷键说明

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