?? switches.c
字號:
/*****************************************************************************/
/* FILENAME */
/* switches.c */
/* */
/* DESCRIPTION */
/* Read the four DIP user input switches on TMS320C5416 DSK and convert */
/* to a number in the range 0-15. */
/* Display meaning of switch setting on Stdout. */
/* */
/* VERSION */
/* 1.01 */
/* */
/* AUTHOR */
/* Bao Xiaojing */
/* */
/* REVISION HISTORY */
/* VER DATE AUTHOR DESCRIPTION */
/* ------------------------------------------------------------------------ */
/* 1.01 2008.12.06 Bao Xiaojing Update 3 audio effects. */
/* 1.00 2002.10.30 Richard Sikora Initial version. */
/* */
/*****************************************************************************/
#include <stdio.h> /* Required for functions printf() and puts() */
/*****************************************************************************/
/* */
/* The name of the following header file will change if used as part of a */
/* different project. New project xxxx will use xxxxcfg.h instead. */
/* */
/*****************************************************************************/
#include "AudioEffectcfg.h"
#include "dsk5416.h"
#include "dsk5416_dip.h"
/*****************************************************************************/
/* user_switches_read() */
/*---------------------------------------------------------------------------*/
/* Read switch values from CPLD. */
/* The value in range 0 - 15 is then debounced in switch_status_display() */
/* */
/*****************************************************************************/
static unsigned int user_switches_read(void)
{
unsigned int temp;
temp = 0;
if ( DSK5416_DIP_get(0) )
{
/* Switch 0 is on */
temp = 0x0001;
}
if ( DSK5416_DIP_get(1) )
{
/* Switch 1 is on */
temp |= 0x0002;
}
if ( DSK5416_DIP_get(2) )
{
/* Switch 2 is on */
temp |= 0x0004;
}
if ( DSK5416_DIP_get(3) )
{
/* Switch 3 is on */
temp |= 0x0008;
}
/* Return value built up in temp */
return( temp );
}
/*****************************************************************************/
/* switch_status_display(). */
/*---------------------------------------------------------------------------*/
/* */
/* Read switch value every tenth of a second. */
/* Display meaning of switch on Stdout. */
/* */
/*****************************************************************************/
unsigned int switch_status_display(void)
{
static unsigned int last_switch_values[2] = {99,99};
static unsigned int current_switch_value = 0;
static unsigned int counter = 0;
unsigned int temp;
/* The variable 'counter' reaches zero 10 times per second. */
/* Check the switch reading. */
if ( 0 == counter)
{
/* Read latest switch settings. */
temp = user_switches_read();
/* Test if switch reading is the same as the last one. */
if ( temp == last_switch_values[0] )
{
/* Same reading as last time. Two identical values received */
current_switch_value = temp; /* Use new value */
/* Only update display on Stdout when switch has just changed */
if ( temp != last_switch_values[1] )
{
/* Reading at switches has changed. */
/* Display new switch value. */
if ( 0 == temp )
{
puts("User switches = 0.\n");
}
else if ( 1 == temp)
{
puts("User switches = 1.\n");
}
else if ( 2 == temp )
{
puts("User switches = 2.\n");
}
else if ( 3 == temp )
{
puts("User switches = 3.\n");
}
else if ( 4 == temp )
{
puts("User switches = 4.\n");
}
else if ( 5 == temp)
{
puts("User switches = 5.\n");
}
else if ( 6 == temp )
{
puts("User switches = 6.\n");
}
else if ( 7 == temp )
{
puts("User switches = 7.\n");
}
else if ( 8 == temp)
{
puts("User switches = 8.\n");
}
else if ( 9 == temp )
{
puts("User switches = 9.\n");
}
else if ( 10 == temp )
{
puts("User switches = 10.\n");
}
else if ( 11 == temp )
{
puts("User switches = 11.\n");
}
else if ( 12 == temp)
{
puts("User switches = 12.\n");
}
else if ( 13 == temp )
{
puts("User switches = 13.\n");
}
else if ( 14 == temp )
{
puts("User switches = 14.\n");
}
else if ( 15 == temp )
{
puts ("User switches = 15.\n");
}
else
{
/* User switches outside the allowed range 0 - 15 */
puts ("User switches out of range.\n");
}
}
}
/* Shuffle switch readings along one place ready for next time. */
/* Then read in current switch status. */
last_switch_values[1] = last_switch_values[0];
last_switch_values[0] = temp;
}
/* Increment counter. If at maximum or over-range, go back to zero. */
if ( counter < 2400)
{
counter++;
}
else
{
/* Counter is at maximum value of 2400 or out of range. */
/* Go back to the beginning. */
counter = 0;
}
return(current_switch_value);
}
/******************************************************************************/
/* End of switches.c */
/******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -