CHASING LEDS IN BOTH DIRECTIONS PROGRAM

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
Riq-M
Posts: 6
Joined: 11 Jan 2014 08:28

CHASING LEDS IN BOTH DIRECTIONS PROGRAM

#1 Post by Riq-M » 12 Jan 2014 19:50

Hallo good people!
I got myself into fix with my program code, when i was trying to create a program code that will allow led lights to flash in opposing directions.
Am still new to mikroC programming and i would greatly greatly apreciate your input.

Thanks in advance!

void main() {
unsigned char j = 1;
TRISC= 0;
for(;;)
{ PORTC = J; // send j to PORTC
Delay_ms(1000);
J = J << 1; //Shift left J
J = J >> 1; // shift right J
if(J==0) J = 1; // If last LED move to the first LED
if(j==1) J = 0; // If first LED move to the first LED

}
}
:?: :?:

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM

#2 Post by tpetar » 13 Jan 2014 14:26

Hello and welcome to MikroE forum,

Something like Knight Rider, check this code:

Code: Select all

int i;

void main() {

  //Ports and pins configurations
  ANSELC = 0;                                    // Configure PORTC pins as digital
  TRISC = 0x00;                                  // Configure PORTC as output

  LATC = 0b00000001;                             // Initial PORTC value

  do {

    for (i=0; i<7; i++)
        {
        LATC <<= 1;                              //Move LED to left
        delay_ms(100);                           //Adjust this value for faster or slower led moving
        }

    for (i=0; i<7; i++)
        {
        LATC >>= 1;                              //Move LED to right
        delay_ms(100);                           //Adjust this value for faster or slower led moving
        }

  } while(1);
}
Best regards,
Peter

Riq-M
Posts: 6
Joined: 11 Jan 2014 08:28

Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM

#3 Post by Riq-M » 13 Jan 2014 21:30

Wooow! Thanks Peter your code that you posted works perfectly. Which reading material did you master your mikroC with, cause it seems very good.
:D

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM

#4 Post by tpetar » 14 Jan 2014 09:21

Riq-M wrote:Wooow! Thanks Peter your code that you posted works perfectly. Which reading material did you master your mikroC with, cause it seems very good.
:D
Hi Riq-M,

prof. Dogan Ibrahim books are nice.

:)

Best regards,
Peter

Post Reply

Return to “mikroBasic PRO for ARM General”