AN123 Silicon_Laboratories, AN123 Datasheet - Page 9

no-image

AN123

Manufacturer Part Number
AN123
Description
Using THE DAC AS A Function Generator
Manufacturer
Silicon_Laboratories
Datasheet
UART0_Init ();
EA = 1;
Print_Command_List();
while(1){
// get user input
printf (“ENTER A COMMAND:>”);
gets(input_str,sizeof(input_str));
input_str[0] = toupper(input_str[0]); // convert the two characters
input_str[1] = toupper(input_str[1]); // in the command to uppercase
// Parse the command
for (i = 0; i < num_commands; i++){
// strncmp() returns 0 if the first two arguments are the same string
// set <i> for the command that matched
if (0 == strncmp(input_str, function_table[i].command, command_length)){
arg_ptr1 = strchr (input_str, ‘ ‘);
arg_ptr1++;
arg_ptr2 = strchr(arg_ptr1, ‘ ‘);
arg_ptr2++;
temp_frequency = atol(arg_ptr1);
temp_amplitude = atol(arg_ptr2);
// check to make sure entered frequency is valid
if (temp_frequency) {
} else {
}
// check to make sure entered amplitude is valid
if ((temp_amplitude > 0) && (temp_amplitude <=100)){
} else {
}
frequency = temp_frequency;
printf(“\n** Frequency will not change\n”);
// multiply by 655 to be divided by 65535 (16-bit shift) in the
// ISR; this is an optimization to reduce the number of
// instructions executed in the ISR
amplitude = temp_amplitude * 655;
printed_amplitude = temp_amplitude;
printf(“\n** Amplitude will not change\n”);
// Enable global interrupts
Rev. 1.1
// wait for input
// point to the frequency
// point to amplitude
AN123
9

Related parts for AN123