Problem with SMS Project: Using 16F877A


Closed Thread
Results 1 to 15 of 15
  1. #1

    Exclamation Problem with SMS Project: Using 16F877A

    Hi
    I have 3 locations in EEprom to which I want to assign an phone number each. I want to achieve this by sending an text messege from an already programmed phone number in the PIC. Its not working for me at the moment when I try to add the number to location 1 & sometimes 2. It works pretty well when I use location 3. Here is my program

    DEFINE OSC 4
    ADCON1=7
    CMCON=7
    INTCON=0
    OPTION_REG.7=0
    TRISA=0 : PORTA=0
    TRISB=0 : PORTB=0
    TRISC=%10000000 : PORTC=0
    TRISD=0 : PORTD=0
    TRISE=0 : PORTE=0
    CCP1CON=0
    a var byte
    b var byte
    c var byte
    d var byte
    e var byte
    f var byte
    g var byte
    num var byte[13]
    ph1 var byte[13]
    ph2 var byte[13]
    ph3 var byte[13]
    my1 var byte[13]
    my2 var byte[13]
    sms var byte[17]
    @ ERRORLEVEL -306
    yellowled var portb.4
    redled var portb.5
    greenled var portb.6

    Include "modedefs.bas"
    EEPROM 200,["+","4","4","7","8","3","2","3","2","3","1","4","6 ","+","4","4","7","9","3","1","2","2","5","2","3", "7"]

    gosub load

    gosub del

    main:
    high portb.6 : pause 30 : low portb.6

    DEBUG "AT^SMGR=1",13
    DEBUGIN 5000,main,[WAIT("UNREAD"),SKIP 3,STR num\13\13,SKIP 27,STR sms\17\13]

    gosub chk : pause 500
    DEBUG "AT+CMGD=1",13
    for a=0 to 15
    num[a]="0" : sms[a]="0"
    next a
    goto main

    chk:
    a=0 : b=0 : d=0 : e=0 : f=0
    for g=0 to 12
    if num[g]=ph1[g] then a=a+1
    if num[g]=ph2[g] then b=b+1
    if num[g]=ph3[g] then d=d+1
    if num[g]=my1[g] then e=e+1
    if num[g]=my2[g] then f=f+1
    next g
    if (a=13) OR (b=13) OR (d=13)then gosub chkms
    if (e=13) OR (f=13)then gosub adn
    return


    adn:
    for g=0 to 50
    toggle yellowled
    pause 50
    next g
    if sms[0]="+" then

    SELECT CASE sms[13]
    CASE "1"
    for a=0 to 12
    write a,num[a]
    next a

    CASE "2"
    for a=0 to 12
    write a+13,num[a]
    next a

    CASE "3"
    for a=0 to 12
    write a+26,num[a]
    next a
    END SELECT
    gosub load

    return

    chkms:
    for g=0 to 30
    toggle greenled
    pause 30
    next g
    return




    load:
    for a=0 to 12
    read a,ph1[a] : read a+13,ph2[a] : read a+26,ph3[a]
    next a

    return

    del:
    DEBUG "AT+CMGD=1",13
    DEBUGIN 5000,del,[WAIT("OK")]
    gosub set
    return

    set:
    pause 1000
    DEBUG "AT+CMGF=1",13
    DEBUGIN 5000,set,[WAIT("OK")]
    return

    ' sms[13] decides which location the number will be stored.
    Please help
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Can you try this

    Code:
    CASE "1"
    for a=0 to 12
    write EE_Ph1+a,num[a]
    next a
    
    CASE "2"
    for a=0 to 12
    write EE_Ph2+a,num[a]
    next a
    
    CASE "3"
    for a=0 to 12
    write EE_Ph3+a,num[a]
    next a
    END SELECT
    gosub load
    do the same for reading back. EE_Ph1 to 3 are the eeprom locations of the telephone numbers
    This is how to define them

    EE_Ph1: data byte[13] ' allocate space for phone 1 in eeprom
    EE_Ph2: data byte[13]
    EE_Ph3: data byte[13]
    Last edited by Jerson; - 18th October 2009 at 02:51.

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Thanks Jerson for your reply. Could you give me single line example of reading as well. I didn´t knew about read write structure like this.
    I am using PBP for this.
    Last edited by financecatalyst; - 18th October 2009 at 22:58.
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Same as the write, you do a read

    for a= 0 to 13
    read EE_Ph1+a, Ph1[a]
    next

    will read from The EEPROM to RAM

  5. #5


    Did you find this post helpful? Yes | No

    Default

    I did as advised, I also changed the code to send me a text back with the what is stored in it after I send 3 text with 3 numbers at 3 locations.

    The problem is with the first location only - the number stored at location one is "00078xxxxxxxx".
    Its only the first 3 digits getting stored as "000" instead of "+44"

    Thanks

    P.s- My PIC is reseting itself automatically, I have an 2.2K between Vdd and MCLR.
    Last edited by financecatalyst; - 19th October 2009 at 22:17.
    ___________________
    WHY things get boring when they work just fine?

  6. #6


    Did you find this post helpful? Yes | No

    Question

    I did the same process again with my original ph1 var byte[]13 only, results are the same. Also when I send another messege the previous number should be replaced at the location specified (Yes, it does enters to write the new number as led does toggles) , BUT its not happening as well. I also tried the following approach where I replaced all locations with "0" before writing the number :
    for a=0 to 12
    write a,"0" : pause 40
    write a,num[a] : toggle red : pause 700
    read a,ph1[a] : pause 40
    next a
    Still no luck.
    Last edited by financecatalyst; - 19th October 2009 at 23:49.
    ___________________
    WHY things get boring when they work just fine?

  7. #7
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Looks like you're overstepping your variables boundary. Do a check on the array indices for each array variable that you write. Maybe you're writing more than it can hold and it overwrites the following variable. Variable in point is Num[13] in this case.

  8. #8


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by Jerson View Post
    Looks like you're overstepping your variables boundary. Do a check on the array indices for each array variable that you write. Maybe you're writing more than it can hold and it overwrites the following variable. Variable in point is Num[13] in this case.
    Could you please explain what you mean, I am sorry I dont understand how and what xcatly I have to do?
    ___________________
    WHY things get boring when they work just fine?

  9. #9
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    What I mean is you should check that if your variable is an array of 12 bytes, you should not be writing more than 12 bytes to it. If you do, you are overwriting another variable in memory which follows the one you are writing to.

  10. #10


    Did you find this post helpful? Yes | No

    Question

    Ok, I think I have got your point. I read somewhere that it is advisable to write "0" to all EEprom locations before attempting any write statement. Is it true?
    I will otherwise remove statements writing "0" to locations before an sms is received and after and sms is processed and system is ready to receive the new one.

    Also I wonder why ph1 locations 0 to 12 gets first 3 digits as 0. As far as overwriting is concerned there are no locations -3,-2,-1 for me to make a mistake and shift 3 places forward?
    ___________________
    WHY things get boring when they work just fine?

  11. #11
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by financecatalyst View Post
    Hi

    a var byte
    b var byte
    c var byte
    d var byte
    e var byte
    f var byte
    g var byte
    num var byte[13]
    ph1 var byte[13]
    ph2 var byte[13]
    ph3 var byte[13]
    my1 var byte[13]
    my2 var byte[13]
    sms var byte[17]
    @ ERRORLEVEL -306
    yellowled var portb.4
    redled var portb.5
    greenled var portb.6

    Include "modedefs.bas"
    EEPROM 200,["+","4","4","7","8","3","2","3","2","3","1","4","6 ","+","4","4","7","9","3","1","2","2","5","2","3", "7"]

    gosub load

    gosub del

    main:
    high portb.6 : pause 30 : low portb.6

    DEBUG "AT^SMGR=1",13
    DEBUGIN 5000,main,[WAIT("UNREAD"),SKIP 3,STR num\13\13,SKIP 27,STR sms\17\13]

    gosub chk : pause 500
    DEBUG "AT+CMGD=1",13
    for a=0 to 15
    num[a]="0" : sms[a]="0"
    next a

    goto main
    Well, see the highlights and draw your conclusions. There is no reason to be writing 0s to eeprom unless you really need it. So, what you've heard is not correct

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,803


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by financecatalyst View Post
    ...
    main:
    high portb.6 : pause 30 : low portb.6

    DEBUG "AT^SMGR=1",13
    DEBUGIN 5000,main,[WAIT("UNREAD"),SKIP 3,STR num\13\13,SKIP 27,STR sms\17\13]
    ...
    Look at the AT^SMGR command. I believe it is typo error. It should be AT+SMGR

    Ioannis

  13. #13


    Did you find this post helpful? Yes | No

    Question

    Hey Ioannis, AT^SMGR is fine, it reads the messege without setting it to REC READ. I think what you are talking about is AT+CMGR. It helps if the messege is not deleted by the AT command, if it sees the unread messege again it will come back to try again to delete it. Else location one will be rendered useless and this messege will stay there untill system restart takes place (but thats my programming).

    Jerson, I will try your solution soon (as soon as I get my monthly text allowance charged again-you wont believe I spent all texts in testing the system) and will update my findings here. Thanks
    ___________________
    WHY things get boring when they work just fine?

  14. #14


    Did you find this post helpful? Yes | No

    Default

    FAO: financecatalyst

    Do you really need to store the "+" in eeprom for the phone numbers?
    can you not just hard code it when you send the SMS data? saves 3 bytes of eeprom and one less byte per number to read back...

  15. #15


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    FAO: financecatalyst

    Do you really need to store the "+" in eeprom for the phone numbers?
    can you not just hard code it when you send the SMS data? saves 3 bytes of eeprom and one less byte per number to read back...
    At my level, its easier for me to grab all and send all. I will try your approach as well it doesn´t work out this way.
    ___________________
    WHY things get boring when they work just fine?

Similar Threads

  1. Problem displaying data from GPS module & using 16f877a
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th April 2010, 10:27
  2. Problem with SMS IO Controller
    By dario.costa in forum GSM
    Replies: 4
    Last Post: - 30th November 2009, 07:04
  3. 16F877A problem: "coupled" digital values
    By Lupo83 in forum General
    Replies: 16
    Last Post: - 4th December 2007, 12:46
  4. sending sms with 16f877A
    By anushka in forum General
    Replies: 1
    Last Post: - 18th January 2007, 11:00
  5. 16F877A serin problem with baud rate 19200
    By leemin in forum Serial
    Replies: 1
    Last Post: - 31st July 2005, 09:45

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts