937
void main(void) { // Configure PORTB as output for DAC TRISB = 0x00; // Configure RC0 as input for switch TRISCbits.TRISC0 = 1; // Initialize index variable uint8_t i = 0; // Initialize switch state variable uint8_t switchState = 0; // Main loop while(1) { // Read switch state switchState = PORTCbits.RC0; // Generate sinusoidal or triangular waveform based on switch state if (switchState == 0) { // Output the sine wave value to DAC DAC_OUT = SineTable[i++]; } else { // Output the triangular wave value to DAC DAC_OUT = TriangleTable[i++]; } // Delay for the desired waveform frequency __delay_us(390); // Adjust delay for desired frequency // Reset index if end of waveform table is reached if (i == 64) i = 0; } return; }