Problem pic chaser

General discussion on mikroPascal.
Post Reply
Author
Message
ahche
Posts: 5
Joined: 18 Jun 2009 23:43

Problem pic chaser

#1 Post by ahche » 18 Jun 2009 23:51

Hi all , i'm working on my own led chaser prorammed in Pascal , but i can't find how i can bring "explain" this to mikroPascal

Code: Select all

i:=2^n 
? is there a possibility to work ?

PS i want to minimaze this code ( made by myself)


Code: Select all

procedure chaser1;
begin
  GPIO:=$01 ;
  delay_ms(200);
  GPIO:=$02 ;
  delay_ms(200);
  GPIO:=$04 ;
  delay_ms(200);
  GPIO:=$10 ;
  delay_ms(200);
  GPIO:=$20 ;
end;
PSS: Im using PIC12F629 , GP3 - input only !

anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

#2 Post by anton » 19 Jun 2009 08:14

Hi,

What about

Code: Select all

procedure chaser1;
begin
  GPIO:=$01 ;
  repeat
    delay_ms(200);
    if GPIO = $04 then GPIO := GPIO shl 2
    else if GPIO = $20 then GPIO := $01
    else GPIO:=GPIO shl 1;
  until 1 = 0;
end;
Anton
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

ahche
Posts: 5
Joined: 18 Jun 2009 23:43

#3 Post by ahche » 19 Jun 2009 19:11

Thanx Anton, but not ... In simulation with this code ... i 'm making a multi device

Code: Select all

program button_test;
var b1:integer;
label 1;

procedure flash;
begin
  GPIO:=$08 ;
  delay_ms(250);
  GPIO:=$FF;
end;


procedure chaser1;
begin
  GPIO:=$01 ;
  delay_ms(200);
  GPIO:=$02 ;
  delay_ms(200);
  GPIO:=$04 ;
  delay_ms(200);
  GPIO:=$10 ;
  delay_ms(200);
  GPIO:=$20 ;
end;

procedure chaser2;
begin
  GPIO:=$09 ;
  delay_ms(200);
  GPIO:=$0A ;
  delay_ms(200);
  GPIO:=$0C ;
  delay_ms(200);
  GPIO:=$18 ;
  delay_ms(200);
  GPIO:=$28 ;
  delay_ms(200);
  GPIO:=$18 ;
  delay_ms(200);
  GPIO:=$0C ;
  delay_ms(200);
  GPIO:=$0A ;
  delay_ms(200);
  GPIO:=$09 ;
 end;

begin
  TRISIO := $00;
  INTCON := 0;
  GPIO := $00;
  b1:=0;
 1: repeat
   begin
        if button (GPIO,3,0,0) then b1:=b1+1 ;
        delay_ms (200);
        if b1=0 then GPIO:=$7F;
        if b1=1 then flash;
        if b1=2 then Chaser1;
        if b1=3 then chaser2;
        if b1=4 then GPIO:=$08;
    end;
  until b1=5;
  b1:=0;
  goto 1 ;
end.
 {begin
  TRISIO := 0;
  GPIO := $00;
  b1:=0;
 1: repeat
   begin
        if button (GPIO,3,0,0) then b1:=b1+1 ;
        delay_ms (200);
        if b1=0 then GPIO:=$01 ;
        if b1=1 then GPIO:=$02 ;
        if b1=2 then GPIO:=$04 ;
        if b1=3 then GPIO:=$10 ;
        if b1=4 then GPIO:=$20 ;
    end;
  until b1=5;
  b1:=0;
  goto 1 ;
end. }
 

but the result is not that i expected ... in pin GP3 i have buton to chnage the work , but i can change it only in some positions .... tnx

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#4 Post by Dany » 19 Jun 2009 20:13

but the result is not that i expected
Can you describe as precise as possible which result you expect?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

ahche
Posts: 5
Joined: 18 Jun 2009 23:43

#5 Post by ahche » 21 Jun 2009 16:18

when i press the button the device must change the way of blinking dhe leds , but not in every press it do this ( i think that this is because of long codes of chasers - bevore end of code and return to if statement i can't change the way of blinking)

Moas
Posts: 25
Joined: 14 Apr 2009 19:50

Re: Problem pic chaser

#6 Post by Moas » 06 Jul 2009 15:11

ahche wrote:

Code: Select all

procedure chaser1;
begin
  GPIO:=$01 ;
  delay_ms(200);
  GPIO:=$02 ;
  delay_ms(200);
  GPIO:=$04 ;
  delay_ms(200);
  GPIO:=$10 ;
  delay_ms(200);
  GPIO:=$20 ;
end;
I would recommend moving the delay_ms (200); to a separate procedure and always call that procedure. You will need three more lines of the code but actually the compiled result will be much smaller - the delay routines consume quite a bunch of bytes and the optimizer is not smart enough to create just one delay and link everything to it - that's why you should create it yourself in the separated procedure.

ahche
Posts: 5
Joined: 18 Jun 2009 23:43

Re: Problem pic chaser

#7 Post by ahche » 07 Jul 2009 23:15

Moas wrote:I would recommend moving the delay_ms (200); to a separate procedure and always call that procedure. You will need three more lines of the code but actually the compiled result will be much smaller - the delay routines consume quite a bunch of bytes and the optimizer is not smart enough to create just one delay and link everything to it - that's why you should create it yourself in the separated procedure.
I can't figure out other code to do this :roll: Help :arrow:

PS : I have some other questions . The first : How i can make the device go in slippnig mode ? (much smaller consumation )

Moas
Posts: 25
Joined: 14 Apr 2009 19:50

Re: Problem pic chaser

#8 Post by Moas » 08 Jul 2009 20:18

Ahche, I ment to prepare a code like this:

Code: Select all

procedure Delay200;
begin
  delay_ms (200);
end;

procedure chaser1;
begin
  GPIO:=$01 ;
  Delay200;
  GPIO:=$02 ;
  Delay200;
  GPIO:=$04 ;
  Delay200;
  GPIO:=$10 ;
  Delay200;
  GPIO:=$20 ;
end;
The compiled code will occupy considerably less space in your PIC.
ahche wrote: PS : I have some other questions . The first : How i can make the device go in slippnig mode ? (much smaller consumation )
I am not sure if I understand you correctly but if you want to use "low power" mode for your PIC you need to use LP oscillator (not XT or HS) config bits and very low Xtal frequency (32,768 kHz). Please study the datasheet for your specific PIC - it always states the maximum LP frequency and it also recommends capacitors to be used with that particular Xtal. The lower the frequency, the lower the consumed power.

With 16F84A and 32,768 kHz Xtal the consumption of my devices is usually somewhere around 500 uA. Pay also attention to the PIC specifics! You cannot use 32,768 kHz Xtal for 20 MHz flavour of 16F84A. It would not work. You need to pick the 4 MHz one.

But I am also a newbie to PICs and mikroPascal so if someone more experienced can advice, please go ahead. :)

ahche
Posts: 5
Joined: 18 Jun 2009 23:43

#9 Post by ahche » 08 Jul 2009 20:45

in asm there is command

Code: Select all

sleep 
wich brings the device in sleaping mode something like waiting to press a button to wake up ... that i mean :)

Post Reply

Return to “mikroPascal General”