MikroElektronika PIC Microcontrollers PIC18 Manuale Utente Pagina 36

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 40
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 35
Filter 3 for buffer 2 is set to value 3 so that identifiers having values 3 are accepted by
the receive buffer.
The operation mode is then set to NORMAL. The program then configures the LCD
and displays the message “CAN BUS” for one second on the LCD.
The main program loop executes continuously and starts with a for statement. Inside
this loop the LCD is cleared and text “TEMP ¼ is displayed on the LCD. Then
character “T” is sent over the bus with the identifier equal to 500 (the COLLECTOR
/
/
/
/ Configure LCD
/
/
Lcd_Config(&PORTC,4,5,0,3,2,1,0); // LCD is connected to PORTC
Lcd_Cmd(LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"CAN BUS"); // Display heading on LCD
Delay_ms(1000); // Wait for 2 seconds
/
/
/
/ Program loop. Read the temperature from Node:COLLECTOR and display
/
/ on the LCD continuously
/
/
for(;;) // Endless loop
{
Lcd_Cmd(LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"Temp = "); // Display "Temp = "
//
// Send a message to Node:COLLECTOR and ask for data
//
data[0] = 'T'; // Data to be sent
id = 500; // Identifier
CANWrite(id, data, 1, send_flag); // send 'T'
//
// Get temperature from node:COLLECT
//
dt = 0;
while(!dt)dt = CANRead(&id, data, &len, &read_flag);
if(id == 3)
{
temperature = data[0];
ByteToStr(temperature,txt); // Convert to string
Lcd_Out(1,8,txt); // Output to LCD
Delay_ms(1000); // Wait 1 second
}
}
}
Figure 9.17: (Cont’d)
www.newnespress.com
510 Chapter 9
Vedere la pagina 35
1 2 ... 31 32 33 34 35 36 37 38 39 40

Commenti su questo manuale

Nessun commento