Shift left – shift right value For CSS Compiler

Summary of Shift left – shift right value For CSS Compiler


This article presents a PIC16F877 microcontroller program that creates a sequential LED light pattern. The code initializes the device, configures Timer0 for delays, and sets Port B as an output. It then enters an infinite loop where it shifts a single 'on' bit across 8 pins leftward, waits, resets to the last pin, shifts rightward back to the start, and repeats. This generates a chaser effect on connected LEDs.

Parts used in the PIC16F877 LED Chaser Project:

  • PIC16F877 Microcontroller
  • 4MHz Crystal Oscillator (XT Fuses)
  • Port B Output Pins
  • LEDs connected to Port B
  • Delay Function (150ms)
  
#include <16F877.h>
#device adc=8
#FUSES NOWDT ,XT                                        
#use delay(clock=4000000) 
int8 x,k;
void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1); 
   set_tris_b(0x00);
   output_b(0);
   k=0;
   x=0x01;
    while(true)
   {
     for(k=0;k<=7;++k){
      output_b (x);
      delay_ms(150);
      shift_left(&x,1,0);
       }
        x = 0x80;
        k = 0;
      for(k=0;k<=7;++k){
      output_b (x);
      delay_ms(150);
      shift_right(&x,1,0);  
      }
        x = 0x01;
        k = 0;
        }
}

Quick Solutions to Questions related to PIC16F877 LED Chaser Project:

  • What microcontroller is used in this project?
    The project uses the PIC16F877 microcontroller.
  • How long does each LED stay on?
    Each LED stays on for 150 milliseconds.
  • Which port is configured for the output?
    Port B is configured as the output using set_tris_b(0x00).
  • Does the code use hardware timers for the delay?
    No, the code uses a software delay function called delay_ms.
  • What direction does the light move first?
    The light moves from left to right initially using shift_left.
  • Can I change the speed of the blinking?
    Yes, by modifying the value inside the delay_ms function.
  • What happens after the rightmost LED lights up?
    The sequence resets the variable x to 0x80 and shifts right immediately.
  • Is the ADC enabled in this code?
    No, the ADC is explicitly disabled with setup_adc(ADC_OFF).

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter