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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/21/05 07:03
Read: times


 
#99762 - Digital amp-hour meter is having errors
i have written the code for my digital ampere hour meeter , but when i compile it with kiel uvision software. i find these errors


D:DOCUMENTS AND SETTINGSNARENDERDESKTOPAHMETERKEY_LCD_FULL.C(21): error C132: 'rnge': not in formal parameter list
D:DOCUMENTS AND SETTINGSNARENDERDESKTOPAHMETERKEY_LCD_FULL.C(22): error C244: 'res': can't initialize, bad type or class
D:DOCUMENTS AND SETTINGSNARENDERDESKTOPAHMETERKEY_LCD_FULL.C(22): error C132: 'res': not in formal parameter list
D:DOCUMENTS AND SETTINGSNARENDERDESKTOPAHMETERKEY_LCD_FULL.C(23): error C244: 'flag': can't initialize, bad type or class
D:DOCUMENTS AND SETTINGSNARENDERDESKTOPAHMETERKEY_LCD_FULL.C(23): error C132: 'flag': not in formal parameter list
compiling define.h...
Target not created


what might be the problem , can any one help me out of this ,,,,
iam pasting the full code and the difine.h header file too please help.


/********* header file (define.h) */
#define LCD_RS P1_5
#define LCD_RW P1_6
#define LCD_EN P1_7


/****************/


#include <AT898252.H>
#include"define.h"
void range(void);
void resolution(void);
void pre_value(void);
void exit(void);
void LCD_init(void);
void LCD_write(unsigned char , unsigned char );
void timer_counter(void);
void keypad(void);
char keyscan(char);
char keyscanenter(void);
void write_to_eprom(void);
void DELAY_HARDWARE_One_Second(void);
void DELAY_HARDWARE_50ms(void);
void big_delay(void);
void big_delay(void)


//unsigned char pin; /* pin refers to the pin to be scanned*/
unsigned char rnge; /* rnge refers to the value of shunt */
float res = 0.000; /* res refers to the resolution with which ah should be displayed*/
unsigned char flag = 0; /* flag temperory variable to check condition*/
unsigned char xdata mem_ah;//data in internal EEPROM
flaoat ahfinal = 0.0000;

void main(void)
{
unsigned char value; /** value for enter key***/
unsigned char vald; /** vald for down key ****/
unsigned char valup; /** valup for up key *****/

LCD_init();
LCD_write(1,'D');
LCD_write(1,'A');
LCD_write(1,'T');
LCD_write(1,'A');
LCD_write(1,'L');
LCD_write(1,'O');
LCD_write(1,'G');
big_delay();

LCD_init();
LCD_write(1,'C');
LCD_write(1,'O');
LCD_write(1,'N');
LCD_write(1,'T');
LCD_write(1,'R');
LCD_write(1,'O');
LCD_write(1,'L');
LCD_write(1,'S');
big_delay();
keypad();
}



/******************************* keypad_program************/

void keypad()
{


LCD_init();
LCD_write(1,'P');
LCD_write(1,'R');
LCD_write(1,'E');
LCD_write(1,'S');
LCD_write(1,'S');
LCD_write(1,' ');
LCD_write(1,'M');
LCD_write(1,'E');
LCD_write(1,'N');
LCD_write(1,'U');
big_delay();

value = 0;
while(!flag)
{
value = kayscanenter();
if (value == 0)
{
lab_range: LCD_init();
LCD_write(1,'R');
LCD_write(1,'A');
LCD_write(1,'N');
LCD_write(1,'G');
LCD_write(1,'E');
big_delay();
range();
flag = 1;
} /* if statement for press menu ends ends */
} /* while loop ends for press menu */
} /* key pad program ends*/








/****************** lcd initialization **************************/

/* lcd initialistion*/
void LCD_init(void)
{
LCD_write(0,0x30);
LCD_write(0,0x0F);
LCD_write(0,0x06);
LCD_write(0,0x01);
LCD_write(0,0x00);
}

/************************ function for writing to lcd starts *************/
void LCD_write(unsigned char data_ctrl, unsigned char LCD_data)
{
unsigned char temp1,temp2;
temp1 = 0x0F;
temp2 = 0xF0;
temp1 = temp1 & LCD_data;
temp2 = temp2 & LCD_data;
temp2 >>= 4; //temp2 = temp2 >> 4;
LCD_RS = data_ctrl;
LCD_RW = 0;
//sending MSB 4 bits
P2 &= 0xF0;
P2 |= temp2;
LCD_RS = data_ctrl;
LCD_RW = 0;
P2 = LCD_data;
LCD_EN = 0;
small_delay();
LCD_EN = 1;
small_delay();
LCD_EN = 0;
//sending LSB 4 bits
P2 &= 0xF0;
P2 |= temp1;
LCD_EN = 0;
small_delay();
LCD_EN = 1;
small_delay();
LCD_EN = 0;
}

