hi all... im currently doing on this project(attached).. basically my part is the communication between microcontroller and remote system and acknowledgement (slides 7 and 8)... basically i have tried various examples but i couldnt find a way to do it.. pointers and helps are much appreciated...
and here's a code i have been working on for the communication between the remote system and PIC...
Code:
#include <p18f4520.h>
#include <usart.h>
#include <delays.h>
#include <portb.h>
unsigned char c;
unsigned char c1;
unsigned char c2;
unsigned char c3;
unsigned char c4;
unsigned char c5;
/*
unsigned char c[6];
unsigned char i;
unsigned char b;
*/
void rx_handler (void);//declare the ISR function.HIGH
#define BUF_SIZE 25
/*
* Step #1 The data is allocated into its own section.
*/
#pragma idata bigdata
char data[8][BUF_SIZE+1] = {
{ "You Typed: 0\n\r" },
{ "You Typed: 1\n\r" },
{ "You Typed: 2\n\r" },
{ "You Typed: 3\n\r" },
{ "You Typed: 4\n\r" },
{ "You Typed: 5\n\r" },
{ "Invalid key (0-5 only)\n\r" }
};
#pragma idata
//location of the ISR.(HIGH)
#pragma code rx_interrupt = 0x8
void rx_int (void)
{
_asm goto rx_handler _endasm
}
#pragma code //return to default code section
#pragma interrupt rx_handler
void rx_handler (void)
{
/*
b = getcUSART();
if(b == '1')
{
c[0] = b;
i = 1;
}
else
{
c[i] = b;
i++;
}
*/
//Get the character received from the USART
while(!DataRdyUSART());
c = getcUSART();
while(!DataRdyUSART());
c1 = getcUSART();
while(!DataRdyUSART());
c2 = getcUSART();
while(!DataRdyUSART());
c3 = getcUSART();
while(!DataRdyUSART());
c4 = getcUSART();
//Clear the interrupt flag
PIR1bits.RCIF = 0;
}
void main (void)
{
ADCON1 = 0x0F;
TRISCbits.TRISC5 = 0;
//LED
TRISB = 0;
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 25);
PORTBbits.RB3 = 1;
PORTCbits.RC5 = 1;
Delay10KTCYx(50);
while (BusyUSART());
//value sent
putcUSART(0x31);
while (BusyUSART());
//value sent
putcUSART(0x32);
while (BusyUSART());
//value sent
putcUSART(0x33);
while (BusyUSART());
//value sent
putcUSART(0x34);
while (BusyUSART());
//value sent
putcUSART(0x35);
Delay10KTCYx(50);
PORTBbits.RB3 = 0;
PORTCbits.RC5 = 0;
/* Enable interrupt priority */
RCONbits.IPEN = 1;
/* Make receive interrupt high priority */
IPR1bits.RCIP = 1;
/* Enable all high priority interrupts */
INTCONbits.GIEH = 1;
/* Loop forever */
while (1)
;
}
and here's a code i have been working on for the communication between the remote system and PIC...
Attachments
Last edited: