polarbearbear
New Member
I’m doing my project, abt the control of the dc motor direction and speed using PIC16F877. I use 2 push-on switches as my sensor.
The PIC circuit is finished constructed, voltage regulator is used to supply the 5V voltage to PIC. I have some question to ask:
1. I supply the the 5V voltage to the both of the sensor (push-on switch). Once the switch is pressed, 5Vvoltage will pass through the switch and act as input to the PIC. The voltage input to PIC consider as analog or digital input? Which port (port A, B, C, D, E) should act as the input for the voltage?
2. Below is the program using CCS code I do. Is it any mistake? My question is: the program I do is definie the switch as on off switch, not push-on. Anyone can teach me how to define the condition with push-on switch?? ( when the sensor A is press, motor will change direction; when sensor B is press, motor will change direction again)
#include <16f877.h>
#use delay (clock=20000000)
#fuses hs,noprotect, nowdt, nolvp
#byte portb=6
#byte portd=8
void main()
{
set_tris_b(0xff);
set_tris_d(0x00);
portd=0
do{
if
( input(PIN_B0)==1 && input(PIN_B1)==0)
{output_high(PIN_D0);}
Else if
(
input(PIN_B1)==1 && input(PIN_B0)==0)
{output_high(PIN_D1);}
}while(1);
}
THX…
i will attach the circuit i done later....
The PIC circuit is finished constructed, voltage regulator is used to supply the 5V voltage to PIC. I have some question to ask:
1. I supply the the 5V voltage to the both of the sensor (push-on switch). Once the switch is pressed, 5Vvoltage will pass through the switch and act as input to the PIC. The voltage input to PIC consider as analog or digital input? Which port (port A, B, C, D, E) should act as the input for the voltage?
2. Below is the program using CCS code I do. Is it any mistake? My question is: the program I do is definie the switch as on off switch, not push-on. Anyone can teach me how to define the condition with push-on switch?? ( when the sensor A is press, motor will change direction; when sensor B is press, motor will change direction again)
#include <16f877.h>
#use delay (clock=20000000)
#fuses hs,noprotect, nowdt, nolvp
#byte portb=6
#byte portd=8
void main()
{
set_tris_b(0xff);
set_tris_d(0x00);
portd=0
do{
if
( input(PIN_B0)==1 && input(PIN_B1)==0)
{output_high(PIN_D0);}
Else if
(
input(PIN_B1)==1 && input(PIN_B0)==0)
{output_high(PIN_D1);}
}while(1);
}
THX…
i will attach the circuit i done later....