Scroll text on 7seg. digits with PMP

Well, I had to do it also for Pic Micro Pascal :) . It is the same project as here, the same boards and connection wires (schematic). The difference is in the language and finally, I did the movie which demonstrate zero "ghost" effect.

The schematic

See the link above.

The code

I ported the seven_segment Jallib library and it will be attached at the end of this page. In the program, apart of translation, I changed the text to suit. Again, no big deal in scrolling text on 7segments digits (I don't see it's use) but the same procedure applies to the more appropriate digits which permits indeed displaying the entire set of alphanumeric characters.

program scroll7seg;
{$PROCESSOR PIC18f2550}
{$FREQUENCY 48 MHZ}
{$OPTIMIZE MEMORY}
{$VECTORS RESET = $800, INT_HIGH = $808, INT_LOW = $818}
{$CONFIG OFF}
uses seven_segment, 
tmr0_isr_interval;
const
  text_string: array[0..23] of byte = (// --27 is "Space" character
    27,27,27,23,10,16,12,10,21,27,    //--    PASCAL
    15,22,18,27,                      //-- For
    4,22,26,18,27,                    //-- Your
    26,12,27,27,27                    //-- uC
  ); 
  leds_sequence: array[0..30] of byte = (
    0,1,3,7,15,31,63,127,255,254,252,248,240,224,192,128,0,// complete sequence
    128,192,224,240,248,252,255,127,63,31,15,7,3,1); //and reverse
var
  digits_buffer:array[0..3] of byte;
  //-- indices
  ix_text,ix_led: byte;
procedure PORTTEXT(x:byte); //7segments port: RB0 is segment a
begin                       // Dot segment is not connected
  LATB.0 := x.0;  //seg a
  LATB.1 := x.1;  //seg b
  LATB.2 := x.2;  //seg c
  LATB.3 := x.3;  //seg d
  LATB.4 := x.4;  //seg e
  LATB.5 := x.5;  //seg f
  LATB.6 := x.6;  //seg g
end;
procedure portA_low(x:byte);  //select digits
begin
  LATA.0 := x.0; // select digit nr.4 on EvB4.3 board
  LATA.1 := x.1; // select digit nr.3
  LATA.2 := x.2; // select digit nr.2
  LATA.3 := x.3; // select digit nr.1
end;
procedure show_digits;
begin
  PORTTEXT(seven_from_digit(27));
  portA_low(7);// -- 0b0111, digits are selectable with a 0 logic on my board
  PORTTEXT(digits_buffer[3]);
  delay(1500);
  //--
  PORTTEXT(seven_from_digit(27));
  portA_low(11); //-- 0b1011
  PORTTEXT(digits_buffer[2]);
  delay(1500);
  //--
  PORTTEXT(seven_from_digit(27));
  portA_low(13);// -- 0b1101
  PORTTEXT(digits_buffer[1]);
  delay(1500);
  //--
  PORTTEXT(seven_from_digit(27));
  portA_low(14); //-- 0b1110
  PORTTEXT(digits_buffer[0]);
  delay(1500);
  //--
end;
procedure update_buffer(id: byte);
begin
  digits_buffer[3] := seven_from_digit(text_string[id]);
  digits_buffer[2] := seven_from_digit(text_string[id + 1]);
  digits_buffer[1] := seven_from_digit(text_string[id + 2]);
  digits_buffer[0] := seven_from_digit(text_string[id + 3]);
end;
procedure PORTLED(x:byte);
begin             //FreeJALduino pinout
  LATC.7 := x.0;  //D0  LED nr.1
  LATC.6 := x.1;  //D1  LED nr.2
  LATA.4 := x.2;  //D2  LED nr.3
  LATB.7 := x.3;  //D10 LED nr.4
  LATC.0 := x.4;  //D11 LED nr.5
  LATC.1 := x.5;  //D12 LED nr.6
  LATC.2 := x.6;  //D13 LED nr.7
  LATA.5 := x.7;  //D18 LED nr.8
end;
//-------- START -------------
begin
  //-- Initializations
  TRISA := 0; // as output
  TRISB := 0;
  TRISC := 0;
  //adc_off
  ADCON0 := 0b00000000; // -- disable ADC
  ADCON1 := 0b00001111; // -- digital I/O
  ADCON2 := 0b00000000; //
  //comparator_off
  CMCON  := 0b00000111; // -- disable comparator
  //-- digits OFF
  portA_low(0b1111);
  timer0_isr_init; // -- init timer0 isr
  //-- init index
  ix_text := 0;
  ix_led  := 0;
  //-- fill the digits buffer
  update_buffer(ix_text);
  //-- start LED sequence
  PORTLED(leds_sequence[ix_led]);
  //-- set scroll speed for text
  set_delay(0, 300);
  //-- set scroll speed for LED's
  set_delay(1, 100);
  loop // instead of "while(1) do begin" - new feature ;)
    show_digits;
    if check_delay(0) then begin
      ix_text := ix_text + 1;
      if ix_text = 21 then 
        ix_text := 0;
      update_buffer(ix_text);
      set_delay(0, 300);
    end;
    if check_delay(1) then begin
      ix_led := ix_led + 1;
      if ix_led = 31 then 
        ix_led := 0;
      PORTLED(leds_sequence[ix_led]);
      set_delay(1, 100)
    end;
  end; //loop
end.

Note: It use also the timer0_isr_interval units which can be downloaded at the end of this page.