PIC to MAX232

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
That was what I am thinking...!
My space is limited so I will change to ATE0 to save space.

AS for reading SMS..I would need that, but it all depends on how much space is left.
I will implement the GSM part into the controller code and we'll see how much space there is.

I would mostly like to do is
Read a message like "SIMStatus" from the 5 numbers that is already saved for sending the SMS. These no.s have the authority.
When this SMS is received...code would send an SMS to service provider to check for SIM balance and then after receiving the answer from the provider, forward that message to the only number that the status request was made from.
Then clean the inbox.

That is what I will need to do, provided I have memory left.
 

jayanthd

Joined Jul 4, 2015
945
That I have already done in one of my other projects that is when SMS has to be sent to a number after checking an SMS then it uses the senders mobile number.

In Locker project I had coded such that if one has to disable security then s secret sms has to be sent from the same mobile number which was used to setup the locker.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I manage to write a routine that will disable echo, send SMS and when done Enable echo...I think that part is working.

I have a problem...
When I write long SMS, what buffers will be affected.
I think I need increase the buffer size too.
I have these for now

C:
char GSM_Buffer[37];
char buffer[36];
//char SMS[30];
//char SMS_Index[4];
The two below are not is use I believe
C:
//char SMS[30];
//char SMS_Index[4];
Are u using them or are they needed?
The other two I can see them in use but not these two

So far the longest SMS is 58.
I think I need to include all letters and "space, but no "\". Am I right ?

Can you clarify these for me ?
 

jayanthd

Joined Jul 4, 2015
945
So far the longest SMS is 58.
I think I need to include all letters and "space, but no "\". Am I right ?

Can you clarify these for me ?
if you form the message in ram like reading temperature and converting it to string and using it as sms then you need sms[] variable and in your Send_SMS() function *s8 is char that is char*s8

If you want to use rom strings for SMS then you need to change char*s8 to const char*s8

Also buffer1[59] has to be used as it is used in

UART1_Write_Text(CopyConst2Ram(*s2, *s8)); inside Send_SMS() function.
 

jayanthd

Joined Jul 4, 2015
945
Price difference between PIC16F887 E/P and PIC18F46K22 E/P is 1.03 USD.

http://www.microchipdirect.com/ProductDetails.aspx?Category=PIC16F887&&keywords=PIC16F887-I/P

http://www.microchipdirect.com/ProductDetails.aspx?Category=PIC18F46K22

And for 1 USD more you get a lots of ROM and RAM. PIC18F devices are better than PIC16Fs.

mikroC PRO PIC doesn't generate bank switching code. You have to set the IRP_bit manually in the code but works great for PIC1*Fs.

Long back I stopped using PIC16Fs.

The main PICs I use are

PIC12F683
PIC12F1840
PIC18F13K22
PIC18F14K22
PIC18F25K22
PIC18F26K22
PIC18F45K22
PIC18F46K22
PIC18F2550
PIC18F4550
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I figured I would need o increase the buffer.

Another question is which of these takes more space ?
C:
const char [59]
or
C:
char [59]
1. If the message does not change I have to use "const char" right?
2. I believe I would need "char" if I need to read the SMS and send it, right ?

Another question raised is !
My controller code is interrupt driven.
And I see that GSM code is using blocking delays to get the job done.

Would I need to disable TMR0 and TMR1 during a SMS is being sent ?

I do not have plenty of latest PICs. I need to work with what I have to develop a proto that I can show them I can do what they are asking. Depending on how much approval I get I can decide if I can go for 18F's

Wouldn't it be a better choice to have the GSM in a separate PIC and the controller running on another. In a fault even the controller can inform the GSM to send the sms ? may be use I2C to communicate.
Here again I am venturing into uncharted territory for me.
Just a thought.

by the way the I got a partial answer to post # 205
 

jayanthd

Joined Jul 4, 2015
945
Both take the same amount of space but const char is placed in ROM and char is placed in RAM.

1. If the message does not change I have to use "const char" right?
2. I believe I would need "char" if I need to read the SMS and send it, right ?
1.Yes
2.Yes

