Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/02/10 07:35
Read: times


 
Msg Score: -1
 -1 Non-Specific question
#179434 - error
can anyone help me we this code I have some errors with the {while) commands
#include<reg51.h>
#define port P1
#define adc_input P0
#define cont_port P3
#define dataport P2
#define m_sec 10
sbit rs = cont_port^0;
sbit rw = cont_port^1;
sbit en = cont_port^6;
sbit dig_hr1=port^0;
sbit dig_min1=port^1;
sbit start=port^2;
sbit am_pm=port^3;
sbit set_button=port^4;
sbit alarm=port^7;
sbit wr= P3^2;
sbit rd= P3^3;
sbit intr= P3^4;


    // define all varibales
    
 
int hr ,hr1=0,alarm_hr=0;
int min,min1=0,alarm_min=0;
int sec,sec1=0,dig_am_pm=0,alarm_am_pm1=0;
int test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};
int alarmoff=50,alarm2off=121,am_pm1,set;
int alarm2,alarm2_hr,alarm2_min,alarm2_am_pm,am_pm2,min2,hr2,alarm_am_pm2;
int alarm3,alarm3_hr,alarm3_min,alarm3_am_pm,am_pm3,min3,hr3,alarm_am_pm3;
int alarm4,alarm4_hr,alarm4_min,alarm4_am_pm,am_pm4,min4,hr4;
int alarmoffset=30,alarm_set;
int dig_hr,dig_min,dig_hr2,dig_min2,dig_hr3,dig_min3,dig_hr4;



void delay(unsigned int msec) // Time dealy function
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item)  //Function to send command to LCD           
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str[i]!='')
{
  lcd_data(str[i]);
  i++;
  delay(1);
}
return;
}

void lcd_data_int(int time_val)  // Function to send number to LCD
{
int int_amt;
int_amt=time_val/10;
lcd_data(int_amt+48);
int_amt=time_val%10; 
lcd_data(int_amt+48);
}

void lcd(unsigned char str1[10])
{
lcd_cmd(0x38); 
lcd_cmd(0x0e); 
delay(1);
lcd_data_string(str1);
}

void shape()  // Function to create the shape of degree
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}

void convert()  // Function to convert the data of ADC
{
int s;
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc9);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('C');
lcd_data(' ');
delay(2);
}

void set_hr1()  // Function to set set hours digit of clock
{
hr1++;
if(hr1>11)
hr1=0;
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
}

void set_min1()  // Function to set set minutes digit of clock
{
min1++;
if(min1>59)
min1=0;
lcd_cmd(0xc6);
lcd_data_int(min1);
}

void set_alarm_hr1() // Function to set set hours digit of alarm
{
alarm_hr++;
if(alarm_hr>11)
alarm_hr=0;
lcd_cmd(0xc3);
lcd_data_int(alarm_hr);
lcd_data(':');
}

void set_alarm_min1() // Function to set set minutes digit of clock
{
alarm_min++;
if(alarm_min>59)
alarm_min=0;
lcd_cmd(0xc6);
lcd_data_int(alarm_min);
}

void alarm_check()  // Function to check alarm
{
if(hr==alarm_hr)
{
  if(min==alarm_min)
   {
    alarm=1;
    alarmoff=0;
    lcd_cmd(0x8b);
    lcd_data_string("ALARM");
   }
  
} 
}
void alarm2_check() // check alarm 2
{
if(hr==alarm2_hr)
{
  if(min==alarm2_min)
   {
    if (dig_am_pm==alarm2_am_pm)
    {
    alarm2=1;
    lcd_cmd(0x8b);
    lcd("ALARM2");
   }
   }
} 
} 
void alarm3_check() // check alarm 3
{
if(hr==alarm3_hr)
{
  if(min==alarm3_min)
   {
    if (dig_am_pm==alarm3_am_pm)
    {
    alarm2=0;
    lcd_cmd(0x8b);
    lcd_data_string("      ");
   }
   }
} 
} 
void alarm4_check() //check alarm4
{
if (alarm4==alarm4_hr)
{
alarm4=1;
lcd_cmd(0x8b);
lcd_data_string("alarm4");
}
} 
void alarm_off() //alarm off
{
if(alarmoff==alarmoffset)
{
alarm=0;
lcd_cmd(0x8b);
lcd_data_string("      ");
}
} 

void temp() // Function to calculate temperature
{
int i;
for(i=0;i<10;i++)
{
  delay(1);
  rd=1;
  wr=0;
  delay(1);
  wr=1;
  while(intr==1);
  rd=0;
  lcd_cmd(0x88);
  test_intermediate1[i]=adc_input/10;
  delay(1);
  intr=1;
}
for(i=0;i<10;i++)
test_intermediate2[0]=test_intermediate1[i]+test_intermediate2[0];

for(i=0;i<10;i++)
{
  delay(1);
  rd=1;
  wr=0;
  delay(1);
  wr=1;
  while(intr==1);
  rd=0;
  lcd_cmd(0x88);
  test_intermediate1[i]=adc_input/10;
  delay(1);
  intr=1;
}
for(i=0;i<10;i++)
test_intermediate2[1]=test_intermediate1[i]+test_intermediate2[1];

for(i=0;i<10;i++)
{
  delay(1);
  rd=1;
  wr=0;
  delay(1);
  wr=1;
  while(intr==1);
  rd=0;
  lcd_cmd(0x88);
  test_intermediate1[i]=adc_input/10;
  delay(1);
  intr=1;
}
for(i=0;i<10;i++)
test_intermediate2[2]=test_intermediate1[i]+test_intermediate2[2];

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_final=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
convert();
}


