razgriz66
Newbie level 5
- Joined
- Mar 24, 2013
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,336
k. so im having trouble understanding why my gsm and pic cant understand each other.
so far i've been able to do PC to gsm and PC to pic, no luck with gsm to pic.
im using pic16f877a, sim900D, and usb to uart(PL2303) for testing
i have 3 files in the project folder
here's the main code:
main.c
the ff codes are from the example:
usart.c
usart.h
so far what i know is commands are terminated with CR and messages are sent with substitute
https://www.asciitable.com/
the problem i believe lie on my printf's
so far i've been able to do PC to gsm and PC to pic, no luck with gsm to pic.
im using pic16f877a, sim900D, and usb to uart(PL2303) for testing
i have 3 files in the project folder
here's the main code:
main.c
Code:
#define _LEGACY_HEADERS
#include <htc.h>
#include <stdio.h>
#include "usart.h"
__CONFIG(HS & WDTDIS & PWRTEN & BOREN & LVPDIS & UNPROTECT);
//DELAY===================================================================
void sysd(time)
{
while(time != 0)
{
time = time-1;
}
}
//SEND MSG================================================================
void sendmsg(x)
{
printf("\rAT\n");
sysd(20000);
printf("\rAT+CMGF=1\n");
sysd(20000);
printf("\rAT+CMGS=\"09654545564\"\n");
sysd(20000);
if(x == 0)
{
if(RB6 == 0)
printf("\rBin1 Status: OK!");
else if(RB6 == 1)
printf("\rBin1 Status: WARNING!");
if(RB5 == 0)
printf("\rBin2 Status: OK!");
else if(RB5 == 1)
printf("\rBin2 Status: WARNING!");
if(RB4 == 0)
printf("\rBin3 Status: OK!");
else if(RB4 == 1)
printf("\rBin3 Status: WARNING!");
if(RB3 == 0)
printf("\rBin4 Status: OK!");
else if(RB3 == 1)
printf("\rBin4 Status: WARNING!");
printf("\n");
}
else if(x == 1)
{
printf("\rThis is a test message!\n");
}
sysd(10000);
}
//TRIGGER FEEDING=========================================================
void triggerfeeding()
{
RB7 = 0;
sysd(20000);
RB7 = 1;
}
//PROGRAM START===========================================================
void main(void)
{
ADCON1 = 0x0F;
INTCON=0; // purpose of disabling the interrupts.
init_comms(); // set up the USART - settings defined in usart.h
TRISB = 0x0F; //Feeder Module 1111 0000
//rx/tx
TRISE = 0x07; //Trouble Shooting Switches(Trigger and GSM) + Clock
//0000 0111
TRISD = 0x00;
PORTB = 0x00;
PORTE = 0x00;
RB7 = 1;
while(1)
{
sendmsg(1); //for testing
if(RB0 == 1)
{
triggerfeeding();
sendmsg(0);
}
if(RE1 == 1) //test feeder
{
triggerfeeding();
}
if(RE2 == 1) //test GSM
{
sendmsg(1);
}
}
}
usart.c
Code:
#include <htc.h>
#include <stdio.h>
#include "usart.h"
void
putch(unsigned char byte)
{
/* output one byte */
while(!TXIF) /* set when register is empty */
continue;
TXREG = byte;
}
unsigned char
getch() {
/* retrieve one byte */
while(!RCIF) /* set when register is not empty */
continue;
return RCREG;
}
unsigned char
getche(void)
{
unsigned char c;
putch(c = getch());
return c;
}
Code:
#ifndef _SERIAL_H_
#define _SERIAL_H_
#define BAUD 9600
#define FOSC 4000000L
#define NINE 0 /* Use 9bit communication? FALSE=8bit */
#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1
#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif
#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif
#if defined(_16F87) || defined(_16F88)
#define RX_PIN TRISB2
#define TX_PIN TRISB5
#else
#define RX_PIN TRISC7
#define TX_PIN TRISC6
#endif
/* Serial initialization */
#define init_comms()\
RX_PIN = 1; \
TX_PIN = 1; \
SPBRG = DIVIDER; \
RCSTA = (NINE_BITS|0x90); \
TXSTA = (SPEED|NINE_BITS|0x20)
void putch(unsigned char);
unsigned char getch(void);
unsigned char getche(void);
#endif
so far what i know is commands are terminated with CR and messages are sent with substitute
https://www.asciitable.com/
the problem i believe lie on my printf's
Last edited: