Reply To: PIC16F877A with DC Gear Motor

Home Forums Microcontrollers PIC Microcontroller PIC16F877A with DC Gear Motor Reply To: PIC16F877A with DC Gear Motor


Hi there, below is the code I tried to write according to your tutorials:

void main()
  TRISD.F0 = 1; //RD0 as Input PIN 1
  TRISD.F1 = 1; //RD1 as Input PIN 2

  TRISB.F0 = 0; //RB0 as Output PIN 1
  TRISB.F1 = 0; //RB1 as Output PIN 2

  PORTB.F0 = 0; //Motor clockwise direction flow OFF
  PORTB.F1 = 0; //Motor anticlockwise direction flow OFF

    if(PORTD.F0 == 0) //If Switch is presseed
      delay_ms(100); //Provides required delay
      if(PORTD.F0 == 0) //If Switch is still pressed
        PORTB.F0 = 1; //Motor turns in clockwise direction
        if(PORTD.F1 == 1) //If Signal is sent from proximity sensor
          PORTB.F0 = 0;
          PORTB.F1 = 1;
          PORTB.F1 = 0; //After 10 seconds the motor is turned off

The part where the proximity sensor sends a signal, if(PORTD.F1 == 1), the input should be 1 right?

Also, do you need a constant flow of current from input, in order for the output to be able to work constantly? Like if I press the switch once, the motor turns clockwise, but if I cut off the current from the switch, will the motor still keep turning or it will stop??

Furthermore, will this code works in MPLAB or Hi-tech? I know the code is almost similar with just a slight modification, just need to know about this, if I want to program them in other software, anything else to add to the code?

One more question, the voltage of the signal sent from my proximity sensor is quite high, which my PIC16F877A couldn’t stand the voltage as the maximum is 5V, so any solution to this to lower down the signal voltage from my proximity sensor? I’ve searched the internet, I found something about opto-isolator, can I use that?

Your help is greatly appreciated as this is a very urgent project, thanks.