PDA

View Full Version : suggest optimize code



xxxxxx
- 19th March 2009, 09:06
helllo

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


'************************************************* ***************
'* 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

Ioannis
- 19th March 2009, 12:16
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:


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:



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

xxxxxx
- 19th March 2009, 14:32
okay i'm going to tray it, and the next idea is:




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!:D


.......and i almost forgot!!! thx ioannis :D

xxxxxx
- 19th March 2009, 14:39
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?

Ioannis
- 19th March 2009, 19:24
Why not compare array to EEPROM?

Ioannis

xxxxxx
- 20th March 2009, 09:38
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....

Ioannis
- 20th March 2009, 13:24
Not surprised :-)

Ioannis