:) Ok also
ich nutze den Pic18f4580 mit mcp2551.
hier ist mein Code:
#include <18F4580.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include "can-18F4580.c"
#include "lcd_benim.c"
#define S1 0x7DF
#define CAN_USE_EXTENDED_ID False
#define Button pin_c0
int time, time1;
int32 rx_id;
int z=0, rx_len,i;
struct rx_stat stat;
int receive[8];
unsigned char A1[8]={0x02,0x01,0x0C,0x00,0x00,0x00,0x00,0x00};
int16 A1_rpm;
#int_canrx0
void canrx0_int ()
{
lcd_gotoxy(1,4);
printf(lcd_putc,"canbus ");
can_getd(rx_id,receive,rx_len,stat);
if(receive[2] == 0x0C)
{
A1_rpm=((receive[3]*256)+receive[4])/4;
lcd_gotoxy(1,3);
printf(lcd_putc,"S1: %Li rpm",A1_rpm);
}
}
void main()
{
set_tris_c(0x03);
lcd_init();
delay_ms(200);
can_init();
can_set_functional_mode(1); // mode 1
can_set_id(RX0MASK,0xFFF,FALSE);
can_set_id(RXFILTER0,0x7E8,FALSE);
can_set_id(RXFILTER1,0x7E8,FALSE);
can_set_id(RXFILTER2,0x7E8,FALSE);
can_set_id(RXFILTER3,0x7E8,FALSE);
can_set_id(RXFILTER4,0x7E8,FALSE);
can_set_id(RXFILTER5,0x7E8,FALSE);
can_set_id(RXFILTER6,0x7E8,FALSE);
can_set_id(RXFILTER7,0x7E8,FALSE);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F0BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F1BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F2BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F3BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F4BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F5BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F6BP);
can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F7BP);
can_associate_filter_to_buffer(ARXB0, F0BP);
can_associate_filter_to_buffer(ARXB1, F1BP);
can_associate_filter_to_buffer(AB0, F2BP);
can_associate_filter_to_buffer(AB1, F3BP);
can_associate_filter_to_buffer(AB2, F4BP);
can_associate_filter_to_buffer(AB3, F5BP);
can_associate_filter_to_buffer(AB4, F6BP);
can_associate_filter_to_buffer(AB5, F7BP);
enable_interrupts(int_canrx0);
enable_interrupts(GLOBAL);
delay_ms(500);
time = 100;
While(TRUE)
{
can_putd(S1,A1, 8, 1, False, FALSE);
}
}