/************************ function for writing to lcd ends *************/


/*********** function for loading the range (value of shunt) *************/

void range()
{
value = 0;
vald = 0;
flag = 0;
while (!flag) /* while for range selection enter starts */
{
value = keyscanenter();
vald = keyscan(1); /** scan for down (resolution) key */
if ((value == 0) || (vald == 0)) /* if stat for 2 keys check(range or resolution ) starts */
{

if (value == 0) /* if stat for (range or resolution) enter key starts */
{
lab_25A: LCD_init();
LCD_write(1,'2');
LCD_write(1,'5');
LCD_write(1,' '); /* ascii value for space */
LCD_write(1,'A');
big_delay();

value = 0;
vald = 0;
while (!flag) /* while loop for 25A or down*/
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(1); /** scan for down key*/
if ((value == 0) || (vald == 0)) /* if stat for 25A or down key starts */
{

if (value == 0)
{
rnge =25;
goto lab_resolution;
} /* if stat for 25A enter ends */

if ( vald == 0)
{
lab_75A: LCD_init();
LCD_write(1,'7');
LCD_write(1,'5');
LCD_write(1,' '); /* ascii value for space */
LCD_write(1,'A');
big_delay();

value = 0;
vald = 0;
valup = 0;

while (!flag) /* while loop for 75A or down or up starts */
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(1); /** scan for down key*/
valup = keyscan(2); /* scan for up key*/
if ((value == 0) || (vald == 0) || (valup == 0)) /* if stat for 75A 3 keys scan starts */
{

if (value == 0) /* if stat for 75A enter starts */
{
rnge =75;
goto lab_resolution;
} /* if stat for 75A enter ends */

if ( vald == 0) /* if stat for 75A down key (100A) ends */
{
lab_100A: LCD_init();
LCD_write(1,'1');
LCD_write(1,'0');
LCD_write(1,'0');
LCD_write(1,' '); /* ascii value for space */
LCD_write(1,'A');
big_delay();

value = 0;
valup = 0;

while (!flag) /* while loop for 100A or up key starts */
{
value = keyscanenter(); /* scan for enter key */
valup = keyscan(2); /* scan for up key*/
if ((value == 0) || (valup == 0)) /* if stat for 100A or up key scan starts */
{

if (value == 0) /* if stat for 100A enter starts */
{
rnge =100;
goto lab_resolution;
} /* if stat for 100A enter ends */

flag = 1;
} /* if stat for 100A (enter or up key) scan ends */
} /* while loop for 100A or up key ends */
} /* if stat 75A down key (100 A) ends */

if ( valup == 0)
{
goto lab_25A;
} /* if stat for 75 amps up key ends */
flag = 1;
} /* if stat for 3 keys scan end */
} /* while loop for 75A or down key or up key ends */

} /* if stat 75 A (25 amps down) ends */
flag = 1;
} /* if stat for 25A or down key ends */
} /* while loop for 25A or down key ends */
} /* if stat for (range or resolution) enter key ends */

if (vald == 0) /* if stat for (range or resolution) down key starts */
{
lab_resolution: resolution();
} /* if stat for (range or resolution) down key ends */
flag = 1;
} /* if for 2 keys (range or resolution selection) ends */
} /* while for 2 keys (range or down(resolution) key) ends */
} /* range prog ends */



/*********** function for loading the range of metyer (value of shunt) ***/


