?? can_task.c
字號:
/*C*****************************************************************************
* FILE_NAME : can_task.c
*----------------------------------------------------------------------------
* FILE_CREATED_BY : BERTHY JS
* FILE_CREATION_DATE: 4/05/00
*----------------------------------------------------------------------------
* FILE_PURPOSE:
*
******************************************************************************/
/*_____ I N C L U D E - F I L E S ____________________________________________*/
#include "stdio.h"
#include "config.h"
#include "lcd_drv.h"
/*_____ P R I V A T E - F U N C T I O N S - D E C L A R A T I O N ____________*/
#define BRP_100k 0x05
#define SJW_100k 0x00
#define PRS_100k 0x01
#define PHS1_100k 0x03
#define PHS2_100k 0x02
#define BRP_500k 0x00
#define SJW_500k 0x00
#define PRS_500k 0x02
#define PHS1_500k 0x03
#define PHS2_500k 0x03
/*_____ L O C A L S __________________________________________________________*/
can_data_t xdata data_200 = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
can_data_t data_rx= {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
code can_msg_t can_200 = {STD_ID(0x200), CONF_NOIDE | CONF_DLC_8, data_200};
can_msg_t rx_data = {0x00, 0x00, data_rx};
Uchar task_state = 0x00;
Uchar debounce_bp = 0x00;
/*_____ P U B L I C - F U N C T I O N S ______________________________________*/
Uchar dlc;
Uchar f_affichage =1;
Uchar line[2][17];
/*F**************************************************************************
* NAME: bin_to_ascii
*----------------------------------------------------------------------------
* PARAMS:
* to_convert: byte to parse in ascii
*----------------------------------------------------------------------------
* PURPOSE: This function return the ascii value
*****************************************************************************/
Uchar bin_to_ascii (Uchar to_convert)
{
Uchar convert;
if ((to_convert >= 0) &&
(to_convert <= 9) )
{
convert = to_convert + 0x30;
}
else
{
convert = to_convert + 0x37;
}
return (convert);
}
/*_____ P R I V A T E - F U N C T I O N S ____________________________________*/
/*F**************************************************************************
* FUNCTION_NAME: can_task_init
*-------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE : 4/05/00
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: void
******************************************************************************/
void can_task_init(void)
{
CAN_CONTROLLER_RESET;
CAN_IT_DISABLE;
CANTIM_IT_DISABLE;
RazAllMailbox();
CanSetBRP(BRP_500k);
CanSetSJW(SJW_500k);
CanSetPRS(PRS_500k);
CanSetPHS1(PHS1_500k);
CanSetPHS2(PHS2_500k);
CAN_CONTROLLER_ENABLE;
can_rx_filt.ext = 0x00;
can_rx_msk.ext = 0x00;
conf_rx = CONF_NOIDE|CONF_NOMSK_IDE|CONF_NOBUFFER;
CAN_SET_CHANNEL(CHANNEL_0);
CAN_CHANNEL_IT_ENABLE(CHANNEL_0);
ConfChannel_Rx();
CAN_IT_ENABLE;
CAN_TX_IT_ENABLE;
CAN_RX_IT_ENABLE
task_state = 0x00;
line[0][0] = 'A';
line[0][1] = 'T';
line[0][2] = 'M';
line[0][3] = 'E';
line[0][4] = 'L';
line[0][5] = ' ';
line[0][6] = 'W';
line[0][7] = 'i';
line[0][8] = 'r';
line[0][9] = 'e';
line[0][10] = 'l';
line[0][11] = 'e';
line[0][12] = 's';
line[0][13] = 's';
line[0][14] = ' ';
line[0][15] = '&';
line[1][0] = 'M';
line[1][1] = 'i';
line[1][2] = 'c';
line[1][3] = 'r';
line[1][4] = 'o';
line[1][5] = 'C';
line[1][6] = 'o';
line[1][7] = 'n';
line[1][8] = 't';
line[1][9] = 'r';
line[1][10] = 'o';
line[1][11] = 'l';
line[1][12] = 'l';
line[1][13] = 'e';
line[1][14] = 'r';
line[1][15] = 's';
}
void display(void);
/*F**************************************************************************
* FUNCTION_NAME: can_task
*-------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE : 4/05/00
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: void
******************************************************************************/
void can_task(void)
{
if (f_affichage == 1)
{
if(get_lcd_wr()==FALSE)
{
set_lcd_line(1, line[0]);
f_affichage = 2;
}
}
else if (f_affichage == 2)
{
if(get_lcd_wr()==FALSE)
{
set_lcd_line(2, line[1]);
f_affichage = 0;
}
}
switch (task_state)
{
case 0x00:
{
if (P3_3 == 0)
{
debounce_bp++;
if (debounce_bp == 50)
{
task_state = 1;
}
}
break;
}
case 1:
{
CAN_SET_CHANNEL(CHANNEL_1);
CAN_CHANNEL_IT_ENABLE(CHANNEL_1);
can_tx_id = can_200.id;
conf_tx = can_200.ctrl;
pt_candata_tx = can_200.pt_donne;
SendCanMsg();
task_state = 2;
break;
}
case 2:
{
debounce_bp = 0;
break;
}
}
}
/****************************************************************************
* FUNCTION_NAME: can_fct_it_txok
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE :
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:
* FUNCTION_INPUTS :
* FUNCTION_OUTPUTS:
******************************************************************************
* NOTE:
******************************************************************************/
void can_fct_it_txok (void)
{
channel_t channel;
task_state = 0;
channel = CAN_GET_CHANNEL;
CAN_CHANNEL_IT_DISABLE(channel);
}
void display(void)
{
line[0][0] = bin_to_ascii((can_tx_id.tab[0] & 0xF0)>>4);
line[0][1] = bin_to_ascii(can_tx_id.tab[0] &0x0F);
line[0][2] = bin_to_ascii((can_tx_id.tab[1] & 0xF0)>>4);
line[0][3] = bin_to_ascii(can_tx_id.tab[1] &0x0F);
line[0][4] = ' ';
line[0][5] = ' ';
line[0][6] = ' ';
line[0][7] = ' ';
line[0][8] = ' ';
line[0][9] = ' ';
line[0][10] = ' ';
line[0][11] = ' ';
line[0][12] = ' ';
line[0][13] = ' ';
line[0][14] = bin_to_ascii((dlc & 0xF0)>>4);
line[0][15] = bin_to_ascii(dlc &0x0F);
if (dlc > 0)
{
line[1][0] = bin_to_ascii((data_rx[0] & 0xF0)>>4);
line[1][1] = bin_to_ascii((data_rx[0] & 0x0F));
}else
{
line[1][0] = ' ';
line[1][1] = ' ';
}
if (dlc > 1)
{
line[1][2] = bin_to_ascii((data_rx[1] & 0xF0)>>4);
line[1][3] = bin_to_ascii((data_rx[1] & 0x0F));
}else
{
line[1][2] = ' ';
line[1][3] = ' ';
}
if (dlc > 2)
{
line[1][4] = bin_to_ascii((data_rx[2] & 0xF0)>>4);
line[1][5] = bin_to_ascii((data_rx[2] & 0x0F));
}else
{
line[1][4] = ' ';
line[1][5] = ' ';
}
if (dlc > 3)
{
line[1][6] = bin_to_ascii((data_rx[3] & 0xF0)>>4);
line[1][7] = bin_to_ascii((data_rx[3] & 0x0F));
}else
{
line[1][6] = ' ';
line[1][7] = ' ';
}
if (dlc > 4)
{
line[1][8] = bin_to_ascii((data_rx[4] & 0xF0)>>4);
line[1][9] = bin_to_ascii((data_rx[4] & 0x0F));
}else
{
line[1][8] = ' ';
line[1][9] = ' ';
}
if (dlc>5)
{
line[1][10] = bin_to_ascii((data_rx[5] & 0xF0)>>4);
line[1][11] = bin_to_ascii((data_rx[5] & 0x0F));
}else
{
line[1][10] = ' ';
line[1][11] = ' ';
}
if (dlc>6)
{
line[1][12] = bin_to_ascii((data_rx[6] & 0xF0)>>4);
line[1][13] = bin_to_ascii((data_rx[6] & 0x0F));
}else
{
line[1][12] = ' ';
line[1][13] = ' ';
}
if (dlc>7)
{
line[1][14] = bin_to_ascii((data_rx[7] & 0xF0)>>4);
line[1][15] = bin_to_ascii((data_rx[7] & 0x0F));
}else
{
line[1][14] = ' ';
line[1][15] = ' ';
}
}
/****************************************************************************
* FUNCTION_NAME: can_fct_it_rxok
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE :
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:
* FUNCTION_INPUTS :
* FUNCTION_OUTPUTS:
******************************************************************************
* NOTE:
******************************************************************************/
void can_fct_it_rxok (void)
{
Uchar i;
dlc = CANCONCH & MSK_CTRL_DLC;
for (i=0; i<dlc; i++)
{
data_rx[i] = CANMSG;
}
can_tx_id.std = (CANIDT1 << 3) | (CANIDT2 >> 5);;
CANSTCH = 0x00;
ENABLE_CHANNEL_RX; /* Reception enabled.*/
CAN_SET_CHANNEL(CHANNEL_2);
CAN_CHANNEL_IT_ENABLE(CHANNEL_2);
CANCONCH = dlc;
pt_candata_tx = data_rx;
CANIDT1 = CAN_SET_STD_ID_10_4 (can_tx_id.std);
CANIDT2 = CAN_SET_STD_ID_3_0 (can_tx_id.std);
for (i=dlc; i!=0; i--)
{
CANMSG = *pt_candata_tx++;
}
ENABLE_CHANNEL_TX;
CAN_IT_ENABLE;
display ();
CAN_SET_CHANNEL(CHANNEL_0);
CANCONCH |= 0x08;
f_affichage = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -