#include <htc.h>#ifndef _XTAL_FREQ#define _XTAL_FREQ 4000000#endif __CONFIG(FOSC_INTOSCIO & WDTE_OFF & MCLRE_OFF & BOREN_OFF & LVP_OFF);__CONFIG(FCMEN_OFF & IESO_OFF);void main(){ OSCCON = 0x68; ANSEL = 0x00; TRISA = 0x00; TRISB = 0x07; PORTB = 0x00; __delay_ms(2000); PORTA = 0x0F; __delay_ms(250); PORTA = 0x00; __delay_ms(250); PORTA = 0x05; __delay_ms(250); PORTA = 0x0A; __delay_ms(250); PORTA = 0x05; __delay_ms(250); PORTA = 0x0A; __delay_ms(250); PORTA = 0x09; __delay_ms(250); PORTA = 0x06; __delay_ms(250); PORTA = 0x09; __delay_ms(250); PORTA = 0x06; __delay_ms(250); PORTA = 0x00; __delay_ms(250); PORTA = 0x01; __delay_ms(250); PORTA = 0x02; __delay_ms(250); PORTA = 0x04; __delay_ms(250); PORTA = 0x08; __delay_ms(250); PORTA = 0x00; __delay_ms(250); PORTA = 0x0F; __delay_ms(250); PORTA = 0x00; __delay_ms(250); while(1) { while (PORTB == 0x07) // all sense logic 1 // { PORTA = 0x00; // standby motor // } while (PORTB == 0x02) // center sensor logic 1 // { PORTA = 0x0A; // forward // } while (PORTB == 0x04) // left sensor logic 1 // { PORTA = 0x02; // turn left // } while (PORTB == 0x01) // right sensor logic 1 // { PORTA = 0x08; // turn right // } while (PORTB==0x00) // no sense // { PORTA = 0x05; // reverse // } } }
while (portb == 0b101){porta = 0101;}
while (portb == 0b101) {porta = 0b0101; //forward__delay_ms(200);porta = 0b0000; //stop__delay_ms(100);}
#include <htc.h>#ifndef _XTAL_FREQ#define _XTAL_FREQ 4000000#endif __CONFIG(FOSC_INTOSCIO & WDTE_OFF & MCLRE_OFF & BOREN_OFF & LVP_OFF);__CONFIG(FCMEN_OFF & IESO_OFF);void main(){ OSCCON = 0x68; ANSEL = 0x00; TRISA = 0x00; TRISB = 0x07; PORTB = 0x00; __delay_ms(2000); PORTA = 0x0F; __delay_ms(300); PORTA = 0x00; __delay_ms(300); PORTA = 0x0A; __delay_ms(300); PORTA = 0x09; __delay_ms(300); PORTA = 0x05; __delay_ms(300); PORTA = 0x05; __delay_ms(300); PORTA = 0x06; __delay_ms(300); PORTA = 0x09; __delay_ms(300); PORTA = 0x06; __delay_ms(300); PORTA = 0x00; __delay_ms(300); PORTA = 0x01; __delay_ms(300); PORTA = 0x02; __delay_ms(300); PORTA = 0x04; __delay_ms(300); PORTA = 0x08; __delay_ms(300); PORTA = 0x00; __delay_ms(300); PORTA = 0x0F; __delay_ms(300); PORTA = 0x00; __delay_ms(300); while(1) { while (PORTB == 0x07) // 111 // { PORTA = 0x00; // stop // } while (PORTB == 0x02) // 010 // { PORTA = 0x06; // forward // } while (PORTB == 0x04) // 100 turn right // { PORTA = 0x00; // stop // __delay_ms(100); PORTA = 0x04; // right // __delay_ms(150); } while (PORTB == 0x06) // 110 turn right// { __delay_ms(100); PORTA = 0x00; // stop // __delay_ms(150); PORTA = 0x04; // right // __delay_ms(100); } while (PORTB == 0x01) // 001 turn left // { __delay_ms(100); PORTA = 0x00; // stop // __delay_ms(150); PORTA = 0x02; // // __delay_ms(100); } while (PORTB == 0x03) // 011 turn left // { __delay_ms(100); PORTA = 0x00; // stop // __delay_ms(150); PORTA = 0x02; // // __delay_ms(100); } while (PORTB == 0x07) // 111 // { __delay_ms(100); PORTA = 0x00; // stop // __delay_ms(100); PORTA = 0x09; // revere // __delay_ms(100); }}}
ayos +1 sayo
imitation yan ng lf mu boss tiktak heheehetsaka salamat kay ate ***** sa tulong......question kung IR and Phototrans gagamitin ko sa sensors same lang po ba yung schem?