Would I need to disable TMR0 and TMR1 during a SMS is being sent ?
Yes.


Yes, you can do that but not necessary if you use a PIC18F with more ROM and RAM. One controller will be able to do it.

For security Locker I had used PIC32MX795F512L
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
C:
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr) {
    asm clrwdt

    while(strstr(s1, CopyConst2Ram(s2, s3)) == 0) {
        asm clrwdt
        GSM_Send_Const_Command(s1, s2, s3, s5, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s3, s6, idx, gsmAttempt, 1);
        GSM_Send_Const_Command(s1, s2, s4, s7, idx, gsmAttempt, 1);

        UART1_Write_Text(s8);
        Delay_ms(500);
        UART1_Write(0x1A);

        DelayXSec(6);
    }

    memset(gsmBuffer, '\0', sizeof(gsmBuffer));
    (*idx) = 0;
    asm clrwdt
I am trying to get my head around the above code.
Q.>?
1. How does this work I mean see below
C:
void Send_SMS(char *s1, char *s2, const char *s3, const char *s4, const char *s5, const char *s6, const char *s7, char *s8, unsigned int *idx, char *gsmAttempt, char clr)
I know what those things (*s) points to. I am wondering why the arrangement, How does one know which is evaluated first and how one compares to the other. Mainly how one knows which order to put them in ?
2. what does "*idx" do, what it the reason for it to be at that location. ?
3. Same goes for "*gsmAttempt".
4. if I do not need "*s5" and "*s6", can I omit them ?

5.
C:
  while(strstr(s1, CopyConst2Ram(s2, s3)) == 0)
I am still confused about the above part. In what condition the the function executes ?
 

jayanthd

Joined Jul 4, 2015
945
I already mentioned that you have to change

C:
char*s8
to

C:
const char*s8
In function prototype and function definition and also change

C:
UART1_Write_Text(s8);
to

C:
UART1_Write_Text(CopyConst2Ram(s2, s8));
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I was implementing the GSM part into controller code. :)
I knew it won't fit but I tried to put in the basics to send SMS and I go the stupid IRP issue. :eek:
Even if I solve the IRP issue I cannot get all the function in this PIC. :( So what's the point...EH !

So I searched and I got this PIC18F45K22, just on piece. It is a pin replacement meaning It has a internal oscillator.
I can swap it into the proto type.
But I am in a bit of a jam.
I started with it and I got stuck right at the beginning . It has way too many configurations. :confused:
and I can't even seem to get a simple blinking led running. I believe it is a config issue.
I need guidance to start with this.

Below is the 16F887 settings I am using for the controller


C:
void main(){
  OSCCON = 0x77;                 // 8MHz Internal Osc.
  ANSEL = 0x03;                  // RA0 & RA1 as Analog Rest as Digital IO.
  ANSELH = 0x00;                 // Rest as Digital IO.
  CM1CON0 = 0x07;                // Disable Comparator 1.
  CM2CON0 = 0x07;                // Disable Comparator 2.
  PORTA = 0;                     // Clear PORT A.
  PORTB = 0;                     // Clear PORT B.
  PORTC = 0;                     // Clear PORT C.
  PORTD = 0;                     // Clear PORT D.
  PORTE = 0;                     // Clear PORT E.
  TRISA = 0xFF;                  // PORT A as Input.
  TRISB = 0x00;                  // PORT B as Output.
  TRISC = 0xB8;                  // "b10111000".
  PORTDimg = 0x2F;               // PORT D Shadow, Identical to TRISD.
  TRISD = 0x2F;                  // RD <0 - 3 & 5> as Input, Rest as Output.
  TRISE = 0xFF;                  // PORT E as Input.

  ADC_Init();                    // Innitiate ADC.
  VCFG0_bit = 1;                 // Externel Vref +.
  VCFG1_bit = 0;                 // Internal Vref - as GND.
  Lcd_Init();                    // Innitiate LCD.
  Lcd_Cmd(_LCD_CLEAR);           // Clear LCD.
  Lcd_Cmd(_LCD_CURSOR_OFF);      // Cursor OFF.
  Delay_ms(100);                 // Wait to Stabilize.
  UART1_Init(9600);              // Initialize UART module at 9600 baud.
  Delay_ms(100);                 // Wait for UART module to stabilize.
//------- Clear and Set up IRQ and Fire up the Timers --------------------------
  OPTION_REG = 0x81;             // No pullups, Timer 0 at Prescaler 4.
  INTCON = 0;                    // Disable All Interrupts First.
  PIE1 = 0;                      // Disable All Peripheral Interrupts.
  PIE2 = 0;                      // Disable All Peripheral Interrupts.
  INTCON.T0IE = 1;               // Enable the Timer0 Interrupt.
  INTCON.T0IF = 0;               // Clear Timer 0 Register Overflow Flag.
  TMR0 = TMR0set;                // Load Timer 0 with Preset.
  T1CON = 0x30;                  // No gate, Int Tcyc/8, TMR1 Stopped.
  TMR1H = TMR1L = 0;             // Timer counts up to CCP value.
  CCPR1 = 625;                   // 1usTcyc * 8 Prescale * 625 = 5msec.
  CCP1CON = 0x0B;                // NO Hardware PWM.
  TMR1IF_bit = 0;                // PIR1 reg, Clear the TMR1 Overflow IRQ.
  CCP1IF_bit = 0;                // Clear TMR1 IRQ flag bit.
  T1CON.TMR1ON = 1;              // Start TIMER 1.
  TMR1IE_bit = 1;                // Enable the Timer1 overflow Interrupt.
  RCIF_bit = 0;                  // Clear Rx Interrupt Flag (GSM)
  PIE1.RCIE = 1;                 // Enable Rx Interrupt (GSM)
  CCP1IE_bit = 1;                // Enable the CCP1 Interrupt.
  INTCON.GIE = 1;                // Global Interrupt Enabled.
I need to some advice on how to set the 18F45K22

It has too many oscillator settings.
Too many ANSEL and way too many things new to me.
And an extra comparator.

Below is the blinking code I tried and not working

CSS:
void main() {
OSCCON  = 0x33;
//OSCCON2 = 0x07;
ANSELA =  0x03;
ANSELB =  0x00;
ANSELC =  0x00;
ANSELD =  0x00;
ANSELE =  0x00;
CM1CON0 = 0x07; // Disable Comparator 1.
CM2CON0 = 0x07; // Disable Comparator 2.
PORTA = 0; // Clear PORT A.
PORTB = 0; // Clear PORT B.
PORTC = 0; // Clear PORT C.
PORTD = 0; // Clear PORT D.
PORTE = 0; // Clear PORT E.
TRISA = 0xFF; // PORT A as Input.
TRISB = 0x00; // PORT B as Output.
TRISC = 0xF8; // Later.

TRISD = 0x2F; // RD <0 - 3 & 5> as Input, Rest as Output.
TRISE = 0xFF; // PORT E as Input.
LATA = 0x00;
  LATB = 0x00;
   LATC = 0x00;
    LATD = 0x00;
     LATE = 0x00;
//------- Clear or Set flags ---------------------------------------------------
while(1)
  LATA = 0x00;
  DELAY_MS(1000);
  LATB = 0x00;
  DELAY_MS(1000);
   LATC = 0x00;
   DELAY_MS(1000);
    LATD = 0x00;
    DELAY_MS(1000);
     LATE = 0x00;
     DELAY_MS(1000);
  LATA = 0xFF;  
  DELAY_MS(1000);
  LATB = 0xFF; 
   DELAY_MS(1000);
   LATC = 0xFF;
   DELAY_MS(1000);
    LATD = 0xFF;
    DELAY_MS(1000);
     LATE = 0xFF;
     DELAY_MS(1000);
}
The PORT B, part of C and D should flash but noooo ! o_O

I need to work on internal oscillator at 8Mhz. If I change the frequency I need to re-set my timers which will take time, 8Mhz should be OK.
No comparator or any other features except timers.

Please help me out here guys.
I just need to get pass the setting stage.
 
Top