Learn   /   Peripheral Tutorials

Stepping Motor Control For CSS Compiler

Stepping Motor Control For CSS Compiler: circuit, code and details for this PIC microcontroller project.

Published

At a glance

CategoryPeripheral Tutorials
IncludesCode
Reading time~2 min

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)
C source
 
#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{}

   }
}

 

  • 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.
Ibrar Ayyub

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...