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); } }
//////////////////////////////////////// // 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 }