recursive codes have an evaluating condition that is checked for exiting the loop, this procedure does not have that and yet it works , iam trying to understand how .
this procedure is calling it self and not checking for any conditions so how come its not getting in infinite loop?
void writeByteToLCD(uint8_t selectedRegister, uint8_t byte)
{
//split the byte into high and low nibble to be sent in 4 bit mode
uint8_t upperNibble = byte >> 4;
uint8_t lowerNibble = byte & 0x0f;
//Assuming a 4 line by 20 character display, ensure that
//everything goes where it is supposed to go:
if(selectedRegister == DATA_REGISTER && position == 20)
{
writeByteToLCD(COMMAND_REGISTER, 0xC0); //0xC0= 1<1000000> table-6 set DDRAM address
_delay_us(50);
}
elseif(selectedRegister == DATA_REGISTER && position == 40)
{
writeByteToLCD(COMMAND_REGISTER, 0x94); //0x94= 1<0010100>
_delay_us(50);
}
elseif(selectedRegister == DATA_REGISTER && position == 60)
{
writeByteToLCD(COMMAND_REGISTER, 0xd4); //0xd4 = 1<1010100>
_delay_us(50);
}
//Wait for the LCD to become ready
waitForLCD();
//First, write the upper four bits to the LCD
writeNibbleToLCD(selectedRegister, upperNibble);
//Finally, write the lower four bits to the LCD
writeNibbleToLCD(selectedRegister, lowerNibble);
//Reset the position count if it is equal to 80
if(selectedRegister == DATA_REGISTER && ++position == 80)
position = 0;
}
so how does it work , it will call it self only once? in normal C++ it will surely get into a loop and keep calling it self till some condition forces it out of the loop