PIC to MAX232

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Just a few more questions
Is the WDT shared..I mean in the 16F, the TMR0 prescaler is shared with it ?
I wish to use the WDT and TMR0 this time. I need TMR0 prescaler to work with TMR0 only plus a WDT of 30 seconds

Do I need to use the Extended Instruction set ?


Will the IRP bit setting be solved and I can use the 18F45K22 to read SMS up to like 100 chars and use all the msg "strings without an issue ?
 

jayanthd

Joined Jul 4, 2015
945
WDT is not shared with Timer0 in 18F devices. You can use both at the same time.

WDT delay is set in project settings in mikroC PRO PIC.

I always use extended instruction set with 18F devices. Not sure how it works.

IRP_bit setting will never occur in 18F devices when used with mikroC PRO PIC.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Nice...!
Time to learn a new PIC series.

I can get back tonight.

@jayanthd You have been of great help. Thank you.

I am still waiting for some explanation on your coding though. i.e post #218
 

jayanthd

Joined Jul 4, 2015
945
I am still waiting for some explanation on your coding though. i.e post #218
Don't worry. I will post the explanation in 1 or 2 days. The function needs a little modification. I am busy with another project. It is 99% complete. There is one small bug and I am trying to eliminate it. I never use PIC16F but it is my clients requirement for a project to use PIC16F73.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I will help you with the settings stage.

For now try the LED Blinking project I wrote for PIC18F45K22 @ 8 MHz Internal Oscillator.
Ur code is acting funny o_O
I just burned it and only output 0,1 and 2 are flashing on every port. :confused:
From the code it seems all the Leds should falsh ?? o_O but It's not.
 

bwack

Joined Nov 15, 2011
113
Haha this I didn't expect. Wow, the mikroC simlator was clueless and simulated FF on all ports, but after taking the following listing generated by mikroC with jayanths c-code and importing it into mplabx mpasm, THAT simulator replicated your fault very well as hex 07 (or as you said "output 0,1 and 2 are flashing on every port").

The error is a bit funny and maybe not so obvious. I'm going to be a little evil again and say: Can you see what it is ? Clue: The LATE register is 3 bits wide.
C:
;LED Blinking.c,37 ::      while(1) {
L_main1:
;LED Blinking.c,39 ::      LATA = LATB = LATC = lATD = LATE = 0xFF;
0x006C   0x0EFF     MOVLW  255
0x006E   0x6E8D     MOVWF  LATE
0x0070   0xFF8CCF8D    MOVFF  LATE, LATD
0x0074   0xFF8BCF8C    MOVFF  LATD, LATC
0x0078   0xFF8ACF8B    MOVFF  LATC, LATB
0x007C   0xFF89CF8A    MOVFF  LATB, LATA
MPLABs result:



try:
LATE = 0x07;
LATA = LATB = LATC = lATD = 0xFF;
 
Last edited:

jayanthd

Joined Jul 4, 2015
945
Will the IRP bit setting be solved and I can use the 18F45K22 to read SMS up to like 100 chars and use all the msg "strings without an issue ?
Yes, Yes.


Here you go.


You can replace this

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

with

C:
void Send_SMS(char *ptr2_gsm_buffer, char *ptr2_copy_const_2_ram_buffer, const char *ptr2_Ok_response, const char *ptr2_prompt_response, const char *ptr2_at_command, const char *ptr2_at_cmgf_command, const char *ptr2_at_cmgs_command, char *ptr2_actual_sms, unsigned int *ptr2_gsm_buffer_index, char *gsmAttempt, char clear_buffer_and_buffer_index_flag) {
    asm clrwdt

    while(strstr(gsm_buffer, CopyConst2Ram(ptr2_copy_const_2_ram_buffer, ptr2_Ok_response)) == 0) {
        asm clrwdt
        GSM_Send_Const_Command(ptr2_gsm_buffer, ptr2_copy_const_2_ram_buffer, ptr2_Ok_response, ptr2_at_command, ptr2_gsm_buffer_index, gsmAttempt, 1);
        GSM_Send_Const_Command(ptr2_gsm_buffer, ptr2_copy_const_2_ram_buffer, ptr2_Ok_response, ptr2_at_cmgf_command, ptr2_gsm_buffer_index, gsmAttempt, 1);
        GSM_Send_Const_Command(ptr2_gsm_buffer, ptr2_copy_const_2_ram_buffer, ptr2_prompt_response, ptr2_at_cmgs_command, ptr2_gsm_buffer_index, gsmAttempt, 1);

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

        DelayXSec(6);
    }

    if(clear_buffer_and_buffer_index_flag)
        memset(gsmBuffer, '\0', sizeof(gsmBuffer));

    (*gsm_buffer_index) = 0;
    asm clrwdt


C:
//GSM Constant Strings
const char atCommand1[] = "AT\r";
const char atCommand2[] = "ATE0\r";
const char atCommand3[] = "ATE1\r";
const char atCommand4[] = "AT+IPR=9600\r";
const char atCommand5[] = "AT+CMGF=1\r";
const char atCommand6[] = "AT+CPMS=\"SM\",\"SM\",\"SM\"\r";
const char atCommand7[] = "AT+CNMI=2,1\r";
const char atCommand8[] = "AT+CMGR=";
//const char atCommand9[] = "AT+CMGS=\"9900516837\"\r";
const char atCommand9[] = "AT+CMGS=\"+27725138668\"\r";
const char atCommandA[] = "AT+CMGD=1,4\r";

const char atResponse1[] = "\r\nOK\r\n";
const char atResponse2[] = "ERROR";
const char atResponse3[] = "+CMTI: \"SM\",";
const char atResponse4[] = "> ";
const char atResponse5[] = "RING";
const char atResponse6[] = "NO CARRIER";
const char atResponse7[] = "NO ANSWER";
const char atResponse8[] = "+CFUN: 1";
const char atResponse9[] = "+CPIN: READY";

Inside the function

until OK is received

C:
while(strstr(gsm_buffer, CopyConst2Ram(ptr2_copy_const_2_ram_buffer, ptr2_Ok_response)) == 0) {
then loop is executed continuously.

Sometimes modem will not be initialized and text mode might have not been set or changed and hence to make sure the modem is working and is in text mode the AT \r and AT+CMGF=1\r commands are sent and checked for OK response. To do this GSM_Send_Const_AT_Cmd() function calls are used with buffer clear flag set to 1.
So, until OK is received the AT\r command is sent repeateadly with a short delay to check the response. Then until OK is received AT+CMGF=1\r command is repeateady sent clearing the buffer if required.

Then AT+CMGS=mobile number\r is sent and checked for prompt (> ) response. If Prompt response is received then actual message is sent and 0x1A is sent to complete the SMS sending operation and then the while loop is used to check if OK is received. If OK is received then it means SMS sending was successful.

Then it comes out of the function by clearing the buffer if the buffer clear flag was set to 1.


When you call Send_Sms() function it is actually a nested call.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Thanks Guys...
I was away for a while.

Started the new code in 18F.. Ran a lot of bumps but managed to fix them and so far it is working.
There is a " suspicious pointer conversion" message coming up but code works.
I will get back with that later
 
Top