/************************ function for choosing the resolution *************************/
void resolution()
{
LCD_init();
LCD_write(1,'R');
LCD_write(1,'E');
LCD_write(1,'S');
LCD_write(1,'0');
LCD_write(1,'L');
LCD_write(1,'U');
LCD_write(1,'T');
LCD_write(1,'I');
LCD_write(1,'0');
LCD_write(1,'N');
big_delay();
value = 0;
vald = 0;
flag = 0;
while (!flag) /* while for resolution selection enter or up key or down key starts */
{
value = keyscanenter();
vald = keyscan(1); /** scan for down (previous value) key */
valup = kayscan(2); /* scan for up (range) key */
if ((value == 0) || (vald == 0)|| (valup == 0)))
{

if (value == 0) /* if stat for ( resolution or down or up) enter key starts */
{
0.1AH: LCD_init();
LCD_write(1,'R');
LCD_write(1,'E');
LCD_write(1,'S');
LCD_write(1,'54'); /* ascii value for space (32) */
LCD_write(1,'0');
LCD_write(1,'46'); /* ascii value for decimal point(46) */
LCD_write(1,'1');
LCD_write(1,'A');
LCD_write(1,'H');
big_delay();
value = 0;
vald = 0;
while (!flag) /* while loop for 0.1Ah or down key scan starts */
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(1); /** scan for down key*/
if ((value == 0) || (vald == 0)) /* if stat for 2 keys (0.1Ah or down key) starts */
{
if ( value == 0)
{
res = 0.1;
goto lab_previousvalue;
} /* if stat for 0.1 AH enter key ends */
if ( vald == 0) /* if stat for 0.1ah down key( 0.01AH) starts */
{
0.01AH: LCD_init();
LCD_write(1,'R');
LCD_write(1,'E');
LCD_write(1,'S');
LCD_write(1,'32'); /* ascii value for space point(32) */
LCD_write(1,'0');
LCD_write(1,'46'); /* ascii value for decimal point (46)*/
LCD_write(1,'0');
LCD_write(1,'1');
LCD_write(1,'A');
LCD_write(1,'H');
big_delay();
value = 0;
vald = 0;
valup = 0;
while (!flag) /* while loop for 3 keys (0.01Ah or down key or up key) scan starts */
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(1); /** scan for down key*/
vald = keyscan(2); /** scan for up key*/
if ((value == 0) || (vald == 0) || (valup == 0)) /* if stat for 3 keys (0.01Ah or down key or up key) scan starts */
{

if ( value == 0)
{
res = 0.01;
goto lab_previousvalue;
} /* if stat for 0.01 AH enter key ends */
if ( vald == 0)
{
0.001AH: LCD_init();
LCD_write(1,'R');
LCD_write(1,'E');
LCD_write(1,'S');
LCD_write(1,'32'); /* ascii value for space (32) */
LCD_write(1,'0');
LCD_write(1,'46'); /* ascii value for space (46) */
LCD_write(1,'0');
LCD_write(1,'0');
LCD_write(1,'1');
LCD_write(1,'A');
LCD_write(1,'H');
big_delay();
value = 0;
valup = 0;
while (!flag) /* while loop for 2 keys (0.001Ah or up key) scan starts */
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(2); /** scan for up key*/
if ((value == 0) || (valup == 0)) /* if stat for 2 keys (0.01Ah or up key) scan starts */
{

if ( value == 0)
{
res = 0.001;
goto lab_previousvalue;
} /* if stat for 0.001 AH enter key ends */
if ( valup == 0)
{
goto lab_0.01AH;
} /* if stat for 0.001 AH up key ends */
flag =1;
} /* if stat for 2 keys ( 0.001AH(enter) or up key scan ends */
}/* while loop for 2 keys ( 0.001 AH (enter) or up key( 0.01AH) ends */
} /*if stat for down key from 0.01AH (0.001AH) ends */
flag =1;
} /* if stat for 3 keys (0.01Ah or up or down key) scan ends */
} /* whele loop for 3 keys (0.01AH or up or down) keys ends */
} /* if stat for 0.1AH down key */
flag = 1;
} /* if stat for 0.1ah or down key check */
} /* while loop for 0.1ah or down key scan ends */
} /* if stat for (resolution or down or up) enter key ends */

if (vald == 0) /* if statment for (resolution or down or up) down key (previous value) starts */
{
lab_previousvalue: pre_value();
} /* if statment for (resolution or down or up) down key ends */

if (vald == 0) /* if statment for (resolution or down or up) up key starts */
{
goto lab_range;
} /* if statment for (resolution or down or up) up key ends */

flag = 1;
} /* if stat for 3 keys (resolution or down or up key) ends */
} /* while loop for 3 keys (resolution or up or down key scan) ends */

} /* resolution function ends */

/************* function for choosing the resolution ends ***********/

/******************** exit function **********************/
/* exit function to start the ahmeter actual running mode ********/
void exit()
{
LCD_init();
LCD_write(1,'E');
LCD_write(1,'X');
LCD_write(1,'I');
LCD_write(1,'T');
value = 0;
valup = 0;
flag = 0;
while (!flag)
{
if ((value == 0) || (valup == 0)) /* if stat for 2 keys (exit(enter) or up key) scan starts */
{
if (value == 0)
{
timer_counter();
/************************************/
} /* if stat for exit (enter) ends */
if (valup == 0)
{
goto lab_previousvalue;
} /* if stat for (exit or up) up ends */
flag = 1;
} /* if stat for exit (enter) or up key scan check ends */
} /* while loop for exit function(enter) or up key scan ends */


} /* exit function ends */


/***************** exit function ends *************************


/***************function for displaying previous value **************/


