/********************************************************************************/
/*File Name: */
/***PIC18F2520.c */
/*------------------------------------------------------------------------------*/
/*Description: */
/***This program enables the PIC18F2520 to communicate with the 9XCite RF Module*/
/***and the Basic Atom 24. */
/*------------------------------------------------------------------------------*/
/*Function: */
/***The PIC18F2520 must interpret and process the data received by the RF Module*/
/***at any given time and interrupt the Basic Atom in case of an important */
/***message. An important message will consist of information indicating that */
/***the enemy robot is in this robots personal territory. Also, this MCU will */
/***calculate for the Basic Atom, angle and distance information for any */
/***destination coordinate. */
/*------------------------------------------------------------------------------*/
/*Authors: */
/***Iván C. Filpo */
/***Cory D. Lawrence */
/***Eduardo María Antonieta de las Maricas de hoy día */
/********************************************************************************/
//The below declaration declares variables store the information received by the
//9XCite RF Module. The 'o' stands for 'our', as in our theta for instance.
//On the other hand, the init stands for initial. These are the initial coords
#include <18f2520.h>
#include <p18cxxx.h>
#define ANGLE(A) A*360/255;
#define XCOORD(X) X*6/255;
#define YCOORD(Y) Y*8/255;
#define BAUD_RATE(X) 20000000/16*X-1;
/* Definition of Functions */
void rfint(void);
void changevector(void);
/* Definition of Structures*/
static int count,color;
struct location{
int theta;
int x;
int y;
}init,our,their;
#pragma code
void main(void){
/*If interrupts are desired, then set the RCIE bit and configure the RCIP, GIE/GIEH and
PEIE/GIEL bits, appropriately.*/
PIE1 = PIE1 | 0x20; //Enable Usart Receive Interrupt
IPR1 = IPR1 | 0x20; //Make it a high priority interrupt
INTCON = INTCON | 0x80; //Enable all hight priority unmasked interrupts
/*Set USART Baud Rate*/
/*Baud Rate = FOSC/(16(X+1)), X is value to be set in SPBRG register*/
TXSTA = TXSTA | 0x02;
SPBRG = BAUD_RATE(9600);
}
#pragma code high_vector=0x08
void changevector(void){
_asm GOTO rfint _endasm
}
#pragma interrupt rfint
void rfint(void){
switch(count){
case 0:
blue.theta = RCREG;
count++;
break;
case 1:
red.theta = RCREG;
count++;
break;
case 2:
blue.x = RCREG;
count++;
break;
case 3:
red.x = RCREG;
count++;
break;
case 4:
blue.x = (our.x << 8) | RCREG;
count++;
break;
case 5:
red.x = (their.x << 8) | RCREG;
count++;
break;
case 6:
blue.y = RCREG;
count++;
break;
case 7:
red.y = RCREG;
count++;
break;
}
}