Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

need help..

Status
Not open for further replies.

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....
 
digital input
analog is for like reading voltage difference of LDR. I switch is high or low so it digital. If you where low on inputs you could use a voltage divider and chain switches and read them as analog. But it better to read them digital. hope this helps
 

Attachments

  • sw.PNG
    sw.PNG
    12.1 KB · Views: 118
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top