Hardware Reference
In-Depth Information
void MakeBuf(char *pt1, char *pt2)
{
char i;
*pt1 5 'V'; /* set V1 as the transmit identifier */
*(pt1 1 1) 5 0x3C; /* " */
*(pt1 1 2) 5 0x40; /* “ */
*(pt1 1 3) 5 0; /* “ */
for(i 5 4; i < 9; i 11 ) /* copy voltage data */
*(pt1 1 i) 5 *(pt2 1 i 2 4);
*(pt1 1 12) 5 5;
/* set data length to 5 */
}
/************************************************************************/
/* The following function handles the RXF interrupt. It checks if the RXF */
/* is set. If not, return. It also ignores the RTR request. */
/************************************************************************/
#pragma interrupt_handler RxISR
void RxISR (void)
{
char tmp,i,*ptr;
if (!(CAN1RFLG & RXF))
/* interrupt not caused by RXF, return */
asm(“rti”)
CAN1RFLG 5 RXF;
/* clear RXF flag */
tmp 5 CAN1IDAC & 0x07;
/* extract filter hit info */
if (tmp 55 0){
/* filter 0 hit */
if (CAN1RDLR 55 0)
/* if data length is 0, do nothing */
asm(“rti”)
cmd2LCD(0xC0);
/* set LCD cursor to second row */
putsLCD(msg2);
/* output “received: “ */
ptr 5 (char *)&CAN1RDSR0;
/* ptr points to the first data byte */
for (i 5 0; i , CAN1RDLR; i 11 )
putcLCD(*ptr 11 );
/* output “x.y V” */
asm(“rti”)
}
else asm(“rti”)
/* other hit, do nothing */
}
void openAD0 (void)
{
int i;
ATD0CTL2 5 0xE0;
delayby10us(2);
ATD0CTL3 5 0x0A;
// perform one conversion
ATD0CTL4 5 0x25;
// 4 cycles sample time, prescaler set to 12
}
void OpenCan1(void)
{
CAN1CTL1 | 5 CANE;
// enable CAN, required after reset
CAN1CTL0 | 5 INITRQ;
// request to enter initialization mode
while(!(CAN1CTL1&INITAK));
// wait until initialization mode is entered
CAN1CTL1 5 0x84;
// enable CAN1, select oscillator as MSCAN clock
// source, enable wake-up filter
Search WWH ::




Custom Search