My problem:
When the actual circuit is powered on, it works fine. I can rotate the motor clockwise/counter then after a few instances the circuit freezes and also the display at the lcd. Is there something wrong with my code and circuit?
Another problem, the motor will only stop if the ldr is in dark mode, other than that the motor will just continue until either of the ldr has the higher value then it will rotate that way.
Another, the motor moves from east to west. How can I make the motor move back to east?
For the circuit please see attached file. Purpose of the circuit is just for connection references.
When the actual circuit is powered on, it works fine. I can rotate the motor clockwise/counter then after a few instances the circuit freezes and also the display at the lcd. Is there something wrong with my code and circuit?
Another problem, the motor will only stop if the ldr is in dark mode, other than that the motor will just continue until either of the ldr has the higher value then it will rotate that way.
Another, the motor moves from east to west. How can I make the motor move back to east?
For the circuit please see attached file. Purpose of the circuit is just for connection references.
Rich (BB code):
char strWest[10];
char strEast[10];
int west;
int east;
void main() {
ADCON1 = 0x80;
TRISA = 0xFF;
TRISB = 0x00;
TRISC = 0x00;
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
do {
west = Adc_Read(0);
east = Adc_Read(1);
IntToStr(west,strWest);
IntToStr(east,strEast);
Lcd_Out(1,1,"WEST:");
Lcd_Out(1, 6, strWest);
Lcd_Out(2,1,"EAST:");
Lcd_Out(2,6,strEast);
if(west > east) {
PORTC.F0 = 1;
PORTC.F1 = 0;
}else if(east > west) {
PORTC.F0 = 0;
PORTC.F1 = 1;
}else if(west == east){
PORTC.F0 = 0;
PORTC.F1 = 0;
}
}while(1);
}
Attachments
-
76.2 KB Views: 58