📄 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. */
/* */
/* REVISION */
/* Revision: 1.00 */
/* Author : Richard Sikora */
/*---------------------------------------------------------------------------*/
/* */
/* HISTORY */
/* Revision 1.00 */
/* 2nd November 2002. Created by Richard Sikora from TMS320C5402 DSK code. */
/* */
/*****************************************************************************/
#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 "spectrum_analysercfg.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. Set input reference levels.\n");
}
else if ( 1 == temp)
{
puts("User switches = 1. Power spectrum 375 Hz, 750 Hz, 1125 Hz and 1500 Hz.\n");
}
else if ( 2 == temp )
{
puts("User switches = 2. Power spectrum 1875 Hz, 2250 Hz, 2625 Hz and 3000 Hz.\n");
}
else if ( 3 == temp )
{
puts("User switches = 3. Power spectrum 3375 Hz, 3750 Hz, 4125 Hz and 4500 Hz.\n");
}
else if ( 4 == temp )
{
puts("User switches = 4. Bargraph of power spectrum at 375 Hz.\n");
}
else if ( 5 == temp)
{
puts("User switches = 5. Bargraph of power spectrum at 750 Hz.\n");
}
else if ( 6 == temp )
{
puts("User switches = 6. Bargraph of power spectrum at 1125 Hz.\n");
}
else if ( 7 == temp )
{
puts("User switches = 7. Bargraph of power spectrum at 1500 Hz.\n");
}
else if ( 8 == temp)
{
puts("User switches = 8. Bargraph of power spectrum at 1875 Hz.\n");
}
else if ( 9 == temp )
{
puts("User switches = 9. Bargraph of power spectrum at 2250 Hz.\n");
}
else if ( 10 == temp )
{
puts("User switches = 10. Bargraph of power spectrum at 2625 Hz.\n");
}
else if ( 11 == temp )
{
puts("User switches = 11. Bargraph of power spectrum at 3000 Hz.\n");
}
else if ( 12 == temp)
{
puts("User switches = 12. Bargraph of power spectrum at 3375 Hz.\n");
}
else if ( 13 == temp )
{
puts("User switches = 13. Bargraph of power spectrum at 3750 Hz.\n");
}
else if ( 14 == temp )
{
puts("User switches = 14. Bargraph of power spectrum at 4100 Hz.\n");
}
else if ( 15 == temp )
{
puts ("User switches = 15. Bargraph of power spectrum at 4475 Hz.\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 < 4800)
{
counter++;
}
else
{
/* Counter is at maximum value of 4800 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 + -