void set_up()// set alarms and time
{
delay(200);
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd_data_string("set feeder");
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
lcd_data_int(min1);
	While(set==1);
	{
		delay (10);
	if(dig_hr1==0)
		set_alarm_hr1();
	if (dig_min1==0)
		set_alarm_min1();
	if(am_pm1==0)
		{
		lcd_cmd(0xcb);
		lcd_data_string("am");
		alarm_am_pm1=0;
		}
	if (am_pm1==1)
		{
		lcd_cmd(0xcb);
		lcd_data_string("pm");
		alarm_am_pm1=1;
		}
    if(set_button==1)
    	set++;
    	}
    	
    	
    	//alarm 2 start
    	delay(200);
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd_data_string("set light on");
lcd_cmd(0xc3);
lcd_data_int(hr2);
lcd_data(':');
lcd_data_int(min2);
	While (set==2);
	{
		delay (10);
	if(dig_hr2==0)
		set_alarm_hr2();
	if (dig_min2==0)
		set_alarm_min2();
	if(am_pm2==0)
		{
		lcd_cmd(0xcb);
		lcd_data_string("am");
		alarm_am_pm2=0;
		}
	if (am_pm2==1)
		{
		lcd_cmd(0xcb);
		lcd_data_string("pm");
		alarm_am_pm2=1;
		}
    if(set_button==1)
    	set++;
    	}
    	
    	
    	
    	// start alarm 3
delay(200);
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd_data_string("set light off");
lcd_cmd(0xc3);
lcd_data_int(hr3);
lcd_data(':');
lcd_data_int(min3);
	While (set==3);
	{
		delay (10);
	if(dig_hr3==0)
		set_alarm_hr3();
	if (dig_min3==0)
		set_alarm_min3();
	if(am_pm3==0)
		{
		lcd_cmd(0xcb);
		lcd_data_string("am");
		alarm_am_pm3=0;
		}
	if (am_pm3==1)
		{
		lcd_cmd(0xcb);
		lcd_data_string("pm");
		alarm_am_pm3=1;
		}
    if(set_button==1)
    	set++;
    	}
    	
    	
    	// start alarm 4
delay(200);
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd_data_string("Tank Refill");
lcd_cmd(0xc3);
lcd_data_int(hr4);
lcd_data(' ');
lcd_data_string("  ");
	While (set==4);
	{
		delay (10);
	if(dig_hr4==0)
		{
		set_alarm_hr4();
	   lcd_cmd(0xcb);
		lcd_data_string("  ");
		}		
    if(set_button==1)
    	set++;
    	}
    	
    	
    	//set Time 5
    	
    	
delay(200);
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd_data_string("set time");
lcd_cmd(0xc3);
lcd_data_int(hr);
lcd_data(':');
lcd_data_int(min);
	While (set==5);
	{
		delay (10);
	if(dig_hr==0)
		set_alarm_hr();
	if (dig_min==0)
		set_alarm_min();
	if(am_pm==0)
		{
		lcd_cmd(0xcb);
		lcd_data_string("am");
		dig_am_pm=0;
		}
	if (am_pm==1)
		{
		lcd_cmd(0xcb);
		lcd_data_string("pm");
		dig_am_pm=1;
		}
    if(set_button==1)
    	set=0;
    	}
    	}
    	
    	// need to check all variablles for consistancy

		
		



void main()
{
int k;
start=1;
dig_hr1=1;
dig_min1=1;
alarm_set=0;
alarm=0;
lcd_cmd(0x01);
while(1)
{
  for(k=0;k<2;k++)
  {
   for(hr=hr1;hr<12;hr++)
   {
    alarm2++;
    alarm3++;
    for(min=min1;min<60;min++)
    {
     alarmoff++;
     alarm2off++;
     for(sec=0;sec<60;sec++)
     {
      lcd_cmd(0x81);
      delay(1);
      lcd_data_int(hr);
      lcd_data(':');
      lcd_data_int(min);
      lcd_data(':');
      lcd_data_int(sec);
      if(dig_am_pm==0)
      {
       lcd("am");
      }
      else
      {
       lcd("pm");
      }
      alarm_check();
      alarmoff_check();
      alarm2_check();
      alarm3_check();
      alarm4_check();
      if(set_button==1)
      {
       set=1
       set_up()
      }
      lcd_cmd(0xc3); 
      delay(2);
      lcd_data_string("TEMP:");
      temp();
      lcd_data_string("    ");
     }
     }
    }
   min1=0;
   }
  if(dig_am_pm==0)
  dig_am_pm=1;
  else
  dig_am_pm=0;
  hr1=0;
  }
}
 
 

 



List of 5 messages in thread
TopicAuthorDate
error            01/01/70 00:00      
   What errors, exactly?            01/01/70 00:00      
      Definitely borked while statements there            01/01/70 00:00      
         It's been said before            01/01/70 00:00      
   Bad While            01/01/70 00:00      

Back to Subject List