Slave Code
Slave Code
h>
#define _XTAL_FREQ 12000000
/*********************Definition of Ports********************************/
/****************************Functions********************************/
void LCD_Init()
{
LCD_Port = 0; /*PORT as Output Port*/
__delay_ms(15); /*15ms,16x2 LCD Power on delay*/
LCD_Command(0x02); /*send for initialization of LCD
for nibble (4-bit) mode */
LCD_Command(0x28); /*use 2 line and
initialize 5*8 matrix in (4-bit mode)*/
LCD_Command(0x01); /*clear display screen*/
LCD_Command(0x0c); /*display on cursor off*/
LCD_Command(0x06); /*increment cursor (shift cursor to right)*/
}
char SPI_Read()
{
while ( !SSPSTATbits.BF );
return(SSPBUF);
}
unsigned SPI_Ready2Read()
{
if (SSPSTAT & 0b00000001)
return 1;
else
return 0;
}
int main(void)
{
LCD_Init();
LCD_Command(0x81);
LCD_String("HUME:");
LCD_Command(0xC1);
LCD_String("TEMP:");
TRISC2 = 1;
TRISC3 = 1;
TRISC4 = 1;
TRISC5 = 0;
SSPSTAT = 0b00000000;
SSPCON = 0b00100101;
__delay_ms(50);
while(1)
{
if (SPI_Ready2Read())
{
DATA = SPI_Read();
if (i<5)
{
LCD_Command(0x87+i);
LCD_Char(DATA);
}
if (i<10 && i>4)
{
LCD_Command(0xC7+y);
LCD_Char(DATA);
y = y+1;
}
i=i+1;
if (i == 10)
{
y = 0;
i = 0;
}
}
}