EN0
Member
Hi,
I'm creating a delay function that offers the capability of having the timing configuration in milli-seconds or seconds. See the code below (C18 compiler):
When I build the program it says that this line gives me a syntax error:
This is presumably due to the "char degree = 'm'", but I'm wondering why that is so? I'm more familiar with PHP, and in that particular language, this makes it easy to assign a default value; if no value is entered in the second parameter when the function is called, it defaults to 'm'.
I'm hoping this is possible somehow in C?
Thanks,
Austin
I'm creating a delay function that offers the capability of having the timing configuration in milli-seconds or seconds. See the code below (C18 compiler):
Code:
void delay(int delay, char degree = 'm')
{
int cntr;
if(degree == 'm' || degree == 'M')
{
// Our timing configuration is in milli-seconds
OVF = 0;
T3CON |= 0x80; // 16-bit configuration set
for(cntr = 0; cntr < delay; cntr++)
{
// Load TMR3H and TMR3L bytes
TMR3H = (63536 >> 8) & 0xFF; // Load TMR3H byte first
TMR3L = 63536 & 0xFF; // Load TMR3L byte next
while(!OVF); // Wait for timer to complete transaction
OVF = 0;
}
}
else if(degree == 's' || degree == 'S')
{
// Our timing configuration is in seconds
OVF = 0;
T3CON |= 0x80; // 16-bit configuration set
for(cntr = 0; cntr < (delay * 2); cntr++)
{
// Load TMR3H and TMR3L bytes
TMR3H = (64536 >> 8) & 0xFF; // Load TMR3H byte first
TMR3L = 64536 & 0xFF; // Load TMR3L byte next
while(!OVF); // Wait for timer to complete transaction
OVF = 0;
}
}
}
When I build the program it says that this line gives me a syntax error:
Code:
void delay(int delay, char degree = 'm')
This is presumably due to the "char degree = 'm'", but I'm wondering why that is so? I'm more familiar with PHP, and in that particular language, this makes it easy to assign a default value; if no value is entered in the second parameter when the function is called, it defaults to 'm'.
I'm hoping this is possible somehow in C?
Thanks,
Austin