A Function prototype is a layout of what the function looks like. It lets the computer know what to expect as to the variable types that are being sent and returned from the function. You need to declare a function prototype before you call the function.
Here is an example of a function prototype I placed in a header file which is called by an INCLUDE at the top of the main C file.
// Function Declarations:
char send_byte(char myByte); //Send
And here is the funtion found in the main file:
//#pragma optimize=s 2 //no optimizatio
char send_byte(char mybyte)
{
char i; //Bit counter counts left shift 8 bits per byte
char databit; //current output bit shifted out of byte via SREG.C(arry)
char xor_rslt; //exclusive OR result
char prv_rslt; //previous result
//Process byte as long as timer doesn't over flow
//Timer overflow will scramble the output as OCR0A should have reset Timer
while(!(TIFR0 & (1<
{
for(i=0; i<8; i++) //shift through each bit in mybyte
{
TCCR0B = tmr_clk_1024; //Start timer with prescale /1024
prv_rslt = 0xff; //ensure previous result will be different
//
mybyte = (mybyte<<1); //Left shift databit to SREG carry flag
if(SREG & 0x01) //must test SREG Carry flag immeadiately after shift
{
databit = (1<
//of Timer Interrupt Flag B compare match to simplify XOR'ing
}
else
{
databit = 0x00; //bit == 0 will be XOR'ing a zero with the clock bit
}
//
while(!(TIFR0 & (1<
{
xor_rslt = (TIFR0 ^ databit); //exclusive OR CompB Flag with DATA
xor_rslt &= (1<
if (!(xor_rslt == prv_rslt)) //update ports once per state change
{
if(xor_rslt) //send XOR resuts to I/O pin
{
tx_1; //Set Transmit Pin =1
}
else
{
tx_0; //Set Transmit Pin =0
}
prv_rslt = xor_rslt;
}
////diagnostic output of clock sig on PB1
//if(TIFR0&(1<
//{
// tx_clk_1; //Set Transmit Pin =1
//}
//else
//{
// tx_clk_0; //Set Transmit Pin =0
//}
}
rst_tmr0_flags; //reset interrupt flags
}//NEXT i
return 1;//Successful
}//while not Timer over flow
return 0;//unsuccessful timer must be rinitialized to clear errors and resync
}