This is my program to a Stepper motor using ULN2003A(using STP-ULN2003 which used in arduino) , sensor ( replace as rain sensor module in hardware) , and led ( water pump in hardware) , but when after I write the program into the PIC16F877A it does not work , here is my coding :
so is there any problem that i should check for microC setting or Proteus or PIC setting ? The simulation works perfectly
The voltage I supply to PIC is about 3.5V-4V with both Vdd and Vss supplied, i also had crystall oscillator 4MHz ready but it still does not work even I try with a simple LED light to replace the relay
Moderators note : Used code tags for C
C:
#define STEP1 0b00010010
#define STEP2 0b00000010
#define STEP3 0b00000110
#define STEP4 0b00000100
#define STEP5 0b00001100
#define STEP6 0b00001000
#define STEP7 0b00011000
#define STEP8 0b00010000
#define SENSOR1 PORTD.F0
#define SENSOR2 PORTD.F4
#define PUMP1 PORTC.F0
#define PUMP2 PORTC.F5
void main() {
unsigned int days,t1,t2;
TRISD = 0x11;
TRISB = 0x00;
PORTB = 0;
TRISC = 0;
PORTC = 0;
while(1)
{
for(days=1; days<=2; days++){
PORTB = STEP1;
Delay_ms(500);
PORTB = STEP2;
PORTB = STEP3;
Delay_ms(500);
PORTB = STEP4;
Delay_ms(500);
PORTB = STEP5;
Delay_ms(500);
PORTB = STEP6;
PORTB = STEP7;
Delay_ms(500);
PORTB = STEP8;
Delay_ms(500);
PORTB = STEP1;
}
Delay_ms(1000);
PUMP2 = 1;
t2=0;
do{
Delay_ms(1000);
t2++;}while(SENSOR2 == 0 && t2<=5);
PUMP2 = 0;
PUMP1 = 1;
t1=0;
do{
Delay_ms(1000);
t1++;}while(SENSOR1 == 1 && t1<=5);
PUMP1 = 0;
}
}
The voltage I supply to PIC is about 3.5V-4V with both Vdd and Vss supplied, i also had crystall oscillator 4MHz ready but it still does not work even I try with a simple LED light to replace the relay
Moderators note : Used code tags for C
Last edited by a moderator: