Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with a code for 2 switches

Status
Not open for further replies.

prasadsrkrec

Junior Member level 2
Joined
May 18, 2012
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,421
I am using 2 switches one is for increasing and 2nd one is for decreasing..

with that two switches only i gave two types of displays on lcd using flag.
now i want to give condition to two different displays..

Code like this


switch()
{

for 1st switch
if(flag1 == 0)
flag = 1;
if(flag2 == 0)
condition


for 2nd switch
also same
but i want to give different condition how?????????
 

Re: Reagarding Switch Case ?

Not able to comprehend. Please rephrase.
 

Re: Reagarding Switch Case ?

I am Using 3 flags and 3 switches in 8051 microcontroller program interfacing with lcd

in switch function i gave like this

Code:
sw_press()
{
if(sw1 == 0)
{
    if(flag1 == 0)
    flag1 = 1;
   
   else if(flag2 == 0)
    flag2 =1;
   
  else 
      {
      if(flag3 == 0)
      {
      low++;
      if(low > 40.0)
      low = 0.0;
      }
      else
      {
       if(flag3 == 0)
       {
        high++;
        if(high > 40.0)
        high = 0.0;
       }
    }
if(sw2 == 0)
{
    if(flag1 == 0)
    flag1 = ~flag1;
   
   else if(flag2 == 0)
    flag2 =~flag2;
   
  else 
      {
      if(flag3 == 0)
      {
      low++;
      if(low > 40.0)
      low = 0.0;
      }
      else
      {
       if(flag3 == 0)
       {
        high++;
        if(high > 40.0)
        high = 0.0;
       }
    }
here high means 16*2 lcd dispaly top position if press enter cursor change into low positon display

means on lcd high postion range is 0.0 --40.0 and low position range is 0.0 --40.0
if i press sw1 either high or low incremented by 1 ..
if i press sw2 either high or low incremented by 0.1

so now i want to change ranges of flag1 is 0.0 to 20 and flag 2 is 20 -40 . tell me any suggestion..
 
Last edited by a moderator:

Re: Reagarding Switch Case ?

Code:
[CODE]
void sw_press(void)
{
	SFRPAGE = CONFIG_PAGE; 
	
	if(incr == 0)
	{
		MSDelay(5);
		if(incr == 0)
		{
			if(Mode_flag == 0)
				Mode_flag = 1;

			else if(Cal_flag == 0)
				Cal_flag = 1;		
			
			else 
			{
				if(SW_flag == 0)
				 {
					low++;
					if(low > 20.9)
							low = 0.0;
					convert_lcd(low*10, 3);
					lcdcmd(0xC0);
					lcddata(a_lcd[2]);
					lcddata(a_lcd[1]);
					lcddata('.');
					lcddata(a_lcd[0]);
					while(incr == 0); 
				}
				else 
				{
					high ++;
					if(high > 20.9)
							high = 0.0;
					convert_lcd(high*10, 3);
					lcdcmd(0x80);
					lcddata(a_lcd[2]);
					lcddata(a_lcd[1]);
					lcddata('.');
					lcddata(a_lcd[0]);
					while(incr == 0); 
				}
			}
			convert_flash(low*10, 3);
			for(t = 0 ; t < 3 ; t++)
				l_flash[t] = flash[t];
								
			convert_flash(high*10, 3);
			for(t = 0 ; t < 3 ; t++)
				h_flash[t] = flash[t];
							
			MEM_erase();
			MEM_write();
		}
	}
   
	if(decr == 0)
	{
		MSDelay(5);
		if(decr == 0)
		{
			if(Mode_flag == 0)
				Mode_flag = ~Mode_flag;

		 	else if(Cal_flag == 0)
				Cal_flag = ~Cal_flag;	  
			
			else 
			{
				if(SW_flag == 0)
				 {
					low+= 0.1;
					if(low > 20.9)
						low = 0.0;
					convert_lcd(low*10, 3);
					lcdcmd(0xC0);
					lcddata(a_lcd[2]);
					lcddata(a_lcd[1]);
					lcddata('.');
					lcddata(a_lcd[0]);
					while(decr == 0);
				}
				else
				{
					high+= 0.1;
					if(high > 20.9)
						high = 0.0;
					convert_lcd(high*10, 3);
					lcdcmd(0x80);
					lcddata(a_lcd[2]);
					lcddata(a_lcd[1]);
					lcddata('.');
					lcddata(a_lcd[0]);
					while(decr == 0);
				}
			}
			convert_flash(low*10, 3);
			for(t= 0 ; t < 3 ; t++)
				l_flash[t] = flash[t];

			convert_flash(high*10, 3);
			for(t= 0 ; t < 3 ; t++)
				h_flash[t] = flash[t];
				
			MEM_erase();
			MEM_write();
		}
	}
	
	if(entr == 0)
	{
		MSDelay(5);
		if(entr == 0)
		{	
			SW_flag = ~SW_flag;
			buzzer = 1;
			MSDelay(100);
			buzzer = 0;
			while(entr == 0);
		}
	}
}

if mode flag becomes 1 display one statement
not one display other mode
so finally i want conditions in software flags also different

means ...for mode flag 1 display i want range for low and high is 0 -20
and ,ode flag not one means i want range 20 -40 for low and high..

give me some logic behind ........
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top