Demo entry 6789542

ghj

   

Submitted by anonymous on Apr 30, 2019 at 10:52
Language: C. Code size: 2.4 kB.

#include <reg52.h>

char code lcd_1A[7]="PROJECT";
char code lcd_2A[15]=" LIGHT CONTROL ";

char code LAMP1_ON[11]=" LAMP 1 ON";
char code LAMP1_OFF[12]=" LAMP 1 OFF";
char code LAMP2_ON[11]=" LAMP 2 ON";
char code LAMP2_OFF[12]=" LAMP 2 OFF";

unsigned char number;

char t;
sbit VT = P2^4;

sbit rs = P3^2;
sbit en = P3^3;

sbit LAMP1 = P1^7;
sbit LAMP2 = P1^6;

void delay ()
{
     int i;
	 for (i=0;i<10000;i++);
}

void set_lcd()
{
	rs=0;
	P0=0x38;
	delay();
	en=1;
	delay();
	en=0;
	P0=0x0E;
	delay();
	en=1;
	delay();
	en=0;
	P0=0x01;
	delay();
	en=1;
	delay();
	en=0;			
}

void set_l1()
{
	rs=0;
	P0=0x01;
	delay();
	en=1;
	delay();
	en=0;	
}

void set_l2()
{
	rs=0;
	P0=0xc0;
	delay();
	en=1;
	delay();
	en=0;	
}

void reset_lcd()
{
	P0=0x01;
	delay();
	en=1;
	delay();
	en=0;	
}
void wr_pro()
{
	rs=1;
	for (t=0;t<7;t++)
	{
		P0=lcd_1A[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
}

void GO_1()
{
	set_l1();
	rs=1;
	for (t=0;t<10;t++)
	{
		P0=LAMP1_ON[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
	LAMP1 = 1;
}

void OFF_1()
{
	set_l1();
	rs=1;
	for (t=0;t<11;t++)
	{
		P0=LAMP1_OFF[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
	LAMP1 = 0;
}

void GO_2()
{
	set_l1();
	rs=1;
	for (t=0;t<10;t++)
	{
		P0 = LAMP2_ON[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
	LAMP2 = 1;
}

void OFF_2()
{
	set_l1();
	rs=1;
	for (t=0;t<11;t++)
	{
		P0=LAMP2_OFF[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
	LAMP2 = 0;
}

void wr_name()
{
	rs=1;
	for (t=0;t<15;t++)
	{
		P0=lcd_2A[t];
		delay();
		en=1;
		delay();
		en=0;	
	} 
	rs=0;
}

void READ_HT12D()
{
	while(1)
	{
		if (VT == 0)
		{
		continue;
		}
		else
		{
			  number = P2;
			  number = number & 0x0f;
			  while(VT == 1);
			  break;
		}
		
	 }   					
}
void main()
{
	LAMP1 = 0;
	LAMP2 = 0;
	set_lcd();
	wr_pro();
	set_l2();
	wr_name();
	delay();
	reset_lcd();
	
			while (1)
			{
				READ_HT12D();
				
					if (number == 0x00)
					{
						GO_1();
					}
					else if (number == 0x04)
					{
						OFF_1();
					}
					else if (number == 0x08)
					{
						GO_2();
					}
					else if (number == 0x01)
					{
						OFF_2();
					}				
		    }		
}

	

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).