int main(void) { //Code geoptimaliseerd voor bordje 3 //###1### //Initialize subsystems ClockInit(); //Initialize system clock (16 MHz) USARTInit(); //Initialize USART and bind to stdout,stdin AnalogInit(); //Initialize ADC AccInit(); //Initialize accelerometer system LEDInit(); //Initialize LEDs SwitchInit(); //Initialize switches EncoderInit(); //Initialize encoder SpeakerInit(); //Initialize speaker system //Enable interrupts PMIC.CTRL|=0b00000111; //Enable low, medium, high priority interrupts SREG|=0b10000000; //Globale interrupt enable //###2### //Print the digits 0 to 9 5x on terminal device //Reason this section didn't work: de variabelen 'a' is globaal gedefinieerd. In het subprogramma 'SimpleFunction()' wordt //de variabelen 'a' gebruikt. Na dit subprogramma is de waarde van 'a' gelijk aan 10 en zal de lus (a<5) onderbroken worden. for (a=0; a<5; a++) { SimpleFunction(); printf ("\r\n"); } //###3### //Main program loop a=0; ledOn=0b00001000; //Beeps(); //Genereer 3 beeps van 500hz, 1000hz, 1500hz (500 ms) setNotes(); //Stel een reeks van noten in playNextNote(); //Speel de eerste noot uit de reeks while(1) { LoopLicht(); //LoopLicht sequentie AccLezen(); //Accelerometer lezen printf("$SWITCH %d\r\n", SwitchGet()); //Switchwaarde over USARTD: 1: center, 2: rechts, 4: beneden, 8: links, 16: boven printf("$ACCRAW %d %d %d\r\n", RawAccX, RawAccY, RawAccZ); //Ongecalibreerde waardes accelerometer x, y, z over USARTD printf("$ACC__ %d %d %d\r\n", AccGetXAxis(RawAccX), AccGetYAxis(RawAccY), AccGetZAxis(RawAccZ)); //Gecalibreerde waardes accelerometer x, y, z over USARTD printf("$ENC__ %d\r\n", EncoderGetPos()); //printf ("Counter:%d\r\n",a); //printf("%c", 0x55); //Stuur de waarde 0x55 uit (0b01010101) //a++; _delay_ms(20); } }
int main(void) { uint16_t i = 0; OscInit(); AnalogInit(); OutputInit(); PPSInit(); Timing_Init(); UART_DMA_Init(); UI_LED_Initialize(); for (i=0; i<UI_LED_Count; i++) { UI_LED_SetState(UI_LED_List[i], LED_On); } UI_LED_Update(); DBG_printf("\r\n"); DBG_printf("\2330;36mCalsol Datalogger v%u.%u (alpha)\23337m", VERSION_MAJ, VERSION_MIN); DBG_printf("\23336m Built %s %s with C30 ver %i\23337m", __DATE__, __TIME__, __C30_VERSION__); DBG_DATA_printf("\23336mDevice reset:%s%s%s%s%s%s%s%s\23337m", (RCONbits.TRAPR? " Trap" : ""), (RCONbits.IOPUWR? " IllegalOpcode/UninitializedW" : ""), (RCONbits.CM? " ConfigMismatch" : ""), (RCONbits.EXTR? " ExternalReset" : ""), (RCONbits.SWR? " SoftwareReset" : ""), (RCONbits.WDTO? " WatchdogTimeout" : ""), (RCONbits.BOR? " BrownOutReset" : ""), (RCONbits.POR? " PowerOnReset" : "") ); ECAN_Init(); ECAN_Config(); C1FCTRLbits.FSA = 4; // FIFO starts C1FEN1 = 0; ECAN_SetStandardFilter(0, 0x00, 0, 15); ECAN_SetStandardMask(0, 0x00); ECAN_SetMode(ECAN_MODE_OPERATE); ECAN_SetupDMA(); UI_Switch_Update(); if (UI_Switch_GetTest()) { DBG_printf("Entering test mode"); UI_LED_SetState(&UI_LED_Fault, LED_Blink); while (UI_Switch_GetTest()) { UI_LED_Update(); UI_Switch_Update(); } UI_LED_SetState(&UI_LED_Fault, LED_Off); UI_LED_Update(); } for (i=0; i<UI_LED_Count; i++) { UI_LED_SetState(UI_LED_List[i], LED_Off); } DBG_printf("Initialization complete"); Datalogger_Init(); while(1) { Datalogger_Loop(); } }