suggest optimize code


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Posts
    48

    Default suggest optimize code

    helllo

    if someone have a suggestion to optimize this code pleasa reply to this thread!!

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 20/02/2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : sms controler nokia 6210 i pic 16F887             *
    '*          :                                                   *
    '****************************************************************
    
    '
    'pic defines
    '------------------------------------------------------------------------
    	@ DEVICE pic16F887, WDT_OFF        ' Watchdog Timer
    	@ DEVICE pic16F887, PWRT_ON        ' Power-On Timer
    	@ DEVICE pic16F887, MCLR_ON        ' Master Clear Options (Internal)
    	@ DEVICE pic16F887, BOD_ON         ' Brown-Out Detect
    	@ DEVICE pic16F887, LVP_OFF        ' Low-Voltage Programming
    	@ DEVICE pic16F887, CPD_OFF        ' Data Memory Code Protect
    	@ DEVICE pic16F887, PROTECT_OFF    ' Program Code Protection
    '
    'konfigurisi AN pinove kao digital I/O
    '------------------------------------------------------------------------
    
    ansel=$00
    anselh=$00
    
    '
    ' Definisanje hser-a (transmit-recive) i lcd-a u 4 bitnom modu
    '------------------------------------------------------------------------ 
    define OSC 4
    DEFINE HSER_SPBRG 25
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1
    DEFINE LCD_BITS 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_LINES 2
    
    '
    'definisanje varijabli
    '------------------------------------------------------------------------
    PORUKA VAR BYTE[5]
    TELBR VAR BYTE[12]
    TIME VAR BYTE [5]
    klima var byte
    
    J VAR BYTE
    I VAR BYTE 
    
    
    '
    ' inicijalizacija
    '-----------------------------------------------------------------------
    HIGH PORTB.7
    PAUSE 4000
    LOW PORTB.7
    
    
    ' provjeri nove poruke
    
    pocetak:
    HSerout ["ATZ",13,10]' pocni komunikaciju
    HSERIN 2000,pocetak,[WAIT("OK")]
         LCDoUT $FE,1,"  aktiviraj"
         LCDoUT $FE,$C0,"  uredjaj"
         pause 1000
    
    textmod:
    HSerout ["AT+CMGF=1",13,10]'postavi text mod
    HSERIN 2000,textmod,[WAIT("OK")]
    mem:
    HSEROUT["AT+CPMS=",34,"SM",34,13,10]' ciljana memory lokacija
    HSERIN 2000,mem,[WAIT("OK")]
    
    IP:
    
    HSEROUT["AT+CMGL",13,10]' filter za query
        LCDOUT $FE,1,"trazi poruke.."
    
    HSERIN 5000,IP,[WAIT("REC UNREAD"),skip 2,str TELBR\12,skip 13,str TIME\5,skip 9,STR PORUKA\5\13] 
        LCDOUT $FE,1
    
    I=0
    
    klima[1]="O"
    klima[2]="N"
    klima[3]="K"  
    if poruka[i+1]=klima[i+1] and poruka[i+2]=klima[i+2]and poruka[i+3]=klima[i+3] then  gosub saljisms
    
    J=0
    
    klima[1]="O"
    klima[2]="F"
    klima[3]="F"
    klima[4]="K"
    if poruka[j+1]=klima[j+1] and poruka[j+2]=klima[j+2]and poruka[j+3]=klima[j+3] and poruka[j+4]=klima[j+4] then  gosub saljisms
    
    
    '
    ' brisanje poruke iz memeorije
    ' ------------------------------------------------------------
    MEM2:
    HSEROUT["AT+CPMS=",34,"SM",34,13,10]' ciljana memory lokacija
    HSERIN 2000,mem2,[WAIT("OK")]
    
    del2:
    HSEROUT["AT+CMGD=1",13,10]
    HSERIN 2000,del2,[WAIT("OK")]
            LCDOUT $FE,1,"PORUKA ODBRISANA"
            pause 1500
    GOTO IP
    
    '
    'subrutines
    '---------------------------------------------------------------
    
    '
    'subrutina za u-i potrosca i obavjest korisnika o poduzetoj akciji
    '---------------------------------------------------------------
    
    saljisms:
    high portb.6
    HSerout ["AT",13,10]
           Pause 1000
    
    HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode
           Pause 1000
    
    HSerout ["AT+CMGS=",34,"+38761xxxxxx",34,",129",13,10]
           Pause 1000
    HSerout [str poruka,str time,10,13]
    HSerout [26]
           Pause 1000
    RETURN
    
    End
    thx in advance
    Last edited by xxxxxx; - 19th March 2009 at 10:02.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    I don't think this will work. You need to declare klima as array and not just variable.

    Also Arrays start from 0 so you have to start as klima[0] instead of klima[1].

    More, line:
    Code:
    if poruka[j+1]=klima[j+1] and poruka[j+2]=klima[j+2]and poruka[j+3]=klima[j+3] and poruka[j+4]=klima[j+4] then  gosub saljisms
    maybe compiles less with this:

    Code:
    if poruka[j+0]=klima[j+0] then 
        if poruka[j+1]=klima[j+1 then 
             if poruka[j+2]=klima[j+2] then
                if poruka[j+3]=klima[j+3] then
                     gosub saljisms
                endif
             endif
        endif
    endif

  3. #3
    Join Date
    Mar 2009
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    okay i'm going to tray it, and the next idea is:


    Code:
    testmesage=1
    FOR I=0 to 3  
        if poruka[i+1]<>klima[i+1] then testmesage=0
    next i
    
    if testmesage=1 then gosub saljisms
    poruka[0] is a blank space, so i don't need it, and i'm gona define klima as array and give it a shot!


    .......and i almost forgot!!! thx ioannis
    Last edited by xxxxxx; - 19th March 2009 at 14:41.

  4. #4
    Join Date
    Mar 2009
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    and next question if i put klima in eeprom using DATA command how can i call it in my program to qompare it with some other variable's?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Why not compare array to EEPROM?

    Ioannis

  6. #6
    Join Date
    Mar 2009
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Code:
    testmesage=1
    FOR I=0 to 3  
        if poruka[i+1]<>klima[i+1] then testmesage=0
    next i
    
    if testmesage=1 then gosub saljisms
    this one works fine and compiles less....

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Not surprised :-)

    Ioannis

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

Members who have read this thread : 0

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