📄 drv_rs.txt
字号:
______________________________________________________________________
> <
> RS232 driver v1.02 <
> for <
> PICos18 release 2.00 (beta 10 or upper) <
> <
> PICos18 - Real-time kernel for PIC18 family <
> <
> <
> www.picos18.com www.pragmatec.net <
>______________________________________________________________________<
This file contains all necessary informations to use properly the
PIC18 RS232 driver for PICos18 v2.00. This driver let you design a
multi-task application using the same USART without being concerned by
the USART shared access. Then every task of your application can print
message without being necessarily synchronised to the others.
______________________________________________________________________
> <
> I - Zip file content <
>______________________________________________________________________<
The drv_i2c zip file contains :
- drv_rs.c
- drv_rs.h : header file
- drv_rs.txt : this file
To use the PICos18 RS232 driver, first unzip the file.
Place the C and H file in your project directory.
This driver is supposed to be use with PICos18 and has been tested with
MPLAB 6.62 and C18 v2.40. Do not use this driver at a frequency lower
than 8 Mhz (use the PIC18 PLL to increase the internal frequency).
______________________________________________________________________
> <
> II - Hardware settings <
>______________________________________________________________________<
Adapt the SPBRG register according to the oscillator frequency to set
the correct baud rate generator (file drv_rs.c).
/* Change baud rate here [cf datasheet]*/
/* SPBRG = 0x40; for 9600 [40MHZ only]*/
/* SPBRG = 0x21; for 115200 [40MHZ only]*/
SPBRG = 21;
Look up the PIC18 datasheet for different settings.
______________________________________________________________________
> <
> III - TASCDESC settings (1) <
>______________________________________________________________________<
Update also the tascdesc.c file to take into account the new RS driver in
your application :
/**********************************************************************
* ----------------------- TASK & STACK DEFINITION --------------------
**********************************************************************/
DeclareTask(Example);
DeclareTask(RS_Drv);
...
volatile unsigned char stack0[DEFAULT_STACK_SIZE];
volatile unsigned char stack_rs[DEFAULT_STACK_SIZE];
...
______________________________________________________________________
> <
> IV - TASCDESC settings (2) <
>______________________________________________________________________<
Finally add the task and alarm descriptor to the tascdesc.c file :
...
/**********************************************************************
* ------------------------------ RS task -----------------------------
**********************************************************************/
rom_desc_tsk rom_desc_RS_DRV = {
RDV_RS_PRIO, /* prioinit from 0 to 15 */
stack_rs, /* stack address (16 bits) */
RS_Drv, /* start address (16 bits) */
READY, /* state at init phase */
RS_DRV_ID, /* id_tsk from 0 to 15 */
0x0000 /* ctx address (16 bits) */
};
...
To use the RS232 we propose a EXAMPLE task wich prints some string
of data. Because the task is a periodic one, we create an alarm :
AlarmObject Alarm_list[] =
{
/*******************************************************************
* ----------------------- Example task ----------------------------
*******************************************************************/
{
OFF, /* State */
0, /* AlarmValue */
0, /* Cycle */
&Counter_kernel, /* ptrCounter */
Example, /* TaskID2Activate */
ALARM_EVENT, /* EventToPost */
0 /* CallBack */
}
};
______________________________________________________________________
> <
> V - TASK Settings <
>______________________________________________________________________<
Open define.h and add this 3 definitions with correct value :
#define RS_NEW_MSG 0x10
#define RS_RCV_MSG 0x20
#define RS_QUEUE_EMPTY 0x40
#define RS_DRV_ID 6
#define RDV_RS_PRIO 8
#define EXAMPLE_ID 4
#define EXAMPLE_PRIO 5
The RS232 task is considered to be a driver, that means you have to give
one of the highest priority to the RS232 driver to let it run each time
the RS buffer is updated.
Adapt the values to your application is necessary (event values...).
______________________________________________________________________
> <
> VI - ISR connection <
>______________________________________________________________________<
Open the file int.c and declare the external RS232 ISR function :
extern void AddOneTick(void);
extern void RS_RX_INT(void); <= here
extern void RS_TX_INT(void); <= here
void InterruptVector(void);
And complete the InterruptVector function :
void InterruptVector(void)
{
EnterISR();
if (INTCONbits.TMR0IF == 1)
AddOneTick();
if (PIR1bits.RCIF == 1)
RS_RX_INT();
if (PIR1bits.TXIF == 1)
RS_TX_INT();
LeaveISR();
}
______________________________________________________________________
> <
> VII - RS driver usage <
>______________________________________________________________________<
In the Example task, include the driver header:
#include "drv_rs.h"
#include <stdio.h>
#include <string.h>
And declare a RS message (type RS_message_t):
RS_ message_t RS_msg;
In the task, a Printf function has been added to automaticaly prepare the
RS_message_t buffer with a const string of data.
See hereafter a basic example to print
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -