MikroElektronika PIC Microcontrollers PIC18 Manual de usuario Pagina 37

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 40
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 36
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
CAN BUS EXAMPLE - NODE: COLLECTOR
=================================
This is the COLLECTOR node of the CAN bus example. In this project a
PIC18F258 type microcontroller is used. An MCP2551 type CAN bus transceiver
is used to connect the microcontroller to the CAN bus. The microcontroller is
operated from an 8MHz crystal with an external reset button.
Pin CANRX and CANTX of the microcontroller are connected to pins RXD
and TXD of the transceiver chip respectively. Pins CANH and CANL of the
transceiver chip are connected to the CAN bus.
An LM35DZ type analog temperature sensor is connected to port AN0 of the
microcontroller. The microcontroller reads the temperature when a request is
received and then sends the temperature value as a byte to Node:DISPLAY on
the CAN bus.
CAN speed parameters are:
Microcontroller clock: 8MHz
CAN Bus bit rate: 100Kb/s
Sync_Seg: 1
Prop_Seg: 6
Phase_Seg1: 6
Phase_Seg2: 7
SJW: 1
BRP: 1
Sample point: 65%
Author: Dogan Ibrahim
Date: October 2007
File: COLLECTOR.C
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
/
void main()
{
unsigned char temperature, data[8];
unsigned short init_flag, send_flag, dt, len, read_flag;
char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, txt[4];
unsigned int temp;
unsigned long mV;
long id, mask;
TRISA = 0xFF; // PORTA are inputs
TRISB = 0x08; // RB2 is output, RB3 is input
/
/
/
/ Configure A/D converter
/
/
ADCON1 = 0x80;
Figure 9.18: COLLECTOR program listing
(Continued)
www.newnespress.com
511Advanced PIC18 Projects—CAN Bus Projects
Vista de pagina 36
1 2 ... 32 33 34 35 36 37 38 39 40

Comentarios a estos manuales

Sin comentarios