View previous topic :: View next topic |
Author |
Message |
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Sat Apr 27, 2019 5:07 pm Post subject: Print Array |
|
|
Hello !
Why when printing an array the number of characters to print must be a numeric constant and not a variable?
Let me explain, Printbin # 3, 4d_string_tx_arr (1); 8, print 8 characters
While :
A = 8
Printbin # 3, 4d_string_tx_arr (1); A, do not work!
It will facilitate many things, no!
Bernard
(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.8.1 ) |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Sat Apr 27, 2019 7:55 pm Post subject: |
|
|
HI Bernard,
it must be a constant.
that is why whole sub 4d_write_str(byval 4d_str_indx As Byte , Byval 4d_string_tmp As String ) has so many select case in it.
Also that's why the string limit is set to 32.
Code: | Sub 4d_write_str(byval 4d_str_indx As Byte , Byval 4d_string_tmp As String )
'the body of the command is:
'code + string_index+ string_length + string + xorcrc
Local Index_help_a As Byte 'used to calculate the lengt of the string
Local Index_help_b As Byte 'used to calculate position of the XOR CRC in array, string length+3
'Local Str_tmp_len As Byte 'used for calculating the length before adding CR or LF
Dim Tot_command_len As Byte 'total comand length
'******************************************************************************
'******************************************************************************
'Str_tmp_len = Len(4d_string_tmp) + 1 'get the length of the original string
Tot_command_len = Len(4d_string_tmp) + 4 'string length(+) commad (+) string index (+) string
4d_string_tx = 4d_string_tmp 'copy the string in to variable overlayd at array
4d_string_tx_arr(1) = Write_str '&h02 write string command
4d_string_tx_arr(2) = 4d_str_indx 'index of the string
4d_string_tx_arr(3) = Len(4d_string_tmp) 'length of the string
For Index_help_a = 1 To Tot_command_len -1 'we need to xor this and asign at the end
'the minus (-)1 skip xor of the null termination
4d_string_tx_arr(tot_command_len) = 4d_string_tx_arr(tot_command_len) Xor 4d_string_tx_arr(index_help_a)
Next Index_help_a
Select Case Tot_command_len ' total comand length
Case 5:
Printbin #1 , 4d_string_tx_arr(1) ; 5 'code +string index+ string length + 1 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 5 'code +string index+ string length + 1 char + crc
Case 6:
Printbin #1 , 4d_string_tx_arr(1) ; 6 'code +string index+ string length + 2 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 6 'code +string index+ string length + 2 char + crc
Case 7:
Printbin #1 , 4d_string_tx_arr(1) ; 7 'code +string index+ string length + 3 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 7 'code +string index+ string length + 3 char + crc
Case 8:
Printbin #1 , 4d_string_tx_arr(1) ; 8 'code +string index+ string length + 4 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 8 'code +string index+ string length + 4 char + crc
Case 9:
Printbin #1 , 4d_string_tx_arr(1) ; 9 'code +string index+ string length + 5 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) , 9 'code +string index+ string length + 5 char + crc
Case 10:
Printbin #1 , 4d_string_tx_arr(1) ; 10 'code +string index+ string length + 6 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 10 'code +string index+ string length + 6 char + crc
Case 11:
Printbin #1 , 4d_string_tx_arr(1) ; 11 'code +string index+ string length + 7 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 11 'code +string index+ string length + 7 char + crc
Case 12:
Printbin #1 , 4d_string_tx_arr(1) ; 12 'code +string index+ string length + 8 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 12 'code +string index+ string length + 8 char + crc
Case 13:
Printbin #1 , 4d_string_tx_arr(1) ; 13 'code +string index+ string length + 9 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 13 'code +string index+ string length + 9 char + crc
Case 14:
Printbin #1 , 4d_string_tx_arr(1) ; 14 'code +string index+ string length + 10 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 14 'code +string index+ string length + 10 char + crc
Case 15:
Printbin #1 , 4d_string_tx_arr(1) ; 15 'code +string index+ string length + 11 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 15 'code +string index+ string length + 11 char + crc
Case 16:
Printbin #1 , 4d_string_tx_arr(1) ; 16 'code +string index+ string length + 12 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 16 'code +string index+ string length + 12 char + crc
Case 17:
Printbin #1 , 4d_string_tx_arr(1) ; 17 'code +string index+ string length + 13 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 17 'code +string index+ string length + 13 char + crc
Case 18:
Printbin #1 , 4d_string_tx_arr(1) ; 18 'code +string index+ string length + 14 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 18 'code +string index+ string length + 14 char + crc
Case 19:
Printbin #1 , 4d_string_tx_arr(1) ; 19 'code +string index+ string length + 15 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 19 'code +string index+ string length + 15 char + crc
Case 20:
Printbin #1 , 4d_string_tx_arr(1) ; 20 'code +string index+ string length + 16 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 20 'code +string index+ string length + 16 char + crc
Case 21:
Printbin #1 , 4d_string_tx_arr(1) ; 21 'code +string index+ string length + 17 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 21 'code +string index+ string length + 17 char + crc
Case 22:
Printbin #1 , 4d_string_tx_arr(1) ; 22 'code +string index+ string length + 18 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 22 'code +string index+ string length + 18 char + crc
Case 23:
Printbin #1 , 4d_string_tx_arr(1) ; 23 'code +string index+ string length + 19 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 23 'code +string index+ string length + 19 char + crc
Case 24:
Printbin #1 , 4d_string_tx_arr(1) ; 24 'code +string index+ string length + 20 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 24 'code +string index+ string length + 20 char + crc
Case 25:
Printbin #1 , 4d_string_tx_arr(1) ; 25 'code +string index+ string length + 21 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 25 'code +string index+ string length + 21 char + crc
Case 26:
Printbin #1 , 4d_string_tx_arr(1) ; 26 'code +string index+ string length + 22 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 26 'code +string index+ string length + 22 char + crc
Case 27:
Printbin #1 , 4d_string_tx_arr(1) ; 27 'code +string index+ string length + 23 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 27 'code +string index+ string length + 23 char + crc
Case 28:
Printbin #1 , 4d_string_tx_arr(1) ; 28 'code +string index+ string length + 24 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 28 'code +string index+ string length + 24 char + crc
Case 29:
Printbin #1 , 4d_string_tx_arr(1) ; 29 'code +string index+ string length + 25 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 29 'code +string index+ string length + 25 char + crc
Case 30:
Printbin #1 , 4d_string_tx_arr(1) ; 30 'code +string index+ string length + 26 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 30 'code +string index+ string length + 26 char + crc
Case 31:
Printbin #1 , 4d_string_tx_arr(1) ; 31 'code +string index+ string length + 27 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 31 'code +string index+ string length + 27 char + crc
Case 32:
Printbin #1 , 4d_string_tx_arr(1) ; 32 'code +string index+ string length + 28 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 32 'code +string index+ string length + 28 char + crc
Case 33:
Printbin #1 , 4d_string_tx_arr(1) ; 33 'code +string index+ string length + 29 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 33 'code +string index+ string length + 29 char + crc
Case 34:
Printbin #1 , 4d_string_tx_arr(1) ; 34 'code +string index+ string length + 30 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 34 'code +string index+ string length + 30 char + crc
Case 35:
Printbin #1 , 4d_string_tx_arr(1) ; 35 'code +string index+ string length + 31 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 35 'code +string index+ string length + 31 char + crc
Case 36:
Printbin #1 , 4d_string_tx_arr(1) ; 36 'code +string index+ string length + 32 char + crc
Printbin #lcd_4d , 4d_string_tx_arr(1) ; 36 'code +string index+ string length + 32 char + crc
End Select
End Sub
|
Mark has mentioned he will add new command in to next version so we could use variable there. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Apr 27, 2019 7:55 pm Post subject: |
|
|
you really should read the help. it is documented.
the reason is simple, it is by design. The first version was intended to print the entire content of a variable or array.
a later version added support for specific number of bytes but using a kind of work around : using a constant
A variable would be seen as another variable to print the content so that was not possible.
that said a better alternative was found using a comma to specify the number of bytes but that will be in 2082 after it has been tested properly. _________________ Mark |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Sat Apr 27, 2019 7:57 pm Post subject: |
|
|
Perfect timing |
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Sat Apr 27, 2019 8:06 pm Post subject: |
|
|
This is good news !!
very good weekend Bernard |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Sat Apr 27, 2019 8:33 pm Post subject: |
|
|
@bellon for the Mega2560 you can test this function. It is some mix from oryginal printbin
Im using it for MQTT arrays. This is the version where you can pass address of the array. My previous was simpler (only one array in the code).
..and for second USART you need change UCSR0A, UDRE0 and UDR0 into UCSR1A, UDRE1 and UDR1.
Maybe this will be helpful
Code: | $regfile = "m2560def.dat" '256K FLASH, 8K SRAM, 4K EEPROM
$crystal = 16000000
$hwstack = 128
$swstack = 128
$framesize = 255
$sim
Config Submode = New
Dim Mybuff(10) As Byte , N As Byte
Dim Somebuff(10) As Byte
Sub Print_bin(byref Buffer(1) As Byte , Byval Quantity As Byte)
R19 = Quantity
!ldd r26,Y+2 ; load address of Buffer(1) passed by reference
!ldd r27,Y+3
Start_point2:
!LD R24, x+
Wait_for_empty2:
!LDS R0, UCSR0A
!SBRS R0, UDRE0
!RJMP Wait_for_empty2
!STS UDR0, R24
!DEC R19
!BRBC 1,Start_point2
End Sub
'fill buffer with A,B,C,D...
For N = 1 To 10
Mybuff(n) = N + 64
Next
'fill somebuff with 1,2,3,4...
For N = 1 To 10
Somebuff(n) = N + 47
Next
N = 8
Call Print_bin(mybuff(1) , N)
N = 10 : Print "" 'new line
Call Print_bin(somebuff(1) , N)
End
|
|
|
Back to top |
|
|
bellon
Joined: 01 Mar 2019 Posts: 31
|
Posted: Sat Apr 27, 2019 9:24 pm Post subject: |
|
|
@EDC
Thank you for the proposal, I will try it!
I see that in your simulator there is UART0-1-2-3, what is this version?
Thank you all! |
|
Back to top |
|
|
Pikczu
Joined: 22 Jan 2006 Posts: 72 Location: Dublin, Ireland
|
Posted: Sat Apr 27, 2019 9:35 pm Post subject: |
|
|
The latest 2.0.8.1 |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Sun Apr 28, 2019 3:46 am Post subject: |
|
|
So what is wrong with ?
Code: |
a = 8
for i = 1 to a
Printbin # 3, 4d_string_tx_arr (1)
next
|
_________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
|
|
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
|
|