12F675 C v's P

General discussion on mikroC.
Post Reply
Author
Message
Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

12F675 C v's P

#1 Post by Storic » 09 Jul 2005 00:44

Hi,
I wrote a simple code Analog in to control 4 x outputs at different levels. in both mP and mC both work well. (12F675 int OSC)
>mP compiled to 274 bytes of ROM 9 bytes of RAM :(
>mC compiled to 186 bytes of ROM 9 bytes of RAM :)

mC

Code: Select all

unsigned temp;

void main() {

  GPIO = 0;
  CMCON = 7;
  TRISIO = 0x0C;                     // designate gpio 001100
  TRISIO.ANS2 = 1;                  // pin ANS2 as input
  ADCON0.VCFG = 0;                  // Vdd as Vref

  do {                              // beginning of a repeat loop
    temp = Adc_Read(ANS2);        // ADC conversion
    if (!GPIO.F3)  {
      if (temp > 900)  {
          GPIO = 0;
          GPIO.F0 = 1;
      }
      else
      if  (temp > 600) {
          GPIO = 0;
          GPIO.F1 = 1;
      }
      else
      if  (temp > 400) {
          GPIO = 0;
          GPIO.F4 = 1;
      }
      else
          if (temp > 200) {
          GPIO = 0;
          GPIO.F5 = 1;
      }
    }
  } while (1);                       // endless loop (as this condition is never satisfied)
}//~
mP

Code: Select all

program AC_ISR;

var temp : word;

begin
  GPIO := 0;
  CMCON := 7;
  TRISIO := $0C;           // designate gpio 001100
  SetBit(TRISIO,ANS2);   // pin ANS2 as input
  ClearBit(ADCON0,VCFG); // Vdd as Vref
  repeat                // beginning of a repeat loop
    begin
      temp:=ADC_read(ANS2);     // ADC conversion
      if testbit(GPIO,3) = 0 then
      begin
        if temp > 900 then
        begin
          GPIO := 0;
          Setbit(GPIO,0);
        end
        else
        if  temp > 600 then
        begin
          GPIO := 0;
          Setbit(GPIO,1);
        end
        else
        if  temp > 400 then
        begin
          GPIO := 0;
          Setbit(GPIO,4);
        end
        else
        if  temp > 200 then
        begin
          GPIO := 0;
          Setbit(GPIO,5);
        end;
      end;
    end;
  until 0 = 1;         // endless loop (as this condition is never satisfied)
end.
Andrew

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

#2 Post by LGR » 09 Jul 2005 01:32

One obvious difference is the use of port.pin in C v.s. setbit/clearbit in Pascal. Pascal 3.xx has port.pin. Try converting the Pascal program to use port.pin, and see what happens.
If you know what you're doing, you're not learning anything.

Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

#3 Post by Storic » 09 Jul 2005 04:13

Hi,
I reprogram replacing the Setbit(GPIO,x) with GPIO.x := 1 and I compile ROM is still 274 bytes. :(

Setbit(GPIO,0); => GPIO.0 := 1;


Andrew

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

#4 Post by LGR » 09 Jul 2005 04:29

It would be interesting to compare the ASM listings. This shouldn't be. The languages are supposed to be same compiler with different syntax tables. Maybe not. Or maybe there's something very fluky in this instance. :?
If you know what you're doing, you're not learning anything.

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

#5 Post by pizon » 09 Jul 2005 21:10

LGR wrote:The languages are supposed to be same compiler with different syntax tables.
Well, they are not. ANSI C - compliant language just has too many differences compared to Pascal, to be able to treat them the same way (pointer usage, casting, unary operators, mixing conditional and set statements, arithmetical and logical operators, operator precedence, addressing arithmetics... :x). Usually, Pascal produces nicer code thanks to its simpler and cleaner semantics, so this situation is puzzling to us as well. Anyway, the difference shouldn't be that big. We'll see...
pizon

Post Reply

Return to “mikroC General”