Aguijón Software Libraries  1.0
Documentation for the included Libraries
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
serial.c
Go to the documentation of this file.
1 /********************************************************************
2  FileName: serial.c
3  Dependencies: See INCLUDES section
4  Hardware: Aguijón rev3.0
5  Complier: Microchip XC16(for PIC24), C30(for PIC24)
6  Company: Vinagrón Digital
7 
8  Software License Agreement:
9 
10  blah blah blah
11 
12 ********************************************************************
13  File Description:
14  Includes serial RS232 functions.
15 
16 
17  Change History:
18  Rev Description
19  ---- -----------------------------------------
20  1.0 Initial release
21 ********************************************************************/
22 
23 #include <p24FJ128GB106.h>
24 #include "string.h"
25 #include "serial.h"
26 #include <uart.h>
27 #include "definitions.h"
28 
30 unsigned char RX_data = 0;
32 unsigned char BufferIndex = 0;
34 unsigned char cmdBuffer[20];
36 unsigned char MessageLength = 0;
37 
38 /**************************************************************************/
39 
40 
41 
53 void rx_int(void)
54 {
55  RX_data = ReadUART2();
56 
57  switch(RX_data){
58  case STX:
59  BufferIndex = 0;
60  MessageLength = 0;
61  memset(cmdBuffer, 0, 20);
62  break;
63  case ETX:
65  break;
66  default:
68  RX_data = 0;
69  BufferIndex++;
70  break;
71  }
72 }
73 
85 void tx_int(void) // Interrupcion de Transmision
86 {
87  //no implementada
88 }
89 
101 void __attribute__ ((interrupt,no_auto_psv)) _U2TXInterrupt(void)
102 {
103  tx_int();
104  U2TX_Clear_Intr_Status_Bit; //clear the interrupt status of UART2 TX
105 }
106 
118 void __attribute__ ((interrupt,no_auto_psv)) _U2RXInterrupt(void)
119 {
120  rx_int();
121  U2RX_Clear_Intr_Status_Bit; //clear the interrupt status of UART2 RX
122 }
123 
136 {
137  CloseUART2(); //deshabilitar UART
138 
139  //low baudrate, 8bit comm, no parity, 1 stop bit
140  IFS1bits.U2RXIF = 0;
141  IEC1bits.U2RXIE = 1; //habilitar interrupcion de recepcion
142  IPC7bits.U2RXIP2 = 0;
143  IPC7bits.U2RXIP1 = 1;
144  IPC7bits.U2RXIP0 = 0;
145 
146  U2MODE = 0x8000;
147 
148  U2STA = 0x2400;
149  U2BRG = BAUD19200; //serial.h
150 }
151 
163 void RS232_put(unsigned int data) //escribe datos al protocolo
164 {
165  WriteUART2(data);
166 }