#include "LCD.h"
#define NULL 0
void SendMessage(char*);
void EnableUART (void);
void DisableUART(void);
void CHEK_isr (void);
void TX_isr (void);
void RC_isr (void);
const char MODEM_SEND[] = "AT\n\r";
static char MODEM_RECV[10];
void main()
{
signed char cIndex = 1;
unsigned char ucResponse[2];
InitialiseDisplay();
EnableUART();
while(1)
{
}
}
void EnableUART ( void )
{
TRISCbits.TRISC6 = 1; //TX PIN
TRISCbits.TRISC7 = 1; //RX PIN
SPBRG = 25; //BR = 9600
TXSTAbits.TXEN = 0;
TXSTAbits.BRGH = 1;
RCSTAbits.SPEN = 1;
RCSTAbits.CREN = 1;
BAUDCTLbits.BRG16 = 0;
TXSTAbits.SYNC = 0;
TXSTAbits.TX9 = 0;
TXSTAbits.TXEN = 1;
INTCONbits.PEIE = 1; //Enable Peripheral intr
PIE1bits.RCIE = 1; //Enable RX intr
PIE1bits.TXIE = 1; //Enable TX intr
IPR1bits.TXIP = 0; //TX - Low Priority intr
IPR1bits.RCIP = 0; //RX - Low Priority intr
RCONbits.IPEN = 1; //Enable Interrupt Priorities
INTCONbits.GIEL = 1; //Enable Low Priority Intr
INTCONbits.GIE = 1; //Enable interrupts
}
void SendMessage( char* Msg)
{
int len, count = 0;
TXSTAbits.TXEN = 1; //Enable UART
while( *(Msg+count) != NULL )
{
TXREG = ( *(Msg+count) );
while( !PIR1bits.TXIF )
{
//Wait till TXREG become empty
}
Delay(1);
count++;
}
TXSTAbits.TXEN = 0;
}
void DisableUART( void )
{
TXSTAbits.TXEN = 0;
}
#pragma code low_vector = 0x18
void low_ISR (void)
{
_asm goto CHEK_isr _endasm
}
#pragma code
#pragma interruptlow CHEK_isr
void CHEK_isr(void)
{
if( PIR1bits.TXIF == 1 )
{
TX_isr();
}
if( PIR1bits.RCIF == 1 )
{
RC_isr();
}
}
void TX_isr(void)
{
SendMessage(MODEM_SEND);
TRISB = 0x00;
PORTB = 0x0A;
}
void RC_isr(void)
{
TRISB = 0x00;
PORTB = 0x05;
MODEM_RECV[0] = RCREG;
WriteDataToDisplay(MODEM_RECV[0]);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?