Summary of Stepping Motor Control For CSS Compiler
This article provides a PIC 16F877 microcontroller code snippet to control an LED sequence. The program uses Port A inputs to trigger forward, backward, or stop functions on Port B outputs. It defines a lookup table for binary patterns and utilizes specific fuses and delay configurations to manage timing and hardware settings within a continuous loop.Parts used in the LED Sequence Controller:
- PIC 16F877 Microcontroller
- Port A Input Pins (Pin A0, Pin A1, Pin A2)
- Port B Output Pins
- 4MHz Crystal Oscillator (XT fuse)
- Binary Pattern Lookup Table (num array)
#include <16F877.h>
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock = 4000000)
#use fast_io(A)
#use fast_io(B)
byte num[5] = {0x00,0x01,0x02,0x04,0x08};
int8 disp,i;
void Forward(){
for(i=0; i<=4;i++){
disp =num[i];
output_b(disp);
delay_ms(200);
}
}
void Backward(){
for(i=4;i>0;i--){
disp =num[i];
output_b(disp);
delay_ms(200);
}
}
void Stop(){
disp =0;
output_b(disp);
delay_ms(50);
}
void main(){
setup_adc(adc_off);
set_tris_a(0xFF);
set_tris_b(0B00000000);
stop();
while(true){
if(!input(pin_a0)){
do{
Forward();
}
while(input(pin_a2));
}
else if(!input(pin_a1)){
do{
Backward();
}
while(input(pin_a2));
}
else if(!input(pin_a2)){
Stop();
}
else{}
}
}
Quick Solutions to Questions related to LED Sequence Controller:
-
What is the primary function of the provided code?
The code controls an LED sequence using a PIC 16F877 microcontroller based on input pin states. -
How does the system determine when to move LEDs forward?
It moves forward when Pin A0 is low while Pin A2 remains high. -
Can the LED pattern run backwards?
Yes, the Backward function runs when Pin A1 is low and Pin A2 is high. -
What happens if Pin A2 is activated?
Activating Pin A2 triggers the Stop function which sets all outputs to zero. -
Which port is configured as output in this project?
Port B is configured as the output port with a TRIS setting of 0B00000000. -
What clock frequency is used in the delay configuration?
The delay function is set to use a 4000000 Hz clock frequency.
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...