Esempio n. 1
0
void main(void) {
  PLL_init();
  lcd_init();
  SCI0_init(9600); 
  SCI1_int_init(9600); // Channel to talk to ESP8266
  motor0_init(); // These functions actually control PWM outputs
  motor1_init(); // We use them to run the RGB LED.
  motor2_init();
  RTI_init();
  SW_enable();
  
  initq();
  
  DDRH = 0; // PORTH is an input.
  result = 0;
  status = 'b';
  
  // Populate binary search tree:

  set_lcd_addr(0);
    
  send_at_command_sci1("ATE0");  // change to ATE1 for debug
  
  status = 'i';
  
  // Establish connection to server.
  
  send_at_command_sci1("AT+CWMODE=1");  // Set ESP to station mode
  
  send_at_command_sci1("AT+CIPMODE=0"); // Set ESP to normal transmission mode
  
  send_at_command_sci1("AT+CIPMUX=0");  // Set ESP to single-connection mode 
  
  send_at_command_sci1("AT+CWJAP=\"Freynet\",\"\""); // Connect to network
  
  send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server

  
  while(1){
    command = '\0';   
    while(qempty());
    command = getq();
    
    switch (command) {
      case 'n':
        status = 'w';
        result = new_sequence();
        ms_delay(500); // If we finish too quickly, we open a connection the ESP thinks is already open, and it breaks.
        send_at_command_sci1("AT+CIPSTART=\"TCP\",\"fpf3.net\",12345"); // connect to server

        break;
        
    }
    outchar0(result);
  }
}
Esempio n. 2
0
void main(void) {
    
    PLL_init();       // set system clock frequency to 24 MHz
    ad0_enable(); // enable a/d converter 0
    ad1_enable(); // enable a/d converter 1
    led_enable();
    seg7_disable();
    servo54_init();
    lcd_init();        // enable lcd
    motor1_init(); // enable 8-bit pwm1 for computer fan
  
     
         while(1) {
            
            for (width = 3000; width < 14500; width = width + 150) {
                flame = ad0conv(3); 	// read flame sensor output on channel 3 adc0
                range = ad0conv(5); 	// read range sensor output on channel 7 adc1
                
                set_lcd_addr(0x40);
                if (range > 550) {
                    type_lcd("Flame is near!  ");
                } else {
                    type_lcd("Out of range    ");
                }
                set_servo54(width);
                ms_delay(10);
                
                if (flame > 1000) {
                    set_lcd_addr(0x00);
                    ms_delay(10);
                    type_lcd("Flame Detected! ");
                    if (range > 550) {
                          ms_delay(10);
                          //Turn the motor on for 8 seconds
                          set_lcd_addr(0x40);
                          ms_delay(10);
                          type_lcd("Flame is near!  ");
                          ms_delay(10);
                          leds_on(0b11111000);     //Motor is on
                          ms_delay(8000);
                          motor1(speed);
                          ms_delay(10);
                    }
                } else {
                    leds_on(0b11111100);     //Motor is off
                    set_lcd_addr(0x00);
                    type_lcd("No Flame        ");
                }
                ms_delay(10);
            }
    }
}
Esempio n. 3
0
////////////////////////////////////////
// Initalize                          //
// Ports, Interrupts, Motor and Servo //
////////////////////////////////////////
void portInit(void){
  PLL_init(); // set system clock frequency to 24 MHz
  
  //Direction registers
  DDRH = 0x00;  // Port H is input       
  DDRB = 0x0F; // Port B starts as output
  PORTB = 0x00; // turn all LED's OFF
  DDRT = 0xFF;  // port T7 is input rest is output

  //motors
  PTT_PTT0 = 0; //default
  PTT_PTT1 = 0; //default
  PTT_PTT2 = 0; //default
  PTT_PTT3 = 0; //default
  motor0_init(); //left motor
  motor1_init(); //right motor
  
  //initialize a/d
  ad0_enable(); //enable a/d converter w/ interrupt with custom values
  RTI_init(); //turn on real time interrupt
}