Can any one help me to reduce this program's size ??

Beta Testing discussion on mikroPascal.
Post Reply
Author
Message
gafsi
Posts: 2
Joined: 21 Apr 2011 02:51

Can any one help me to reduce this program's size ??

#1 Post by gafsi » 21 Apr 2011 02:59

I've done this program for a 16F876 and it's size is 9ko,so i need to reduce it,any help please ??

Code: Select all

program chariot;
 var i,j,k,n : integer;
 label  boucle1,boucle2,boucle3;

BEGIN
ADCON1:=$06;
TRISA:=$07;
TRISB:=$00;
TRISC:=$0F;
PORTB.0:=0;
Lcd_Init(PORTB);
Lcd_Cmd(Lcd_Clear);
Lcd_Cmd(LCD_CURSOR_OFF);
//////////////////************Etat_1:mode Repos**************/////////////////
while (PORTC.2=0)AND(PORTC.3=0) do
     Begin
      Lcd_Out(1, 6, 'Mode ');
      Lcd_Out(2, 6, 'Repos');

      PORTA.4:=0;
      PORTA.3:=0;
      i:=0;
      j:=0;
      k:=0;
      n:=0;
     end;
////////////************Etat_2:mode forme cylindrique **************///////////
Lcd_Cmd(Lcd_Clear);
while (PORTC.2=1)AND(PORTC.3=0) do
     Begin
     Lcd_Out(1, 6, 'Mode ');
     Lcd_Out(2, 3, 'Cylindrique');

   REPEAT
   PORTA.4:=0;
   PORTA.3:=1;
   UNTIL PORTA.0=1;
   REPEAT
   PORTA.3:=0;
   PORTA.4:=1;
   PORTB.0:=1;
   UNTIL PORTA.2=1;
     end;
/////////////************Etat_3:mode forme Bouteille **************////////////
////////////////////////////differentielle normale////////////////////////////
Lcd_Cmd(Lcd_Clear);
while (PORTC.2=0)AND(PORTC.3=1) do
BEGIN
PORTA.4:=0;
PORTA.3:=0;
i:=0;
j:=0;
k:=0;
     Lcd_Out(1, 5, 'Bouteille ');
     Lcd_Out(2, 5, 'Normale');

REPEAT
   REPEAT
   //PORTB.0:=0;
   PORTA.4:=0;
   PORTA.3:=1;

   UNTIL PORTA.1=1;

     IF j=0 then goto boucle1             //begin PORTB.0:=1;end
    ELSE

       BEGIN
          REPEAT
               if PORTA.0=1 then
                 BEGIN  j:=0;
                        i:=0;
                        k:=0;
                 goto boucle1
                 end;

                IF (PORTC.0=0) AND (PORTC.1=0 ) THEN           Delay_ms(10);
                IF (PORTC.0=1) AND (PORTC.1=0 ) THEN           Delay_ms(20);
                IF (PORTC.0=0) AND (PORTC.1=1 ) THEN           Delay_ms(30);
                IF (PORTC.0=1) AND (PORTC.1=1 ) THEN           Delay_ms(40);

                k:=k+1;
            UNTIL k=i*100;
       END;
      boucle1:
      i:=i+1;   j:=1;  k:=0;
      REPEAT
            PORTA.3:=0;
            PORTA.4:=1;
      UNTIL PORTA.2=1;

UNTIL PORTA.0=1;
      end;
/////////////************Etat_4:mode  forme Bouteille **************////////////
///////////////////////////////quantité maximale///////////////////////////////
Lcd_Cmd(Lcd_Clear);
while ((PORTC.2=1)AND(PORTC.3=1)) do
BEGIN
Lcd_Out(1, 5, 'Bouteille ');
Lcd_Out(2, 5, 'Maximale');
n:=0;
REPEAT
   REPEAT
   //PORTB.0:=0;
   //IF PORTA.2=1  THEN
   PORTA.4:=0;
   PORTA.3:=1;

   UNTIL PORTA.1=1;

     IF j=0 then goto boucle2             //begin PORTB.0:=1;end
    ELSE

       BEGIN
          REPEAT
               if PORTA.0=1 then
                 BEGIN  j:=0;
                        i:=0;
                        k:=0;
                 goto boucle3
                 end;

                IF (PORTC.0=0) AND (PORTC.1=0 ) THEN           Delay_ms(10);
                IF (PORTC.0=1) AND (PORTC.1=0 ) THEN           Delay_ms(20);
                IF (PORTC.0=0) AND (PORTC.1=1 ) THEN           Delay_ms(30);
                IF (PORTC.0=1) AND (PORTC.1=1 ) THEN           Delay_ms(40);

                k:=k+1;
            UNTIL k=i*100;
       END;

boucle2:
      i:=i+1;   j:=1;  k:=0;
      REPEAT
            PORTA.3:=0;
            PORTA.4:=1;
      UNTIL PORTA.2=1;

UNTIL PORTA.0=1;

boucle3:
REPEAT
REPEAT
   PORTA.4:=0;
   PORTA.3:=1;
   PORTB.0:=1;
   UNTIL PORTA.0=1;
 REPEAT
            PORTA.3:=0;
            PORTA.4:=1;
      PORTB.0:=0;
      UNTIL PORTA.2=1;
 n:=n+1;
UNTIL n=5;
     end;

end.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: Can any one help me to reduce this program's size ??

#2 Post by jpc » 21 Apr 2011 08:26

the very first you may do is move to the pro-compiler, this is more efficient, code will be more compact.You will have to make minor changes but it looks like it compiles to less than 1 kB.
This is hardly the right place on the forum for this post btw, the beta-section of the old compiler should be rather silent these days.
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “mikroPascal Beta Testing”