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
}
}
CHASING LEDS IN BOTH DIRECTIONS PROGRAM
Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM
Hello and welcome to MikroE forum,
Something like Knight Rider, check this code:
Best regards,
Peter
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);
}
Peter
Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM
Wooow! Thanks Peter your code that you posted works perfectly. Which reading material did you master your mikroC with, cause it seems very good.
Re: CHASING LEDS IN BOTH DIRECTIONS PROGRAM
Hi Riq-M,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.
prof. Dogan Ibrahim books are nice.
Best regards,
Peter