PDA

View Full Version : how to hserin compare with known value?



aa222k
- 22nd November 2010, 14:19
hi all ,
this is my first post and i hope help from all .My problem is i can not compare my file my file is
$07 $06 $0D $CA $2E $56 $00 $C9 $77 .when this file recive i want flash led portc.3 on with pic16f688. i get corect boud 115200 with crystal 11.0592 Mhz i also check hserin and hserout
same. my code is below

@ DEVICE PIC16F688, HS_OSC, WDT_OFF, PWRT_OFF, MCLR_OFF, BOD_OFF,PROTECT_OFF
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 5 ' 115200 Baud @ 11.0592MHz, 0.0%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 5 ' 115200 Baud @ 11.0592MHz, 0.0%
ANSEL = 0 'ALL DIGITAL
INTCON = 0 'Disable interrupts
DATAIN VAR byte[9]
main:
HSERIN [WAIT($07), str DATAIN\8]
'if datain = $07,$06,$0D,$CA,$2E,$56,$00,$C9,$77
hserout [str datain\9]

goto main
END
sorry for my english

pedja089
- 22nd November 2010, 15:26
Try something like this

HSERIN [WAIT($07), str DATAIN\8]
if datain[0] = $07 and datain[1] =$06 and datain[2] =$0D and datain[3] =$CA and datain[4] =$2E and datain[5] =$56 and datain[6] =$00 and datain[7] =$C9 and datain[8] =$77 then hserout [str datain\8]
or this


str[0]= $07:.....:str[7]=$77
HSERIN [WAIT($07), str DATAIN\8]
for i = 0 to 8
IF str[i]<>datain[i] then goto DO_NOT_SEND
next i
hserout [str datain\8]
do_not_send:

aa222k
- 22nd November 2010, 15:50
first of all many thanks for repply dear pedja089
now my code like this,

main:
HSERIN [WAIT($07), str DATAIN\8]
if datain[1] = $06 then high portc.3
hserout [str datain\8]
goto main
END

this not working

pedja089
- 22nd November 2010, 15:57
Datain[1] is second byte in string.
If you wait number 7, then that byte isn't in datain array.
If you sent 7,6,12, then in datain first byte is 6, second is 12, so you need something like this

HSERIN [WAIT($07), str DATAIN\8]
if datain[0] = $06 then high portc.3

And now if you send 7,then 6, and 6 more byte portc will go high.

aa222k
- 22nd November 2010, 17:19
many many thanks dear pedja089
now code is working
what methed in short becuse i have too bytes for compare for example
hex :07 06 00 82 2D A1 00 D7 D8 , 07 06 00 82 2D CF 35 C4 90 , 07 06 00 82 2E 2F 35 C4 73 , many more ,so
i want further help?

pedja089
- 22nd November 2010, 21:34
Try both ways and see which is faster.

aa222k
- 23rd November 2010, 18:48
thanks ,
now i want write this 9 byte data and read its back .How this posible my mean how to write aray and read it again.
Regards