int main(void) { char c; INTCON1bits.NSTDIS = 1; openQEI(); OpenUART(); // openPWM(); // InitTMR2(); Clock_Init(); // enablePWM; // ch1Run; // ch2Run; initInterpreter(); initOdometrie(); initAsservissement(); initPIDs(); while(1) { c = (char)ReadUART1(); if(buildCommande()) { interpreteCommande(); clearCommande(); } } return 0; }
void Setup (void) { unsigned char MSG_SAUD_Radio_nRF24L01 [] = {"nRF24L01 Radio\n\r"}; TRISDbits.RD0 = 0; TRISAbits.RA4 = 0; LED_OFF OpenUART(); // abre Soft UART @9600,8N1, TXD pino RB4 & RXD pino RB5 Usart_Send (MSG_SAUD_Radio_nRF24L01); Open_nRF24L01_SPI(); ADCON1 = 0x0E; // CONFIGURA PA0 COMO ANALOGICA, restantes como digitais CMCON = 0x0F; // DESABILITAR COMPARADOR // PIC Expert 2 somente // --------------- TRISBbits.RB3 = 0; // mantém o GLCD resetado PORTBbits.RB3 = 0; // só pra evitar de ficar piscando TRISEbits.RE2 = 0; // pois compartilha o PORT D c/ PORTEbits.RE2 = 0; // os LEDs // --------------- }//
void SerialPCInit( void ){ serialPC_ProcessaPkt = FALSE; stSerialPC = ST_STX; serialPC_CRC = 0; serialPC_DataLen = 0; #ifdef _USE_SERIALPC_TIMEOUT serialPC_timer = TIMER_NULL; #endif #ifdef USE_SONDA serialPC_SondaTimer = TIMER_NULL; #endif OpenUART(); return; }
//***************************************************************************** // //! main() is the programs main routine. //! //! \param argc is the number of parameters that were passed in via the command //! line. //! \param argv is the list of strings that holds each parameter that was were //! passed in via the command line. //! //! This is the main routine for downloading an image to the device via the //! UART. //! //! \return This function either returns a negative value indicating a failure //! or zero if the download was successful. // //***************************************************************************** int32_t main(int32_t argc, char **argv) { FILE *hFile; FILE *hFileBoot; g_ui32DownloadAddress = 0; g_ui32StartAddress = 0xffffffff; g_pcFilename = 0; g_pcBootLoadName = 0; g_pui32BaudRate = 115200; g_ui32DataSize = 8; g_i32DisableAutoBaud = 0; setbuf(stdout, 0); // // Get any arguments that were passed in. // if(parseArgs(argc, argv)) { printf("%s", pcUsageString); return(-1); } if(CheckArgs()) { return(-1); } // // If a boot loader was specified then open it. // if(g_pcBootLoadName) { // // Open the boot loader file to download. // hFileBoot = fopen(g_pcBootLoadName, "rb"); if(hFileBoot == 0) { printf("Failed to open file: %s\n", g_pcBootLoadName); return(-1); } } // // Open the file to download. // hFile = fopen(g_pcFilename, "rb"); if(hFile == 0) { printf("Failed to open file: %s\n", g_pcFilename); return(-1); } if(OpenUART(g_pcCOMName, g_pui32BaudRate)) { printf("Failed to configure Host UART\n"); return(-1); } // // Now try to auto baud with the board by sending the Sync and waiting // for an ack from the board. // if(g_i32DisableAutoBaud == 0) { if(AutoBaud()) { printf("Failed to synchronize with board.\n"); return(-1); } } printf("\n"); if(g_pcBootLoadName) { printf("Boot Loader : %s\n", g_pcBootLoadName); } printf("Application : %s\n", g_pcFilename); printf("Program Address: 0x%x\n", g_ui32DownloadAddress); printf(" COM Port: %s\n", g_pcCOMName); printf(" Baud Rate: %d\n", g_pui32BaudRate); printf("Erasing Flash:\n"); // // If both a boot loader and an application were specified then update both // the boot loader and the application. // if(g_pcBootLoadName != 0) { if(UpdateFlash(hFile, hFileBoot, g_ui32DownloadAddress) < 0) { return(-1); } } // // Otherwise just update the application. // else if(UpdateFlash(hFile, 0, g_ui32DownloadAddress) < 0) { return(-1); } // // If a start address was specified then send the run command to the // boot loader. // if(g_ui32StartAddress != 0xffffffff) { // // Send the run command but just send the packet, there will likely // be no boot loader to answer after this command completes. // g_pui8Buffer[0] = COMMAND_RUN; g_pui8Buffer[1] = (uint8_t)(g_ui32StartAddress>>24); g_pui8Buffer[2] = (uint8_t)(g_ui32StartAddress>>16); g_pui8Buffer[3] = (uint8_t)(g_ui32StartAddress>>8); g_pui8Buffer[4] = (uint8_t)g_ui32StartAddress; if(SendPacket(g_pui8Buffer, 5, 0) < 0) { printf("Failed to Send Run command\n"); } else { printf("Running from address %08x\n",g_ui32StartAddress); } }