int main(void) { init(); int thrust = 0; // Holds thrust %age int old_thrust = 0; // Holds old thrust value. Used to limit the number of bytes sent int checksum = 0; // checksum for outgoing serial data. Integrity is important! while(1) { if (unlock) { // If the safety switch is active LATBbits.LATB5 = 1; // Green LED thrust = get_thrust(old_thrust); clear_bt_buf(); __delay_ms(5); } else { // System is locked! LATBbits.LATB5 = 0; // Red LED clear_bt_buf(); thrust = 0; } if (thrust != old_thrust) { old_thrust = thrust; uart_putChar('t', 2); // t for thrust, same as amarino uart_putChar(thrust, 2); checksum = ('t' ^ thrust); // Checksum is pretty simple for two bytes! uart_putChar(checksum, 2); } } return 0; }
/*---------------------------------------------------------------------------- Write character to Serial Port *----------------------------------------------------------------------------*/ int sendchar (int c) { if (c == '\n') { uart_putChar (0, 0x0D); } uart_putChar (0, c); return (c); }
void uart_putString (int uart, char *s) { while (*s != 0) { uart_putChar(uart,*s++); } }
void uart_putString(const char *s, char p){ while(*s) uart_putChar(*s++, p); // Write a bunch of characters into the output buffer }