This C program uses a DSP to generate a sine wave and control an LED with a dip switch. It initializes peripherals like the codec and dip switches. An infinite loop outputs the sine wave to the codec based on the value of a sine table. It toggles an LED when dip switch 0 is pressed for on_time seconds by tracking a delay counter and flag variable. The LED turns off when the switch is released or the on_time expires.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
44 views2 pages
Prog LED
This C program uses a DSP to generate a sine wave and control an LED with a dip switch. It initializes peripherals like the codec and dip switches. An infinite loop outputs the sine wave to the codec based on the value of a sine table. It toggles an LED when dip switch 0 is pressed for on_time seconds by tracking a delay counter and flag variable. The LED turns off when the switch is released or the on_time expires.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2
//Sine_led_ctrl.
c Sine generation with DIP Switch control
#include "dsk6713_aic23.h" //codec-dsk support file Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate short sine_table[8]={0,707,1000,707,0,-707,-1000,-707};//sine values short loop=0, gain=10; short j=0, k = 0; //delay counter short flag = 0; //for LED on short const delay = 800; //for delay loop short on_time = 2; //led is on for on-time secs void main() { comm_poll(); //init BSL DSK6713_LED_init(); //init LEDs DSK6713_DIP_init(); //init DIP SWs while(1) //infinite loop { if(DSK6713_DIP_get(0)==0 &&(k<=(on_time*5))) //if SW0 pressed { if(flag==0) DSK6713_LED_toggle(0); //LED0 toggles else DSK6713_LED_off(0); //turn LED0 off output_sample(sine_table[loop]*gain);//output with gain if (loop < 7) loop++; //increment loop index else loop = 0; //reinit if end of table if (j < delay) ++j; //delay counter else { j = 0; //reset delay counter if (flag == 1) { flag = 0; //if flag=1 toggle LED k++; } else flag = 1; //toggle flag } } else { DSK6713_LED_off(0); //turn off LED0 if(DSK6713_DIP_get(0)==1) k=0;//If LED0 off reset counter } } } FIGURE 2.27 //Record.c Illustrates use of external memory with voice as input #include "dsk6713_aic23.h" //codec-DSK support file Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate #define N 2400000 //large buffer size long i; short var; //flag when recording/playing short buffer[N]; #pragma DATA_SECTION(buffer,".EXTRAM") //buffer->external memory void main() { comm_poll(); //init DSK, codec, McBSP DSK6713_DIP_init(); DSK6713_LED_init(); while(1) //infinite loop { if(DSK6713_DIP_get(3) == 0) //if SW#3 is pressed { DSK6713_LED_on(3); //turn on LED#3 for (i = 0; i<N; i++) buffer[i] = input_sample(); //input data DSK6713_LED_off(3); //LED#3 off when buffer full break; } }; var = 0; while(1) { if((DSK6713_DIP_get(0)==0)&&(var==0)) //if SW#0 pressed/var=0 { DSK6713_LED_on(0); //turn on LED#0 for (i = 0; i<N; i++) output_sample(buffer[i]*10); //play back var=1; DSK6713_LED_off(0); //LED#0 off when finished } if(DSK6713_DIP_get(0)==1) var=0; //toggle flag }; } FIGURE 2.28. C source program to illustrate the use of input voice stored in external memory (record.c).