MikroElektronika PIC Microcontrollers PIC18 Instrukcja Użytkownika Strona 39

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 40
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 38
// Program loop. Read the temperature from analog temperature
// sensor
//
for(;;) // Endless loop
{
//
// Wait until a request is received
//
dt = 0;
while(!dt) dt = CANRead(&id, data, &len, &read_flag);
if(id == 500 && data[0] == 'T')
{
//
// Now read the temperature
//
temp = Adc_Read(0); // Read temp
mV = (unsigned long)temp
5000 / 1024; // in mV
temperature = mV/10; // in degrees C
//
// send the temperature to Node:Display
//
data[0] = temperature;
id = 3; // Identifier
CANWrite(id, data, 1, send_flag); // send temperature
}
}
}
Figure 9.18: (Cont’d)
Node: DISPLAY Node: COLLECTOR
Initialize CAN module Initialize CAN module
Set mode to CONFIG Set mode to CONFIG
Set Mask bits to 1’s Set Mask bits to 1’s
Set Filter value to 3 Set Filter value to 500
Set mode to NORMAL Set mode to NORMAL
DO FOREVER DO FOREVER
Send character “T” with identifier 500 Read a character
Read temperature with identifier 3 IF character is “T”
Convert temperature to string Read temperature
Display temperature on LCD Convert to digital
Wait 1 second Convert to ºC
ENDDO Send with identifier 3
ENDIF
ENDDO
Figure 9.19: Operation of both nodes
www.newnespress.com
513Advanced PIC18 Projects—CAN Bus Projects
Przeglądanie stron 38
1 2 ... 34 35 36 37 38 39 40

Komentarze do niniejszej Instrukcji

Brak uwag