void pre_value()
{
float fi_ah;
value = 0;
vald = 0;
valup = 0;
flag = 0;
while(!flag) /* while loop for previous value ( enter or up or down key) scan ends */
{
value = keyscanenter(); /* scan for enter key */
vald = keyscan(1); /** scan for down key*/
vald = keyscan(2); /** scan for up key*/
if ((value == 0) || (valup == 0)|| (vald == 0)) /* if stat for 3 keys (pre_value enter or down or up key) scan starts */
{
if (value ==0)
{
fi_ah = mem_ah;
big_delay();
LCD_init();
LCD_write(1,''); /************************/
LCD_write(1,''); /************************/
LCD_write(1,''); /************************/
} /* if stat for (pre_value or down or up) enter ends */

if (vald == 0) /* if stat for (pre_value or down or up) down key starts */
{
lab_exit: exit();
} /* if stat for (pre_value or down or up) down key ends */

if ( valup == 0) /* if stat for (pre_value or down or up) up key starts */

{
goto lab_resolution;
} /* if stat for (pre_value or down or up) up key ends */

flag =1;
} /* if stat for 3 keys (pre_value enter or down or up key) scan starts */
} /* while loop for previous value ( enter or up or down key) scan ends */
} /* pre_value function ends */


/**************************************************************/
void big_delay(void)
{
unsigned int a;
a = 50000;
while(a)
a--;
}

void small_delay(void)
{
unsigned int b;
b = 250;
while(b)
b--;
}

/*****************storing ah vlue in eeprom after every 30 seconds ************************/

void write_to_eprom(void)
{

unsigned char chk_rdybsy;

//enable eprom writing
EEMEN_ = 1;
EEMWE_ = 0;
mem_ah = ahfinal; //write AH into eeprom
small_delay();
//see whether eprom writing is over
chk_once_again:
chk_rdybsy = WMCON;
chk_rdybsy &= 0x02;
if(chk_rdybsy == 0)
goto chk_once_again;
//disable further writing into eprom
EEMWE_ = 0;
}


/************* actual ah calculation and display (running mode)*****************/

void timer_counter(void)
{
unsigned short int count = 0x0000;
unsigned float ah = 0.0000;
unsigned char eecount = 0 ; /* for counting number of number of iterations( writing to eeprom ) */
while(1)
{
TMOD &= 0x0F; /* Clear all T1 bits (T0 left unchanged) */
TMOD |= 0x50; /* Set required T1 bits TMOD=0101 (T0 left unchanged) */
TR1 = 1;
DELAY_HARDWARE_One_Second();
count |= TH1;
count <<= 8;
count |= TL1;
ah = ((count * rnge)/(res * 3600 * 1000));
ahfinal = ah + ahfinal;
eeecount ++;
if (eecount == 30)
{
ecount = 0;
write_to_eprom(void);
}


}
}
/*-------------------------------------------------------------*-
DELAY_HARDWARE_One_Second()
Hardware delay of 1000 ms.
*** Assumes 12MHz (12 osc cycles) ***
-*-------------------------------------------------------------*/
void DELAY_HARDWARE_One_Second()
{
unsigned char d;

/* Call DELAY_HARDWARE_50ms() twenty times */

flag = 0;
for (d = 0; d < 20; d++)
{
DELAY_HARDWARE_50ms();
}
}
/*-------------------------------------------------------------*-
DELAY_HARDWARE_50ms()
*** Assumes 12MHz (12 osc cycles) ***
-*-------------------------------------------------------------*/
void DELAY_HARDWARE_50ms()
{
/* Configure Timer 0 as a 16-bit timer */
TMOD &= 0xF0; /* Clear all T0 bits (T1 left unchanged) */
TMOD |= 0x01; /* Set required T0 bits (T1 left unchanged) */

/* Values for 50 ms delay */
TH0 = 0x3C; /* Timer 0 initial value (High Byte) */
TL0 = 0xB0; /* Timer 0 initial value (Low Byte) */

TF0 = 0; /* Clear overflow flag */
ET0 = 1;
EA = 1;
TR0 = 1; /* Start timer 0 */

while(!flag);
flag = 0;

}


void Timer0_ISR(void) interrupt 1
{
TR0 = 0;
flag = 1;
}





/*********************** keyscan function *************************************/
char keyscan(unsigned char pin)
{
unsigned char p = 0x01; /* 00000001 */
/* Left shift appropriate number of places */
p <<= pin;
/* Write a 1 to the pin (to set up for reading) */
P1| = p; /* set pin p as input port or say for reading*/
/* Read the pin (bitwise AND) and return */
return (P1 & p);
}

/***************************keyscan enter function starts ********/
char keyscanenter()
{
unsigned char p = 0x04; /* pin 1_3 of port 1 for enter ::: 00001000 */
/* Write a 1 to the pin (to set up for reading) */
P1| = p; /* set pin p as input port or say for reading*/
/* Read the pin (bitwise AND) and return */
return (P1 & p);
}



/*** please help me out soon ***/






List of 4 messages in thread
TopicAuthorDate
Digital amp-hour meter is having errors            01/01/70 00:00      
   The compiler has told you the problem            01/01/70 00:00      
   Look and ye shall find!            01/01/70 00:00      
   get used to it, C does rarely post the e            01/01/70 00:00      

Back to Subject List