/****************************************************************** ** LedsFlash * * DESCRIPTION: * Flashes all the Leds * * Create: 5/9/2006 9:41:43 PM - Trampas Stern *******************************************************************/ INT LedsFlash(void) { UINT8 i; for (i=1; i<15; i++) { LEDS_U18=0x00; LEDS_U40=0x00; LedsUpdate(); delay_ms(100); LEDS_U18=0xFF; LEDS_U40=0xFF; LedsUpdate(); delay_ms(100); } return NO_ERROR; }
int main(void) { // Init PIC24 InitMain(); // Init modules AudioInInit(); Uart2Init(UART_BAUD_250000, 0); LedsInit(); // Main loop while(1) { if(AudioInIsGetReady()) { Fixed audioSample = AudioInGet(); // Update LEDs LedsUpdate(audioSample); // Print audio sample Uart2RxTasks(); if(Uart2IsPutReady() >= 6) { static const char asciiDigits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; int i = FIXED_TO_INT(audioSample); div_t n; int print = 0; if(i < 0) { Uart2PutChar('-'); i = -i; } if(i >= 10000) { n = div(i, 10000); Uart2PutChar(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 1000 || print) { n = div(i, 1000); Uart2PutChar(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 100 || print) { n = div(i, 100); Uart2PutChar(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 10 || print) { n = div(i, 10); Uart2PutChar(asciiDigits[n.quot]); i = n.rem; } Uart2PutChar(asciiDigits[i]); Uart2PutChar('\r'); } } } }
/****************************************************************** ** LedsSet * * DESCRIPTION: * Sets the state of the leds * * Create: 5/9/2006 9:37:35 PM - Trampas Stern *******************************************************************/ INT LedsSet(UINT8 Led, UINT8 State) { if (Led<=7) { if (State) { BIT_CLEAR(LEDS_U18,Led); }else { BIT_SET(LEDS_U18,Led); } }else if (Led<=14) { Led=Led-8; if (State) { BIT_CLEAR(LEDS_U40,Led); }else { BIT_SET(LEDS_U40,Led); } } return LedsUpdate(); //update the LEDs }