Saturday, April 19, 2008

Programming practice.

You should alaredy have some basic knowledge about C programming.

Now:-
1. Write a program to blink 8 LED connected to portb one after another. Before trun on the next led off the previous one.

2. Do similar as above and this time when last LED is lit, blink in reverse...ie led 1 to 8 and 7 to 1 endlessly.

3. Blink 2 LED at a time for all 8 LED. 1,2, then 3,4...


Post you code here. If you have errors or have problems let us know.

3 comments:

9w2dtr said...

Yes sir... exercise noted and I will do my homework... please don't cane me if I fail...

9w2gu said...

I need feedback, am i too detailed or further explanation is needed or just right?

Sparky said...

I know, I have a lot to learn.



int a = 1;

void main ()

{
TRISB = 0;
PORTB = 0;

while (1);
{
do
{
PORTB = a;
Delay_ms(100);
a <<= 1; //shift bit to the left
}
while(a<255);

a >>= 2; //stops bit 7 double flashing between do loops

do
{
PORTB = a;
Delay_ms(100);
a >>= 1;
}
while(a>1);
}

}