View previous topic :: View next topic |
Author |
Message |
ztardik
Joined: 08 Apr 2008 Posts: 15
|
Posted: Sun Feb 14, 2010 3:00 pm Post subject: Prinbin array |
|
|
Hi!
I have a problem with printbin function. If I use variable as parameter it allways print the whole array.
Printbin #1 , out_buf(1) ; out_cnt - print 127 bytes
Printbin #1 , out_buf(1) ; 6 - print 6 bytes
I checked the out_cnt variable, it has the correct value before calling the printbin function.
Bascom is 1.11.9.5
Code: | $regfile = "m128def.dat" ' chip used
$crystal = 11059200
Config Com2 = 9600 , Synchrone = 0 , Parity = Even , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com2:" For Binary As #1
Dim out_buf(127) As Byte
Dim out_cnt As Byte
out_buf(1)=1
out_buf(2)=2
out_buf(3)=3
out_buf(4)=4
out_buf(5)=5
out_buf(6)=6
out_cnt=6
do
Printbin #1 , out_buf(1) ; out_cnt
waitms 1000
Printbin #1 , out_buf(1) ; 6
waitms 1000
loop |
|
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Feb 14, 2010 4:19 pm Post subject: |
|
|
Hi,
try this setup of com2
Code: | $regfile = "m128def.dat" ' chip used
$crystal = 11059200
'Config the 2nd Serial Port
$baud1 = 9600
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'Now Open the serial port
Open "com2:" For Random As #1
Dim out_buf(127) As Byte
Dim out_cnt As Byte
out_buf(1)=1
out_buf(2)=2
out_buf(3)=3
out_buf(4)=4
out_buf(5)=5
out_buf(6)=6
out_cnt=6
do
Printbin #1 , out_buf(1) ; out_cnt
waitms 1000
Printbin #1 , Out_buf(1) ; 6 ' send 6
waitms 1000
loop |
_________________ / Kim |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Sun Feb 14, 2010 4:56 pm Post subject: |
|
|
When you use an array in PRINTBIN, then you have to specify the number of data to be printed. Otherwise it prints the complete array! Look at "PRINTBIN" help file.
Hubert |
|
Back to top |
|
|
for_ro
Joined: 11 Nov 2007 Posts: 260
|
Posted: Sun Feb 14, 2010 5:53 pm Post subject: Re: Prinbin array |
|
|
Hi ztardik,
ztardik wrote: |
Printbin #1 , out_buf(1) ; out_cnt |
Unfortunately the Printbin command doesn't allow the number of elements to be printed given as a variable, only constants are used.
That's why
Printbin #1 , out_buf(1) ; 6
does work.
In your code, the content of the variable out_cnt will be printed after the whole array is finished.
If you want to print a variable number of elements of the array, you need to do it via a for-loop like
For I = 1 To out_cnt
Printbin #1, out_buf(i);1
Next I |
|
Back to top |
|
|
ztardik
Joined: 08 Apr 2008 Posts: 15
|
Posted: Mon Feb 15, 2010 10:53 am Post subject: Re: Prinbin array |
|
|
Hi everyone!
kimmi:
If i understand your code correctly, that will only tell the compiler to use same baud rate as COM1. Serial port is not an issue, but printbin.
hgrueneis:
Thanks, I always RTFM first, but the help is not so helpful as it should be. Or I just misread it.
for_ro:
Did it that way already. But it's a workaround, not a solution.
I read the help one more time, and could not find anywhere that it accepts only constant.
Quote from online help http://avrhelp.mcselec.com/index.html?printbin.htm
Quote: | Syntax
PRINTBIN var [ ; varn]
PRINTBIN #channel, var [; varn]
Remarks
Var - The variable which value is send to the serial port.
varn - Optional variables to send. |
|
|
Back to top |
|
|
for_ro
Joined: 11 Nov 2007 Posts: 260
|
Posted: Mon Feb 15, 2010 12:02 pm Post subject: Re: Prinbin array |
|
|
ztardik wrote: |
Did it that way already. But it's a workaround, not a solution.
|
Hi ztardik,
the additional numeric parameter is an option to let you print a fixed portion of an array. It is known at compile time, using a variable it wouldn't.
With this directive the compiler can separate between a number, which defines how many elements to print and the number, which you want to print.
So it is actually not a workaround, it is as it is. |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon Feb 15, 2010 12:56 pm Post subject: |
|
|
You can always make your own;
Code: |
For Lus = 1 To Out_cnt
Printbin #1 , Out_buf(lus) ; 1
Next Lus
|
_________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Feb 15, 2010 2:51 pm Post subject: |
|
|
Or you can take my version, which extends the functionality of PrintBin Basically it's a rebuilt of the original function and can handle more than 256 Bytes.
As it's not seemlessly integrated into the compiler, it needs its 3 UART constants adjusted. And of course those who wish not to meddle with assembler will better use Evert's version, which is straight and clean.
Code: | $regfile = "m128def.dat"
Dim A(10) As Byte , C As Byte , Bc As Word
Declare Sub Printbin_var(arr_adr As Byte , Byval Cnt As Word) ' Print cnt bytes from array arr_adr
For C = 1 To 10
A(c) = C
Next
Printbin_var A(1) , 2
Bc = 5
Printbin_var A(1) , Bc
End
Sub Printbin_var(arr_adr As Byte , Cnt As Word)
$asm
MOVW ZL, YL
LD XL, Z+
LD XH, Z+
LD R24, X+
LD R25, X
LD XL, Z+
LD XH, Z+
!UART_Get_Next_Byte:
LD R20, X+
!UART_Not_Ready:
LDS R0, UCSR1A ' In case a different UART than Com2 is used, change UCSR1A accordingly
SBRS R0, UDRE1 ' same for UDRE1
RJMP UART_Not_Ready
STS Udr1, R20 ' and same for UDR1
SBIW R24, 1
BRNE UART_Get_Next_Byte
$end Asm
End Sub
|
But it |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon Feb 15, 2010 3:03 pm Post subject: |
|
|
Hi MWS,
Are you aware of the CONFIG PRINTBIN = extended option?
It allows you to work with more then 255 bytes.
Needs Bascom > 1.11.94. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Feb 15, 2010 3:33 pm Post subject: |
|
|
Hi Evert,
I'm aware of the extended option, thanks. My focus was a function as close as possible to the original PrintBin, but with an ajustable bytecount, the option to send more than 256 bytes came out just by the way.
Ludwig |
|
Back to top |
|
|
Madf
Joined: 13 Nov 2011 Posts: 179 Location: Moscow
|
Posted: Tue Aug 14, 2012 12:30 pm Post subject: |
|
|
hello.
not want to create a new topic, I will ask here.
assistance in printbin no mistake? it says:
Quote: | Printbin ar(1) ; 2 ; ar(2) ; 4 ' will send 2 bytes from array ar() starting at index 1, then 4 bytes from array ar() starting at index 4. |
bold text I selected a place of interest to me.
Did not mean "ar(2) ; 4 - then 4 bytes from array ar() starting at index 2"?
typo 4 in 2? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Aug 14, 2012 10:01 pm Post subject: |
|
|
yes, that is a typo. that must be 2. _________________ Mark |
|
Back to top |
|
|
Madf
Joined: 13 Nov 2011 Posts: 179 Location: Moscow
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Aug 16, 2012 9:40 pm Post subject: |
|
|
if there are 10 users that reply that they want it, i can add a new printbin variant that will work simpler : printbinB ar(index), bytes ; othervar , 4
So this would not send whole array, only specified amount of bytes. _________________ Mark |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Thu Aug 16, 2012 11:35 pm Post subject: |
|
|
Personally I would resist the temptation to add more and more complexity to commands. It takes about as long to look up the exact syntax and conditions of use of some little-used command, as it does to use the existing language flexibility ( write a simple loop, in this case ) to do this type of job. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
|