📄 user_func.c
字号:
{
ButtFlags |= BUTT_FLAG_2 + BUTT_EVENT_2;
}
}
else
{
++ButtCount2;
}
}
else
{
if ( ButtCount2 == 0 )
{
if ( ButtFlags & BUTT_FLAG_2 )
{
ButtFlags &= ~BUTT_FLAG_2;
}
}
else
{
--ButtCount2;
}
}
//************************************************************************
if ( !IO0PIN_bit.P0_15 )
{
if ( ButtCount3 > BUTT_DEB )
{
if ( ( ButtFlags & BUTT_FLAG_3 ) == 0 )
{
ButtFlags |= BUTT_FLAG_3 + BUTT_EVENT_3;
}
}
else
{
++ButtCount3;
}
}
else
{
if ( ButtCount3 == 0 )
{
if ( ButtFlags & BUTT_FLAG_3 )
{
ButtFlags &= ~BUTT_FLAG_3;
}
}
else
{
--ButtCount3;
}
}
//************************************************************************
if ( !IO0PIN_bit.P0_16 )
{
if ( ButtCount4 > BUTT_DEB )
{
if ( ( ButtFlags & BUTT_FLAG_4 ) == 0 )
{
ButtFlags |= BUTT_FLAG_4 + BUTT_EVENT_4;
}
}
else
{
++ButtCount4;
}
}
else
{
if ( ButtCount4 == 0 )
{
if ( ButtFlags & BUTT_FLAG_4 )
{
ButtFlags &= ~BUTT_FLAG_4;
}
}
else
{
--ButtCount4;
}
}
}
/********************************************************************************************************************
【函数名称】void LEDs_Set( unsigned char m )
【功能描述】LED显示设置
【参数输入】无
【参数返回】无
********************************************************************************************************************/
unsigned char Buttons_Get( void )
{
if ( IO0PIN_bit.P0_5 == 0 )
return 1 ;
if ( IO0PIN_bit.P0_6 == 0 )
return 2 ;
if ( IO0PIN_bit.P0_15 == 0 )
return 3 ;
if ( IO0PIN_bit.P0_16 == 0 )
return 4 ;
return 0 ;
}
/********************************************************************************************************************
【函数名称】void LEDs_Set( unsigned char m )
【功能描述】LED显示设置
【参数输入】无
【参数返回】无
********************************************************************************************************************/
void Buttons_Test( void )
{
unsigned char m ;
unsigned char key ;
UART_PutStringByPolling( UART0 , "\n\rButtons Test, Please press the buttons, 'ESC' to exit!\n\r" );
while ( 1 )
{
key = Buttons_Get() ;
if ( key != 0 )
LEDs_Set( 3 << ( ( key - 1 ) * 2 ) ) ;
else
LEDs_Set( 0x00 ) ;
m = UART_GetKeyByPolling( UART0 ) ;
if ( m == ESC_KEY )
return ;
}
}
/*************************************************************************
* Function Name: GetButtonsEvent
* Parameters: none
* Return: LPC_INT8U
* Description: Return buttons event and clear event flags
*
*************************************************************************/
LPC_INT8U GetButtonsEvent( void )
{
LPC_INT8U Events = ButtFlags & ( BUTT_EVENT_1 | BUTT_EVENT_2 );
ButtFlags &= ~( BUTT_EVENT_1 | BUTT_EVENT_2 );
return Events;
}
/*************************************************************************
* Function Name: ClearFlag
* Parameters: void
* Return: void
*
* Description: clear arg
*
*************************************************************************/
void SetSysTickFlag( void* arg )
{
int* pFlag = arg;
*pFlag = 1;
Buttons();
}
/*************************************************************************
* Function Name: LightInit
* Parameters: none
* Return: none
* Description: Init light control
*
*************************************************************************/
void LightInit( void )
{
/* pin P0_21 is IO port */
PINSEL1_bit.P0_21 = 0;
/* pin P0_21 is output */
IO0DIR_bit.P0_21 = 1 ;
/* Init Current state of light */
LightState = LIGHT_OFF;
}
/*************************************************************************
* Function Name: LightInit
* Parameters: LPC_BOOL Slow,
LPC_BOOL On
* Return: none
* Description: Light control
*
*************************************************************************/
void LightCntr( LPC_BOOL On )
{
if ( On == LIGHT_ON )
{
IO0SET_bit.P0_21 = LIGHT_ON ;
LightState = LIGHT_ON ;
}
else
{
IO0CLR_bit.P0_21 = LIGHT_OFF ;
LightState = LIGHT_OFF ;
}
}
/*************************************************************************
* Function Name: Adc ADC_Measure
* Parameters: none
* Return: none
* Description: Light control
*
*************************************************************************/
void ADC_Init( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
/* ADC Chanel3 is connected to pin P0_30 */
PINSEL1_bit.P0_30 = 1;
/* ADC Settings */
AD0CR_bit.SEL = 1 << 3;
AD0CR_bit.CLKDIV = SYS_GetFpclk() / MAX_ADC_FREQ;
AD0CR_bit.BURST = 0;
AD0CR_bit.PDN = 1;
AD0CR_bit.TEST = 0;
AD0CR_bit.START = 0;
ADC_Measure( pVarArg , MenuIndex , MenuTO );
}
/*************************************************************************
* Function Name: Adc ADC_Measure
* Parameters: MEMU_STING_DEF * pVarArg,
* MEMU_IND_DEF * MenuIndex,
* MEMU_TIME_OUT_DEF * MenuTO
* Return: none
* Description: Light control
*
*************************************************************************/
void ADC_Measure( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
LPC_INT32U AdcResult;
LPC_INT8U Count;
int i;
/* ADC Conversion start */
AD0CR_bit.START = 1;
/* Delay needed when executing from flash, unknown why */
for ( i = 0; i < 32; i++ )
__no_operation();
/* Wait result */
do
{
AdcResult = AD0DR;
}
while ( ( AdcResult & 0x80000000 ) == 0 );
AdcResult = ( AdcResult >> 12 ) & 0xF;
for ( Count = 0; Count < 16; ++Count )
{
if ( AdcResult )
{
*pVarArg = '*';
--AdcResult;
}
else
{
*pVarArg = ' ';
}
++pVarArg;
}
*pVarArg = 2;
*++pVarArg = 0;
}
/********************************************************************************************************************
【函数名称】void ADC_Channel_3_Init( void )
【功能描述】ADC通道3初始化
【参数输入】无
【参数返回】无
********************************************************************************************************************/
void ADC_Channel_3_Init( void )
{
/* ADC Chanel3 is connected to pin P0_30 */
PINSEL1_bit.P0_30 = 1;
/* ADC Settings */
AD0CR_bit.SEL = 1 << 3;
AD0CR_bit.CLKDIV = SYS_GetFpclk() / MAX_ADC_FREQ;
AD0CR_bit.BURST = 0;
AD0CR_bit.PDN = 1;
AD0CR_bit.TEST = 0;
AD0CR_bit.START = 0;
}
/********************************************************************************************************************
【函数名称】unsigned int ADC_Channel_3_Measure( void )
【功能描述】ADC通道3进行模数转换
【参数输入】无
【参数返回】返回ADC转换的值
********************************************************************************************************************/
unsigned int ADC_Channel_3_Measure( void )
{
unsigned int AdcResult;
int i;
/* ADC Conversion start */
AD0CR_bit.START = 1;
/* Delay needed when executing from flash, unknown why */
for ( i = 0; i < 32; i++ )
__no_operation();
/* Wait result */
do
{
AdcResult = AD0DR;
}
while ( ( AdcResult & 0x80000000 ) == 0 );
AdcResult = ( AdcResult >> 6 ) & 0x3ff;
return AdcResult ;
}
/********************************************************************************************************************
【函数名称】void ADC3_Input_Test( void )
【功能描述】ADC3通道模数转换实验
【参数输入】无
【参数返回】无
********************************************************************************************************************/
void ADC3_Input_Test( void )
{
unsigned int a ;
unsigned char m ;
unsigned int adc[16] ;
unsigned int FEQ = 500 ;
Uart_Printf( UART0, "\nADC3_Test, 'ESC' key to exit\n" );
ADC_Channel_3_Init() ;
while ( UART_GetKeyByPolling( UART0 ) != ESC_KEY )
{
for( m = 0; m < 16; m++ ) //16次采样
{
adc[m] = ADC_Channel_3_Measure(); //AIN6是温度检测
}
for( m = 1; m < 16; m++ ) //取平均值
{
adc[0] = adc[0] + adc[m] ;
}
a = adc[0] / 16 ; //平均值
if( FEQ > 1 )
FEQ-- ;
else
{
FEQ = 500 ;
Uart_Printf( UART0, " AIN6 : %04d\n" , a );
}
}
}
/********************************************************************************************************************
【函数名称】void ADC_Channel_6_Init( void )
【功能描述】ADC通道6初始化
【参数输入】无
【参数返回】无
********************************************************************************************************************/
void ADC_Channel_6_Init( void )
{
/* ADC Chanel6 is connected to pin P0_04 */
PINSEL0_bit.P0_4 = 3;
/* ADC Settings */
AD0CR_bit.SEL = 1 << 6;
AD0CR_bit.CLKDIV = SYS_GetFpclk() / MAX_ADC_FREQ;
AD0CR_bit.BURST = 0;
AD0CR_bit.PDN = 1;
AD0CR_bit.TEST = 0;
AD0CR_bit.START = 0;
}
/********************************************************************************************************************
【函数名称】unsigned int ADC_Channel_6_Measure( void )
【功能描述】ADC通道6进行模数转换
【参数输入】无
【参数返回】返回ADC转换的值
********************************************************************************************************************/
unsigned int ADC_Channel_6_Measure( void )
{
unsigned int AdcResult;
int i;
/* ADC Conversion start */
AD0CR_bit.START = 1;
/* Delay needed when executing from flash, unknown why */
for ( i = 0; i < 32; i++ )
__no_operation();
/* Wait result */
do
{
AdcResult = AD0DR;
}
while ( ( AdcResult & 0x80000000 ) == 0 );
AdcResult = ( AdcResult >> 6 ) & 0x3ff;
return AdcResult ;
}
/*************************************************************************
* Function Name: IlluminationShow
* Parameters: MEMU_STING_DEF * pVarArg,
* MEMU_IND_DEF * MenuIndex,
* MEMU_TIME_OUT_DEF * MenuTO
* Return: none
* Description: Ilumination show
*
*************************************************************************/
void IlluminationShow( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
const char* SourceData = IlluminationModeStr[LightMode];
for ( int i = 0; i < 10; ++i )
{
if ( *SourceData )
{
*pVarArg = *SourceData;
++SourceData;
}
else
{
*pVarArg = ' ';
}
++pVarArg;
}
*pVarArg = 2;
*++pVarArg = 0;
}
/*************************************************************************
* Function Name: IlluminationModeCursorOn
* Parameters: MEMU_STING_DEF * pVarArg,
* MEMU_IND_DEF * MenuIndex,
* MEMU_TIME_OUT_DEF * MenuTO
* Return: none
* Description: Ilumination cursor on
*
*************************************************************************/
void IlluminationModeCursorOn( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
HD44780_CursorPosSet( HD44780_CURSOR_OFF , HD44780_CURSOR_BLINK , 8 , 2 );
}
/*************************************************************************
* Function Name: IlluminationNextMode
* Parameters: MEMU_STING_DEF * pVarArg,
* MEMU_IND_DEF * MenuIndex,
* MEMU_TIME_OUT_DEF * MenuTO
* Return: none
* Description: Ilumination next
*
*************************************************************************/
void IlluminationNextMode( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
if ( ++LightMode > 2 )
{
LightMode = 0;
}
IlluminationShow( pVarArg , MenuIndex , MenuTO );
}
/*************************************************************************
* Function Name: IlluminationNextMode
* Parameters: MEMU_STING_DEF * pVarArg,
* MEMU_IND_DEF * MenuIndex,
* MEMU_TIME_OUT_DEF * MenuTO
* Return: none
* Description: Cursor off
*
*************************************************************************/
void CursorOff( MEMU_STING_DEF* pVarArg , MEMU_IND_DEF* MenuIndex , MEMU_TIME_OUT_DEF* MenuTO )
{
HD44780_CursorPosSet( HD44780_CURSOR_OFF , HD44780_CURSOR_NORM , 1 , 1 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -