Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

bytematch change in running programm

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
kempol

Bascom Member



Joined: 27 Sep 2010
Posts: 5

poland.gif
PostPosted: Sat Jul 15, 2017 8:39 am    Post subject: bytematch change in running programm Reply with quote

Hi

Is there a chance to change bytematch in running code?
By change I mean something like this:

Code:

Select Case A

Case 0

   Config Serialin1 = Buffered , Size = 202 , Bytematch = All

Case 1

   Config Serialin1 = Buffered , Size = 202 , Bytematch = 10       '10 = Lf, 13 = Cr

End Select
 


Of course above example will not work, but I'm wondering if it is possible to do something similar.
I have a project with different type of data (binary and ascii) and I would like to receive them on the same port which I can configure by simple DIP switch.

Thanks.[/quote]

(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4369
Location: Holland

blank.gif
PostPosted: Sat Jul 15, 2017 8:38 pm    Post subject: Reply with quote

it will not work because of this code in mcs.lib


* Cpi r25,_CHECHCHAR0_char ;check with char to compare

but you could change it and put [_GOTCHAR0] in a custom lib with code like:
*lds r16,{YOURBYTE}
* CP r25, R16 ;check with char to compare


then you need to dim YOURBYTE as a byte and assign it a value of your choice.

We could integrate it as a new option in the compiler but you need to discuss that at support.

_________________
Best regards,

Mark Alberts
MCS Electronics

http://www.mcselec.com
Back to top
View user's profile Visit poster's website
AdrianJ

Bascom Member



Joined: 16 Jan 2006
Posts: 2402
Location: Queensland

australia.gif
PostPosted: Mon Jul 17, 2017 8:20 am    Post subject: Reply with quote

Of course you can do this in the library function, as Mark suggests.

But you can just as easily do it in running code, rather than in the config. And this gives you a lot more flexibility to handle all sorts of characters in the incoming stream.
Code:

while ischarwaiting() = 1 'character in buffer
bt = inkey()  'get the character as a byte
select case A 'your selection from external switch
 case 0
'... do whatever you want with bt as binary
case 1
'... do the alternate as ascii
 select case bt 'get the value
 case 10  'pick out the LF
' ... do whatever you want with the LF
 case ... anything else you want to handle specially, just create another case for it

 case else 'all other characters
'... put them in string, or whatever
 end select
end select

end while
 

Bascom is plenty fast enough to handle all sorts of constructions like this, and process characters one by one as they come in, especially when using buffered serial input.
If you do a search on the forum for "NMEA" you will find several examples using this to decode NMEA strings passed from GPS units. But the technique can be applied to almost anything.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
laborratte

Bascom Member



Joined: 27 Jul 2005
Posts: 215
Location: Berlin

germany.gif
PostPosted: Mon Jul 17, 2017 1:28 pm    Post subject: Reply with quote

Third option: use BYTEMATCH = ALL and check the received byte in your sub:
Code:

Config Serialin1 = Buffered , Size = 202 , Bytematch = All
dim MyMatch as byte
(...)
MyMatch = 10 'or what you want
(...)

Serial1ByteReceived:
'r25 holds the received byte (Bascom Version 2.0.8.0, check mcs.lib if any doubt)
'r16 can be used as the content is no longer necessary
$asm
   lds r16,{MyMatch} 'load variable MyMatch to Register R16
   cp r25,r16           'Compare received Byte with MyMatch
   breq Serial1ByteReceived_Matched  'If equal, jump to "Serial1ByteReceived_Matched"
   ret 'Fast back to buffered serial in
$end asm

Serial1ByteReceived_Matched:
  pushall
  (...) 'your code
  popall
return
 


So you have fast buffered serial in and you do not need to write your own lib.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum