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).
Related projects
PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation
Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....
Peripheral TutorialsHands-On Digital I/O Lab with PIC18F46K22 Microcontroller
PIC18F46K22 Microcontroller Digital I/O specifically explores the design of simple combinational circuits using the digital I/O capabilities of the PIC18F46K22 microcontroller. Moving...
Peripheral TutorialsDesign for manufacturing and assembly: DFA&DFM
Product developers understand the challenges involved in creating a market-ready product. Even experienced designers often go through multiple prototype iterations before reaching...
Peripheral Tutorials · PIC16F877AKeypad 4×5 for microcontrollers v. 1.1 using PIC16F877
What's this? The circuit here described is a simple 4x5 keypad that can be used in particular with the PIC 16F877 microcontroller,...
Peripheral TutorialsMatrix scankey 3×4 for Lcd 2 line For CSS Compiler
Peripheral Tutorials · PIC16F877APIC16F877 timer1 code and Proteus simulation
This PIC16F877 microcontroller tutorial answers the question, " How to use timer1 of PIC16F877 and how to handle its interrupts? " Using...