Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
#include <PIC16F877A.h>void MSDelay (unsigned int);#define Psensor PORTBbits.RB1#define buzzer PORTCbits.RC7void main (void) { TRISBbits.TRISB1 = 1; //PORTB.1 as an input TRISCbits.TRISC7 = 0; //make PORTC.7 an output while (Psensor ==1) { buzzer = 0; MSDelay (200) ; buzzer = 1; MSDelay (200) ; } while(1); // stay here forever } void MSDelay (unsigned int itime) { unsigned int i; unsigned char j; for (i=0;i<itime;i++) for (j=0;j<165;j++)
#include <PIC16F877A.h>void MSDelay (unsigned int);#define Psensorlow PORTBbits.RB1 //attach low sensor to pin b1#define Psensorhigh PORTBbits.RB2 //attach high sensor to pin b2#define led PORTCbits.RC6 //attach led to pin rc6#define buzzer PORTCbits.RC7 //attach buzzer to pin c7void main (void) { TRISBbits.TRISB1 = 1; //PORTB.1 as an input TRISBbits.TRISB2 = 2; //PORTB.2 as an input TRISCbits.TRISC7 = 0; //make PORTC.7 an output TRISCbits.TRISC6 = 0; //make PORTC.6 an output while (1) //do this loop for ever { if(Psensorlow == 1){ //if the low level sensor detects water if(Psensorhigh == 1){ //if the high sensor is active buzzer = 1; //turn on the buzzer led=0; //make sure the led is off MSDelay (200) ;//wait for 200 ms buzzer = 0; //turn the buzzer off (this will make the buzzer intermittent) //or may be needed for pwm to the buzzer circuit? MSDelay (200) ;//wait for 200 ms } //end of if high sensor is active if(Psensorhigh == 0){ //if high sensor is not activated buzzer =0; //make sure the buzzer is off led =1; //switch the led on } //end of if high sensor is not active }//end of if low level active }//end of while loop }//end of main void MSDelay (unsigned int itime) { unsigned int i; unsigned char j; for (i=0;i<itime;i++){ for (j=0;j<165;j++); } }
the code will only work if water is detected at the top level. and will halt at doing nothing forever otherwise.
#include <16f877A.h>#use delay (clock = 20000000)#fuses hs, noprotect, nowdt, nolvp#byte PORTA = 5#byte PORTB = 6#byte PORTC = 7main(){ set_tris_a(1); set_tris_b(0); set_tris_c(0); do{ if (input(PIN_A1)==0) // condition when switch 1 is pressed { output_high(PIN_B1); // buzzer on portc = 0x1; // led at Pin C0 on } else { portc = 0xaa; // led at port C on alternately output_low(PIN_B1); // buzzer off output_low(PIN_C0); // led at pin C0 off } } while (1);}