Specifications
October 25, 2006 Cypress Semiconductor – Rev. ** 53
LIN Bus 2.0 Reference Design 5. Demonstration Projects
// Start the ADC and Start Conversion
ADC_Start(ADC_MEDPOWER);
ADC_StartAD();
// Enable Global Interrupts
M8C_EnableGInt;
// Infinite loop
while(1)
{
// Read the LIN status
TransferStatus = (char)l_ifc_read_status();
// Check if Frame1 has been successfully received. If yes,
// update the LEDs with the data received.
if (BufferFrame1[0] & bfLAST_TRANSACTION_OK)
{
// Clear the Last Transaction Ok flag
BufferFrame1[0] &= ~bfLAST_TRANSACTION_OK;
// Read the Frame1 buffer into TempBuffer
l_bytes_rd(Frame1, 0, 9, TempBuffer);
// Clear the Last Transaction OK Flag
TempBuffer[0] &= ~bfLAST_TRANSACTION_OK;
// Update Status Byte in Frame1 Buffer
l_bytes_wr(Frame1, 0, 1, TempBuffer);
// Now check the data bytes and set or clear the
// corresponding bit in the bLED variable
bLED = 0;
for(i=0;i < 8 ; i++)
{
if(TempBuffer[i+1] == 0)
{
bLED = bLED | ((BYTE)0x01 << (7-i));
}
else
{
bLED = bLED & (~(0x01 << (7-i)));
}
}
// Update Port 1 with LED data
PRT1DR = bLED;
}
// Process Frame2. Call the CheckResistance function and update
// the Frame2 buffer with the measured resistance
Resistance = CheckResistance();
TempBuffer[0] = (BYTE)Resistance;
TempBuffer[1] = ((BYTE)(Resistance >> 8)) & 0x7F;
// Update the Frame2 buffer with the prepared data
l_bytes_wr(Frame2, 1, 2, TempBuffer);
// Now check the bResponseError variable. If this variable is a non-zero
// then set the Response Error bit in the 2nd data byte (MSB) of Frame2