Hi guys, I have got a PIC dev kit with loads of LED's on it, and I have been successful in having them chase after each other. I have included the code I used for my 16F877A. I need help in creating a more efficient program.
I was thinking of having i as a variable and implementing this statement, but when I try it doesn't work:
How can I use this statement in my program.
I know im awfully wrong with the second code . Also ignore the fact that there are no portb, or portc in the second code
Code:
// PIC16F877A
#include<system.h>
// _LVP_OFF disables Low Voltage Programming, enabling use of the RB3 output.
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
#pragma CLOCK_FREQ 5000000
void main()
{
// - turn portb inputs that we are using into digital mode.
adcon1 = 00000110b;
trisb = 0x00;
trisc = 0x00;
trisa = 0x00;
while( 1 )
{
porta = 0x01;
delay_ms( 50 );
porta = 0x02;
delay_ms( 50 );
porta = 0x04;
delay_ms( 50 );
porta = 0x08;
delay_ms( 50 );
porta = 0x10;
delay_ms( 50 );
porta = 0x20;
delay_ms( 50 );
porta = 0x40;
delay_ms( 50 );
porta = 0x80;
delay_ms( 50 );
porta = 0x00;
portb = 0x01;
delay_ms( 50 );
portb = 0x02;
delay_ms( 50 );
portb = 0x04;
delay_ms( 50 );
portb = 0x08;
delay_ms( 50 );
portb = 0x10;
delay_ms( 50 );
portb = 0x20;
delay_ms( 50 );
portb = 0x40;
delay_ms( 50 );
portb = 0x80;
delay_ms( 50 );
portb = 0x00;
portc = 0x01;
delay_ms( 50 );
portc = 0x02;
delay_ms( 50 );
portc = 0x04;
delay_ms( 50 );
portc = 0x08;
delay_ms( 50 );
portc = 0x10;
delay_ms( 50 );
portc = 0x20;
delay_ms( 50 );
portc = 0x40;
delay_ms( 50 );
portc = 0x80;
delay_ms( 50 );
portc = 0x00;
}
}
I was thinking of having i as a variable and implementing this statement, but when I try it doesn't work:
Code:
for (i=8;i>0;i--)
How can I use this statement in my program.
Code:
// PIC16F877A
#include<system.h>
// _LVP_OFF disables Low Voltage Programming, enabling use of the RB3 output.
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
#pragma CLOCK_FREQ 5000000
void main()
{
// - turn portb inputs that we are using into digital mode.
adcon1 = 00000110b;
trisb = 0x00;
trisc = 0x00;
trisa = 0x00;
while( 1 )
{
int i
for(i=8;i>0;i--)
porta = i;
delay_ms( 50 );
}
}
I know im awfully wrong with the second code
Last edited: