Forum > Beginners

Write Part of array of char

(1/1)

coradi:
Hallo,
it's not Freepascal, its Mikroe Pascal for AVR Controllers

I have an array of char
sign : array [0..3] OF CHAR;

And will give it out on LCD one part after another for rotating - / - \

LCD_OUT(1,16,sign[0]);


But this till make a failure because simple and complex Type:-(

Ho can I give out a part of an array of char?

Zvoni:
You do realize, that the third parameter is a String?
http://download.mikroe.com/documents/compilers/mikropascal/pic/help/lcd_library.htm#lcd_out

Arioch:
if you want to "rotate" - that is, make first numbers re-appear after last ones - then probably there is no simple way, you just can not copy a pat of array, if you need a circular queue.

you can do something like this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure LCD_OUT_CHAR(const LCD_char_No: byte; Const ch: char);begin ... output one char in a given position.... end; var   sign : array [0..3] OF CHAR;   i, shift: integer; begin   shift := 0; // 1, 2, 3   for i := 0 to 3 do        LCD_OUT_CHAR( i, sign[ (i + shift) mod 4 ]);end; 
Judging by ZVONI's link, you can probably bridge the first funciton as


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure LCD_OUT_CHAR(const LCD_char_No: byte; Const ch: char);begin    Lcd_Chr(     1,  // or whatever row you choose     1 + LCD_char_No,     Ord(ch)  // or byte(ch)    );end; 
But not sure what their starting coordinates are

You can also generalize it somewhat.
in Delphi/FPC it could look like this (not sure how you can adapt it to Mikroe)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$PointerMath ON} procedure LCD_OUT_CHAR(const LCD_char_No: byte; Const ch: char);begin ... output one char in a given position.... end; procedure LCD_OUT_WRAPPED(   const LCD_Length: integer;  // how many letters in LCD   const Array_Length: integer; // how many letters in string   const Array_ptr: PChar  // first leter   const Array_shift: integer;  // n-th letter of string to be put to zero-th place of LCD);var   i: integer;begin   for i := 0 to LCD_Length - 1 do        LCD_OUT_CHAR( i, Array_ptr[ (i + Array_shift) mod Array_Length ]);end;  .... var   sign : array [0..3] OF CHAR;...   LCD_OUT_WRAPPED(12, 4, @sign[0], 2 );  Sleep(1000);  LCD_OUT_WRAPPED(12, 4, @sign[0], 3 );  Sleep(1000);  LCD_OUT_WRAPPED(12, 4, @sign[0], 4 );  
Not sure if C-style "pointer maths" is available in Mikroe, but you an replace it with explicit pointer operations.

Or, using "open array" type of procedure declaration (TurboPascal and compatibles, not sure about Mikroe)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure LCD_OUT_CHAR(const LCD_char_No: byte; Const ch: char);begin ... output one char in a given position.... end; procedure LCD_OUT_WRAPPED(   const LCD_Length: integer;  // how many letters in LCD   const Array_Letters: array of char;  // "open array", has Low(x), High(x), Length(x) implicitly passed   const Array_shift: integer;  // n-th letter of string to be put to zero-th place of LCD);var   i: integer;begin   for i := 0 to LCD_Length - 1 do        LCD_OUT_CHAR( i, Array_Letters[ Low(Array_Letter) + (i + Array_shift) mod Length(Array_Letters) ]);end;  .... var   sign : array [0..3] OF CHAR;...   LCD_OUT_WRAPPED(12, sign, 2 );  Sleep(1000);  LCD_OUT_WRAPPED(12, sign, 3 );  Sleep(1000);  LCD_OUT_WRAPPED(12, sign, 4 ); 

Arioch:
in TP/Delphi/FPC you also could


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  sign : array [0..3] OF CHAR;  s, s1: string; ....s1 := sign[0] + sign[1] + sign[2] + sign[3]; s := s1;LCD_OUT(1,16, s);Sleep(1000); s := Copy( s1, 1+1, 4-1) + Copy(s1, 1, 1);LCD_OUT(1,16, s);Sleep(1000); s := Copy( s1, 1+2, 4-2) + Copy(s1, 1, 2);LCD_OUT(1,16, s); 
This way you have much more memory copying but much less function calls (once per text, not once per letter);

On "big p[erating systems" this would probably be faster, but on embedded it would probably be slower

Navigation

[0] Message Index

Go to full version