apizbaygon
Junior Member level 3
Hi,i wanna ask a question...how to program pic16f877a to blink 3 led via 3 different ports..example
ort b,c and d
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature currently requires accessing the site using the built-in Safari browser.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 void main() { TRISB = 0x00; // Sets all pins in PORTB as output PORTB = 1; // Set RB0 to high 00000001 do // To set infinite loop { Delay_ms(100); // 100 mili seconds delay PORTB = PORTB<<1; //Shifting right by one bit if(PORTB >= 0b10000000) //To reset to 00000001 { //when the count becomes 10000000 Delay_ms(200); // 200 mili seconds delay PORTB = 1; } }while(1); // To set infinite loop TRISD = 0x00; PORTD = 1; do { Delay_ms(200); PORTD = PORTD<<1; if (PORTD >=0b10000000) { Delay_ms(350); PORTD = 1; } }while (1); }
void main() {
PORTB=0; //initialize portb
PORTD=0; //initialize portd
TRISB=0b00000000; //configure portB as output
TRISD=0b00000000; //configure portD as output
ANSELH=0; //configure an pin as digital I/O
ANSEL=0;
while(1){
PORTB=1;
delay_ms(1000);
PORTD=1;
delay_ms(1000);
}
}
void main() {
PORTB=0; //initialize portb
PORTC=0; //initialize portc
PORTD=0; //initialize portd
TRISB=0b00000000; //configure portB as output
TRISC=0b00000000; //configure portC as output
TRISD=0b00000000; //configure portD as output
while(1)
{
PORTB = 0x01;
PORTC = 0x01;
PORTD = 0x01;
delay_ms(1000);
PORTB = 0x02;
PORTC = 0x02;
PORTD = 0x02;
delay_ms(1000);
PORTB = 0x04;
PORTC = 0x04;
PORTD = 0x04;
delay_ms(1000);
PORTB = 0x08;
PORTC = 0x08;
PORTD = 0x08;
delay_ms(1000);
PORTB = 0x10;
PORTC = 0x10;
PORTD = 0x10;
delay_ms(1000);
PORTB = 0x20;
PORTC = 0x20;
PORTD = 0x20;
delay_ms(1000);
PORTB = 0x40;
PORTC = 0x40;
PORTD = 0x40;
delay_ms(1000);
PORTB = 0x80;
PORTC = 0x80;
PORTD = 0x80;
delay_ms(1000);
}