Hardware Reference
In-Depth Information
Solution:
The C program that performs the desired operation is as follows:
#include “c:\iccv712\include\hcs12.h”
#include “c:\iccv712\include\delay.h”
#include “c:\iccv712\include\lcd_util.h”
char *msg1
5
“Sent: “;
char *msg2
5
“Received: “;
void RxISR(void);
void openAD0(void);
void OpenCan1(void);
void MakeBuf(char *pt1, char *pt2);
void snd2can1(char *ptr);
int main(void)
{
char buffer[6];
/* to hold measured voltage */
char buf[16];
/* transmit data buffer */
int temp;
asm(
“ldd #_RxISR”
);
// pass the interrupt vector of CAN1Rx interrupt
asm(
“pshd”
);
//
“
asm(
“ldd #21”
);
// place the vector number of CAN1Rx in D
asm(
“ldx $EEA4”
);
asm(
“jsr 0,X”
);
openLCD();
/* configure LCD kit */
OpenCan1();
/* configure CAN1 module */
buffer[1]
5
'.';
/* decimal point */
buffer[3]
5
0x20;
/* space character */
buffer[4]
5
'V';
/* volt character */
buffer[5]
5
0;
/* null character */
openAD0();
/* configure AD0 module */
CAN1RIER
5
0x01;
/* enable RXF interrupt only */
asm(“cli”);
/* enable interrupt globally */
while(1) {
ATD0CTL5
5
0x87;
/* convert AN7, result right-justified */
while(!(ATD0STAT0 & SCF));
/* wait for conversion to complete */
buffer[0]
5
0x30
1
(ATD0DR0*10)/2046;
/* integral digit of voltage */
temp
5
(ATD0DR0 * 10) % 2046;
/* find the remainder */
buffer[2]
5
0x30
1
(temp * 10)/2046;
/* compute the fractional digit */
MakeBuf(&buf[0],&buffer[0]);
/* format data for transmission */
snd2can1(&buf[0]);
/* send out voltage on CAN bus */
cmd2LCD(0x80);
/* set LCD cursor to first row */
putsLCD(msg1);
/* output the message “sent: x.y V” */
putsLCD(&buffer[0]);
/* “ */
delayby100ms(2);
/* wait for messages to arrive for 0.2 s */
}
return 0;
}
/****************************************************************************/
/* The following function formats a buffer into the structure of a CAN transmit buffer so */
/* that it can be copied into any empty transmit buffer for transmission. */
/****************************************************************************/
Search WWH ::
Custom Search