Marcoscr
Newbie level 4

- Joined
- Aug 20, 2009
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Costa Rica
- Activity points
- 1,344
16f877a sample c programs
Hello!
I am new at this forum,
I am starting in PIC programming, I have bought a PIC16F877A, and I am having problems with my first attempt to program this PIC, now I really don't know what else to do, I hope someone can guide me through this.
What I am trying to do is to control 2 DC motor by sensing a photoresistor, I used OPAMP's to generate a high signal by comparing to a reference voltage with the photoresistor's voltage.
Inputs=
A0: sensor1
A1:sensor2
A2:sensor3
A3:sensor4
outputs=
B0:motor1
B1:motor1(reverse); I used a H bridge for now.
B2:motor2
here is my code:
#include <16F877A.h>
#use delay(clock=4000000)
fuses NOWDT
#use standard_io(A)
#use standard_io(B)
void main() {
inicio_rutina:
OUTPUT_B(0x00);
inicio:
if (input(pin_A0))
{
goto avance;
}
else
goto inicio;
avance:
{
delay_ms(5000);
do {
output_B(0b00000001);
}
while (!(input(pin_A1))||(!(input(pin_A3))));
}
{
if (input(pin_A1))
goto llenado;
else
goto retrocede;
}
llenado:
{
while (input(pin_A1))
{
output_low(PIN_B0);
delay_ms(1000);
output_high(PIN_B1);
goto avance;
}
}
retrocede:
if (!(input(pin_A0)))
{
do {
output_high(PIN_B2);
}
while (!(input(pin_A2)));
}
else
goto retrocede;
goto inicio_rutina;
}
Hello!
I am new at this forum,
I am starting in PIC programming, I have bought a PIC16F877A, and I am having problems with my first attempt to program this PIC, now I really don't know what else to do, I hope someone can guide me through this.
What I am trying to do is to control 2 DC motor by sensing a photoresistor, I used OPAMP's to generate a high signal by comparing to a reference voltage with the photoresistor's voltage.
Inputs=
A0: sensor1
A1:sensor2
A2:sensor3
A3:sensor4
outputs=
B0:motor1
B1:motor1(reverse); I used a H bridge for now.
B2:motor2
here is my code:
#include <16F877A.h>
#use delay(clock=4000000)
fuses NOWDT
#use standard_io(A)
#use standard_io(B)
void main() {
inicio_rutina:
OUTPUT_B(0x00);
inicio:
if (input(pin_A0))
{
goto avance;
}
else
goto inicio;
avance:
{
delay_ms(5000);
do {
output_B(0b00000001);
}
while (!(input(pin_A1))||(!(input(pin_A3))));
}
{
if (input(pin_A1))
goto llenado;
else
goto retrocede;
}
llenado:
{
while (input(pin_A1))
{
output_low(PIN_B0);
delay_ms(1000);
output_high(PIN_B1);
goto avance;
}
}
retrocede:
if (!(input(pin_A0)))
{
do {
output_high(PIN_B2);
}
while (!(input(pin_A2)));
}
else
goto retrocede;
goto inicio_rutina;
}