Dear all,

              I use PIC16F684  to control a multiplexer (HCF4052) for one servo and autopilot program.  Program is working well.But somethime is ok and sometime is not work.When I give servo output,multiplexer is working.Amazing it!
Give me ur light.This is a program for Multiplexer .

#include <16F684.H>
#include <stdlib.h>

#define SWLED PIN_C5
#define MUXa PIN_C1
#define MUXb PIN_C2

#fuses INTRC_IO,NOWDT,NOPROTECT,PUT
#use delay(clock=4000000)

//-----------------Global Variables-----------------
long pulseLength=0;

//--------------------------------------------------

#INT_EXT
void isr()
{
   set_timer1(0);
   while(input(PIN_A2)){

   // if SW interrupt triggers during HW interrupt, prevent bogus pulseLength value
   pulseLength = get_timer1();
  
 }
}

void main(){
            //setup interrupts
            ext_int_edge(L_TO_H);
            setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); // other param causing interrupt to occur every 20 msec
            setup_timer_1(T1_INTERNAL);
            enable_interrupts(INT_EXT);
            enable_interrupts(GLOBAL);
            port_a_pullups (TRUE);
            //output_high(SWLED); delay_ms(1500);
            //output_low(SWLED); delay_ms(1500);
          
while(1){
           
            if(pulseLength>1500) // pulseLength/(clock/4) is time in us
              {
                output_low(SWLED); // LED off under manual control
                output_low(PIN_C4);
                output_low(MUXa); //Mux control
                output_low(MUXb);
                                 
              }

            else if(pulseLength<1500)
              {
                output_high(SWLED); // LED on under AP
                output_high(PIN_C4);
                output_high(MUXa); //Mux control
                output_high(MUXb);
                                 
              }

         }

   }

  

Tags: multiplexer, program

Views: 4

Reply to This

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service