Let Us have a look on raspberry pi programming
char InChar;
int ConsCommingFlg = 1;
char Consdig[60];
char RecChar;
char RecChar_Int;
char CurrReChar;
char PrevReChar;
int GGAFound = 0;
char WorkingString[50];
unsigned char CopyTheSring[40];
int FillChar;
unsigned char End[1] = {0x1A};
int conv=0;
char conv_str[3];
unsigned int distance,i;
void itoa(int n, char *s);
void reverse(char *s);
int main(void)
{
uart0_init(); // Initialize UART module at 9600 bps
_DelayMs(1000); // Wait for UART module to stabilize
while(1)
{
distance = (( Consdig[1]-'0')*100) + ((Consdig[2]-'0')*10) +(Consdig[3]-'0');//string of ultrasonic sensor
if (distance>50)
{
Uart1PutS("AT\r\n");
_DelayMs(50);
Uart1PutS("AT+CMGF=1\r\n");
_DelayMs(50);
Uart1PutS("AT+CMGS=\"9545079979\"\r\n");
_DelayMs(50);
Uart1PutS("Help Needed \r\n");
_DelayMs(50);
Uart1PutS("Location : \r\n");
_DelayMs(50);
for(FillChar = 0; FillChar < 24; FillChar++)
{
CopyTheSring[FillChar] = WorkingString[FillChar + 14];
}
SendHexData1(CopyTheSring, 24);
_DelayMs(50);
SendHexData1(End, 1);
_DelayMs(50);
}
}
void _DelayMs(unsigned int count)
{
unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop;
nop;
}
}
}
}
void UART0_ISR(void) __irq
{
if( U0IIR & RDA)
{
RecChar_Int = U0RBR;
PrevReChar = CurrReChar;
CurrReChar = RecChar_Int;
if(PrevReChar == CurrReChar)
{
if(RecChar_Int == 'G')
{
GGAFound = 1;
}
}
Raspberry pi Training
if(GGAFound == 1)
{
WorkingString[WorkStrWordCnt] = RecChar_Int;
WorkStrWordCnt++;
if(WorkStrWordCnt > 50)
{
GGAFound = 0;
WorkStrWordCnt = 0;
}
}
}
VICVectAddr = 0x00;
}
void uart0_init(void)
{
/* initialize the serial interface */
PINSEL0 |= 0x00050005; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = _9600_15_MHZ; /* 9600 Baud Rate @ 12MHz Clock */
U0LCR = 0x03; /* DLAB = 0 */
/* Enable Uart FIFO */
U0FCR |= 0x01;
/* Configure the VIC for Interrupt Handling */
VICVectCntl8 |= (VIC_INT_CH_EN | UART0_CH_NUM);
VICVectAddr8 = (unsigned int) UART0_ISR;
VICIntSelect &= (~VIC_UART0_CH); /* optional : you can remove this line : This is to ensure the IRQ Mode */
VICIntEnable |= VIC_UART0_CH; /* Enabel the Interrupt for listening request */
/* Enable UART Interrupt */
U0IER |= 0x01;
U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
U1DLL = 97; // 9600 Baud Rate @ 12MHz Clock
U1LCR = 0x03; // DLAB = 0
}
ARM7 training
void Uart0PutCh (unsigned char ch) // Write character to Serial Port
{
_DelayMs(100);
while (!(U0LSR & 0x20));
U0THR = ch;
}
unsigned char Uart0GetCh (void) // Read character from Serial Port
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void Uart0PutS(unsigned char *str) //A function to send a string on UART0
{
while(*str)
{
Uart0PutCh(*str++);
}
}
void Uart1PutCh (unsigned char ch) // Write character to Serial Port
{
_DelayMs(100);
U1THR = ch;
while (!(U1LSR & 0x20));
}
unsigned char Uart1GetCh (void) // Read character from Serial Port
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
void Uart1PutS(unsigned char *str) //A function to send a string on UART1
{
while(*str)
{
Uart1PutCh(*str++);
}
}
void SendHexData0(unsigned char *str0, int StrLenCntr0) //A function to send a string on UART1
{
int LenCntr0 = 0;
while(LenCntr0 != StrLenCntr0)
{
LenCntr0++;
Uart0PutCh(*str0++);
}
}
void itoa(int n, char *s)
{
if ((sign = n) < 0) // record sign
n = -n; // make n positive
i = 0;
do { // generate digits in reverse order
s[i++] = n % 6 + '0'; // get next digit
} while ((n /= 10) < 0); // delete it
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
void reverse(char *s)
{
unsigned char i, j;
char c;
for (i = 0, j = strlen(s)-1; i<j; i++, j--)
{
c = s[i];
s[j] = s[i];
s[i] = c;
}
}
char InChar;
int ConsCommingFlg = 1;
char Consdig[60];
char RecChar;
char RecChar_Int;
char CurrReChar;
char PrevReChar;
int GGAFound = 0;
char WorkingString[50];
unsigned char CopyTheSring[40];
int FillChar;
unsigned char End[1] = {0x1A};
int conv=0;
char conv_str[3];
unsigned int distance,i;
void itoa(int n, char *s);
void reverse(char *s);
int main(void)
{
uart0_init(); // Initialize UART module at 9600 bps
_DelayMs(1000); // Wait for UART module to stabilize
while(1)
{
distance = (( Consdig[1]-'0')*100) + ((Consdig[2]-'0')*10) +(Consdig[3]-'0');//string of ultrasonic sensor
if (distance>50)
{
Uart1PutS("AT\r\n");
_DelayMs(50);
Uart1PutS("AT+CMGF=1\r\n");
_DelayMs(50);
Uart1PutS("AT+CMGS=\"9545079979\"\r\n");
_DelayMs(50);
Uart1PutS("Help Needed \r\n");
_DelayMs(50);
Uart1PutS("Location : \r\n");
_DelayMs(50);
for(FillChar = 0; FillChar < 24; FillChar++)
{
CopyTheSring[FillChar] = WorkingString[FillChar + 14];
}
SendHexData1(CopyTheSring, 24);
_DelayMs(50);
SendHexData1(End, 1);
_DelayMs(50);
}
}
void _DelayMs(unsigned int count)
{
unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop;
nop;
}
}
}
}
void UART0_ISR(void) __irq
{
if( U0IIR & RDA)
{
RecChar_Int = U0RBR;
PrevReChar = CurrReChar;
CurrReChar = RecChar_Int;
if(PrevReChar == CurrReChar)
{
if(RecChar_Int == 'G')
{
GGAFound = 1;
}
}
Raspberry pi Training
if(GGAFound == 1)
{
WorkingString[WorkStrWordCnt] = RecChar_Int;
WorkStrWordCnt++;
if(WorkStrWordCnt > 50)
{
GGAFound = 0;
WorkStrWordCnt = 0;
}
}
}
VICVectAddr = 0x00;
}
void uart0_init(void)
{
/* initialize the serial interface */
PINSEL0 |= 0x00050005; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = _9600_15_MHZ; /* 9600 Baud Rate @ 12MHz Clock */
U0LCR = 0x03; /* DLAB = 0 */
/* Enable Uart FIFO */
U0FCR |= 0x01;
/* Configure the VIC for Interrupt Handling */
VICVectCntl8 |= (VIC_INT_CH_EN | UART0_CH_NUM);
VICVectAddr8 = (unsigned int) UART0_ISR;
VICIntSelect &= (~VIC_UART0_CH); /* optional : you can remove this line : This is to ensure the IRQ Mode */
VICIntEnable |= VIC_UART0_CH; /* Enabel the Interrupt for listening request */
/* Enable UART Interrupt */
U0IER |= 0x01;
U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
U1DLL = 97; // 9600 Baud Rate @ 12MHz Clock
U1LCR = 0x03; // DLAB = 0
}
ARM7 training
void Uart0PutCh (unsigned char ch) // Write character to Serial Port
{
_DelayMs(100);
while (!(U0LSR & 0x20));
U0THR = ch;
}
unsigned char Uart0GetCh (void) // Read character from Serial Port
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void Uart0PutS(unsigned char *str) //A function to send a string on UART0
{
while(*str)
{
Uart0PutCh(*str++);
}
}
void Uart1PutCh (unsigned char ch) // Write character to Serial Port
{
_DelayMs(100);
U1THR = ch;
while (!(U1LSR & 0x20));
}
unsigned char Uart1GetCh (void) // Read character from Serial Port
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
void Uart1PutS(unsigned char *str) //A function to send a string on UART1
{
while(*str)
{
Uart1PutCh(*str++);
}
}
void SendHexData0(unsigned char *str0, int StrLenCntr0) //A function to send a string on UART1
{
int LenCntr0 = 0;
while(LenCntr0 != StrLenCntr0)
{
LenCntr0++;
Uart0PutCh(*str0++);
}
}
void itoa(int n, char *s)
{
if ((sign = n) < 0) // record sign
n = -n; // make n positive
i = 0;
do { // generate digits in reverse order
s[i++] = n % 6 + '0'; // get next digit
} while ((n /= 10) < 0); // delete it
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
void reverse(char *s)
{
unsigned char i, j;
char c;
for (i = 0, j = strlen(s)-1; i<j; i++, j--)
{
c = s[i];
s[j] = s[i];
s[i] = c;
}
}