help me understand this code

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
	}
	else if(selectedRegister == DATA_REGISTER && position == 40)
	{
		writeByteToLCD(COMMAND_REGISTER, 0x94);    //0x94= 1<0010100> 
		_delay_us(50);
	}
	else if(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;
	
}
The function is not recursive, it just calls itself with different parameters that don't result in recursion.
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
The condition for calling itself is selectedRegister == DATA_REGISTER and in each case when it calls itself it passes COMMAND_REGISTER instead.
oh i see it now . .thanks a lot
Topic archived. No new replies allowed.