PIC16F877A – MIKRO C – DIGITAL OUT

Photo of author

By Jackson Taylor

1)To turn on single led on port b  (2nd led in port b is on)
void main()
                              {
                              while(1)
                              {
                              trisb=0;    //to set port b as output
                              portb=0x2;  //write  the value to port b ie, 10 (binary)
                              }
                              }
2)To turn on all led on port b
void main()
                              {
                              while(1)
                              {
                              trisb=0;    //to set port b as output
                              portb=0xff;  //write  the value to port b ie, 11111111 (binary)
                              }
                              }
3)To turn on the 8th and 6th led on port b
void main()
                              {
                              while(1)
                              {
                              trisb=0;    //to set port b as output
                              portb=0xa0;  //write  the value to port b ie, 10100000 (binary)
                              }
                              }
4) To blink the 8th  led on port b
void main()
                              {
                                 trisb=0;
                              while(1)
                              {
                               portb=0xa0;
                               delay_ms(100); // delay of 100ms,us for micro seconds
                                portb=0x0; //sets output as low
                               delay_ms(100);
                                 }
                              }
5) To blink led using “ not”
  void main()
                              {
                               trisb=0;
                               portb=0xff;
                              while(1)
                              {
                               portb=~portb; //simply not the input
                               delay_ms(100);
                              }
                              }
6) single pin configuration (7th led is on)
void main()
                              {
                              while(1)
                              {
                               trisb.f7=0;         //sets 8th pin on the port b as output
                               portb.f7=1; //sets 8th pin on the port b as high
                              }
                              }
7) Runninng  led  on port b (Shift operator)
     void main()
                              {
                              int a=2,i;
                               trisb=0x0;
                               portb=0x80;
                                delay_ms(100);
                              while(1)
                              {
                             
                              for(i=0;i<8;i++)
                              {
                              portb= portb>>1;
                               delay_ms(100);
                              }
                              portb=0x80;
                               delay_ms(100);
                               }
                              }