program TX_RX_CAN_500Kbs
include "logo"
dim Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags, MSG_RCVD, RX_DATA_LEN, X as word
Tx_Data as byte[8]
Rx_Data as byte[8]
txt as string[3]
Rx_ID, Tx_ID as longint
main:
ADPCFG = $FFFF
Can_Init_Flags = 0
Can_Send_Flags = 0
Can_Rcv_Flags = 0
Can_Send_Flags = CAN_TX_PRIORITY_1 and ' SE UTILIZA PARA
CAN_TX_STD_FRAME and ' CANSendMessage
CAN_TX_RTR_FRAME
Can_Init_Flags = CAN_CONFIG_SAMPLE_THRICE and ' SE ULILIZA PARA
CAN_CONFIG_PHSEG2_PRG_ON and ' CANInitialize
CAN_CONFIG_XTD_MSG and
CAN_CONFIG_DBL_BUFFER_ON and
CAN_CONFIG_ALL_VALID_MSG and
CAN_CONFIG_LINE_FILTER_OFF
CAN1Initialize(1,2,4,4,1,Can_Init_Flags) ' configurado a 500kbs con oscilador
'de 20 MHz
CAN1SetOperationMode(CAN_MODE_NORMAL, 0x00) ' set CONFIGURATION mode
CAN1SetMask(CAN_MASK_B1, -1, CAN_CONFIG_MATCH_MSG_TYPE and CAN_CONFIG_STD_MSG) ' set all mask1 bits to ones
CAN1SetMask(CAN_MASK_B2, -1, CAN_CONFIG_MATCH_MSG_TYPE and CAN_CONFIG_STD_MSG) ' set all mask2 bits to ones
CAN1SetFilter(CAN_FILTER_B1_F1, 5,CAN_CONFIG_STD_MSG) ' set id of filter B2_F3 to 3
CAN1SetOperationMode(CAN_MODE_NORMAL, 0x00) ' modo Normal ENVIA Y RECIBE
' -----------------configuracion del glcd 128x64
Glcd_Init(PORTC,13,PORTC,14,PORTE,8,PORTD,1,PORTB,8,PORTD,3,PORTB) 'conf d puertos
delay_ms(2000)
Glcd_Fill(0x00) ' Limpiar pantalla
Glcd_Image(LOGOTIPO_bmp) 'dibujar imagen
Delay_MS(5000)
Uart2_Init(9600) 'INICIALIZAMOS RS232
Glcd_Fill(0x00) ' Limpiar pantalla
MOSTAR:
while TRUE
Tx_ID=$100
Tx_Data[0] = $EC
Tx_Data[1] = $04
Tx_Data[2] = $00
Tx_Data[3] = $00
Tx_Data[4] = $00
Tx_Data[5] = $A9
Tx_Data[6] = $0B
Tx_Data[7] = $6a
CAN1Write(Tx_ID, Tx_Data, 8, Can_Send_Flags) ' envio los datos
Tx_ID=$500
Tx_Data[0] = $5E
Tx_Data[1] = $00
Tx_Data[2] = $F8
Tx_Data[3] = $02
Tx_Data[4] = $D2
Tx_Data[5] = $02
Tx_Data[6] = $26
Tx_Data[7] = $02
CAN1Write(Tx_ID, Tx_Data, 8, Can_Send_Flags) ' envio los datos
FOR X=0 TO 100
DELAY_MS(1) 'PAUSA ENTRE ENVIO RECEPCION
NEXT X
Msg_Rcvd = CAN1Read(Rx_ID , Rx_Data , Rx_Data_Len, Can_Rcv_Flags)
IF Rx_ID=$112 THEN
Uart2_Write_TEXT ("112")
Glcd_Set_Font(@System3x6, 3, 6, 32)
Glcd_Write_TEXT("RX_ID=112 DLC=", 3, 0, 2)
ByteToStr(Rx_Data_LEN, txt)
Glcd_Write_TEXT(TXT, 63, 0, 2)
ByteToStr(Rx_Data[0], txt)
Glcd_Write_TEXT(TXT, 3, 1, 0)
ByteToStr(Rx_Data[1], txt)
Glcd_Write_TEXT(TXT, 18, 1, 0)
ByteToStr(Rx_Data[2], txt)
Glcd_Write_TEXT(TXT, 33, 1, 0)
ByteToStr(Rx_Data[3], txt)
Glcd_Write_TEXT(TXT, 48, 1, 0)
ByteToStr(Rx_Data[4], txt)
Glcd_Write_TEXT(TXT, 63, 1, 0)
ByteToStr(Rx_Data[5], txt)
Glcd_Write_TEXT(TXT, 78, 1, 0)
ByteToStr(Rx_Data[6], txt)
Glcd_Write_TEXT(TXT, 93, 1, 0)
ByteToStr(Rx_Data[7], txt)
Glcd_Write_TEXT(TXT, 108, 1, 0)
END IF
IF Rx_ID=$512 THEN
Uart2_Write_TEXT ("512")
Glcd_Set_Font(@System3x6, 3, 6, 32)
Glcd_Write_TEXT("RX_ID=512 DLC=", 3, 2, 2)
ByteToStr(Rx_Data_LEN, txt)
Glcd_Write_TEXT(TXT, 63, 2, 2)
ByteToStr(Rx_Data[0], txt)
Glcd_Write_TEXT(TXT, 3, 3, 0)
ByteToStr(Rx_Data[1], txt)
Glcd_Write_TEXT(TXT, 18, 3, 0)
ByteToStr(Rx_Data[2], txt)
Glcd_Write_TEXT(TXT, 33, 3, 0)
ByteToStr(Rx_Data[3], txt)
Glcd_Write_TEXT(TXT, 48, 3, 0)
ByteToStr(Rx_Data[4], txt)
Glcd_Write_TEXT(TXT, 63, 3, 0)
ByteToStr(Rx_Data[5], txt)
Glcd_Write_TEXT(TXT, 78, 3, 0)
ByteToStr(Rx_Data[6], txt)
Glcd_Write_TEXT(TXT, 93, 3, 0)
ByteToStr(Rx_Data[7], txt)
Glcd_Write_TEXT(TXT, 108, 3, 0)
END IF
IF Rx_ID=$712 THEN
Uart2_Write_TEXT ("700")
Glcd_Set_Font(@System3x6, 3, 6, 32)
Glcd_Write_TEXT("RX_ID=700 DLC=", 3, 4, 2)
ByteToStr(Rx_Data_LEN, txt)
Glcd_Write_TEXT(TXT, 63, 4, 2)
ByteToStr(Rx_Data[0], txt)
Glcd_Write_TEXT(TXT, 3, 5, 0)
ByteToStr(Rx_Data[1], txt)
Glcd_Write_TEXT(TXT, 18, 5, 0)
ByteToStr(Rx_Data[2], txt)
Glcd_Write_TEXT(TXT, 33, 5, 0)
ByteToStr(Rx_Data[3], txt)
Glcd_Write_TEXT(TXT, 48, 5, 0)
ByteToStr(Rx_Data[4], txt)
Glcd_Write_TEXT(TXT, 63, 5, 0)
ByteToStr(Rx_Data[5], txt)
Glcd_Write_TEXT(TXT, 78, 5, 0)
ByteToStr(Rx_Data[6], txt)
Glcd_Write_TEXT(TXT, 93, 5, 0)
ByteToStr(Rx_Data[7], txt)
Glcd_Write_TEXT(TXT, 108, 5, 0)
END IF
wend
GOTO MOSTRAR
end.