⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test__.c

📁 UCOS-II ATMEGA128 移殖
💻 C
📖 第 1 页 / 共 5 页
字号:
      		else if ( ( 300 < key_adc_value) && ( key_adc_value < 450))
        		KEY_value = 0x03;
      		else if ( (400 < key_adc_value) && ( key_adc_value < 550))
        		KEY_value = 0x04; 
      		else if ( key_adc_value > 550) 
        		KEY_value = 0x05;  
        		
		// new key in key press 
         	if( !F_KEY_1IN )	//|| ( KEY_value != key_last_value ) )
         	{
                       	F_KEY_1IN = 1; 
                       	F_KEY_OK=1;
         	}          

        	//key press keep
	        else if( ++key_timer >= 100 && ( (key_timer%25) == 0))
	        {
              		F_KEY_OK=1;
            }
	}
         
        //key realease                
        else 
        {
        	if(F_KEY_1REL)
            	{
            		F_KEY_1REL=0;
                	F_KEY_1IN=0;
            	}
            
          	else
          	{       
          		key_timer=0;
          		F_KEY_1REL=1;
          	}
        }
} 
   
static void KeyScanTask(void *p_arg)
{
	OS_CPU_SR cpu_sr;
	INT8U	err;

	while(1)
	{	
		KEY_SCAN(ADCW);
		if(F_KEY_OK)
		{
 			F_KEY_OK = 0;
 			OS_ENTER_CRITICAL();
 			menu_select(KEY_value);
 			OS_EXIT_CRITICAL();
			OSSemPost(LedSem);		
		}
	//	OSTimeDly(3);	
		OS_ENTER_CRITICAL();
		ADMUX = ADC_KEY_CHANNEL;//切换到KEY
		ADCSRA &=~ (1<<ADIF) ;       		   
 		ADCSRA |= (1 << ADSC);				//*重新启动ADC
 		OS_EXIT_CRITICAL();
 		OSTimeDly(OS_TICKS_PER_SEC/8);
 	}
}
  
void menu_display(char flash *flash_disp_ptr)
{
	unsigned char i;

	for(i = 0; i < 8; i ++)
		{                                     
			disp_buf[i] = *flash_disp_ptr ++;
		} 
}

/***********************************************************************************/
//			根据键值选择菜单   
//
//	KEY_UP		向上移动菜单项
//	KEY_DOWN	向下移动菜单项
//	KEY_ENTER	进入下一层菜单或执行菜单命令
//	KEY_ESC		回到上一层菜单   
//
// note  : 
//
// input :
//	(1)unsigned char key
// output:
//
/**********************************************************************************/
flash unsigned char  MenuUp[6][9]={
{"11111111"},
{"22222222"},
{"33333333"},
{"44444444"},
{"55555555"},
{"66666666"}
};
//flash unsigned char  MenuDown[]="44444444";
unsigned char fff=0;
void menu_select(unsigned char key)
{        

	if(fff>5)
		fff=5;
	switch(key)
	{					
        case KEY_UP:
       	{                                   	
		   	if(fff < 5 && flash_bit == 1)
		   	{
		   		fff++;
		   	menu_display(&MenuUp[fff][0]);
		   	}	                          
        	break;
    	}                       
     	case KEY_DOWN:
      	{                                                	                       	                	
			
			if(fff != 0 && flash_bit == 1)
			{
				fff--;
				
			menu_display(&MenuUp[fff][0]);
			}               	                    
            break;
      	}                        
       	case KEY_ENTER:
        {       
			//menu_display(MenuEnter);
			flash_bit = 1;
           	break;
       	}                         
        case KEY_ESC:
        {                       
        	//menu_display(MenuEsc);
        	flash_bit = 0;
            break;
       	} 
 
        default:
       	break;
	}
} 

static void MenuProcTask(void *p_arg)
{
}
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*                                             CORE FUNCTIONS
*
*                          (c) Copyright 1992-2003, Jean J. Labrosse, Weston, FL
*                                           All Rights Reserved
*
* File    : OS_CORE.C
* By      : Jean J. Labrosse
* Version : V2.76
*********************************************************************************************************
*/

#ifndef  OS_MASTER_FILE
#define  OS_GLOBALS
#include "ucos_ii.h"
#endif

/*
*********************************************************************************************************
*                              MAPPING TABLE TO MAP BIT POSITION TO BIT MASK
*
* Note: Index into table is desired bit position, 0..7
*       Indexed value corresponds to bit mask
*********************************************************************************************************
*/

INT8U  const  OSMapTbl[8]   = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

/*
*********************************************************************************************************
*                                       PRIORITY RESOLUTION TABLE
*
* Note: Index into table is bit pattern to resolve highest priority
*       Indexed value corresponds to highest priority bit position (i.e. 0..7)
*********************************************************************************************************
*/

INT8U  const  OSUnMapTbl[256] = {
    0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x00 to 0x0F                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x10 to 0x1F                             */
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x20 to 0x2F                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x30 to 0x3F                             */
    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x40 to 0x4F                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x50 to 0x5F                             */
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x60 to 0x6F                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x70 to 0x7F                             */
    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x80 to 0x8F                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x90 to 0x9F                             */
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xA0 to 0xAF                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xB0 to 0xBF                             */
    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xC0 to 0xCF                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xD0 to 0xDF                             */
    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xE0 to 0xEF                             */
    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0        /* 0xF0 to 0xFF                             */
};

/*$PAGE*/
/*
*********************************************************************************************************
*                                       FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static  void  OS_InitEventList(void);
static  void  OS_InitMisc(void);
static  void  OS_InitRdyList(void);
static  void  OS_InitTaskIdle(void);
#if OS_TASK_STAT_EN > 0
static  void  OS_InitTaskStat(void);
#endif
static  void  OS_InitTCBList(void);
  
/*$PAGE*/
/*
*********************************************************************************************************
*                         GET THE NAME OF A SEMAPHORE, MUTEX, MAILBOX or QUEUE
*
* Description: This function is used to obtain the name assigned to a semaphore, mutex, mailbox or queue.
*
* Arguments  : pevent    is a pointer to the event group.  'pevent' can point either to a semaphore,
*                        a mutex, a mailbox or a queue.  Where this function is concerned, the actual
*                        type is irrelevant.
*
*              pname     is a pointer to an ASCII string that will receive the name of the semaphore,
*                        mutex, mailbox or queue.  The string must be able to hold at least 
*                        OS_EVENT_NAME_SIZE characters.
*
*              err       is a pointer to an error code that can contain one of the following values:
*
*                        OS_NO_ERR                  if the name was copied to 'pname'
*                        OS_ERR_EVENT_TYPE          if 'pevent' is not pointing to the proper event 
*                                                   control block type.
*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
*                        OS_ERR_PEVENT_NULL         if you passed a NULL pointer for 'pevent'
*
* Returns    : The length of the string or 0 if the 'pevent' is a NULL pointer.
*********************************************************************************************************
*/

#if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)
INT8U  OSEventNameGet (OS_EVENT *pevent, char *pname, INT8U *err)
{
    INT8U      len;
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr;
    cpu_sr = 0;                                  /* Prevent compiler warning                           */
#endif    
    OS_ENTER_CRITICAL();
#if OS_ARG_CHK_EN > 0
    if (pevent == (OS_EVENT *)0) {               /* Is 'pevent' a NULL pointer?                        */
        OS_EXIT_CRITICAL();                      /* Yes                                                */
        *err = OS_ERR_PEVENT_NULL;
        return (0);
    }
    if (pname == (char *)0) {                    /* Is 'pname' a NULL pointer?                         */
        OS_EXIT_CRITICAL();                      /* Yes                                                */
        *err = OS_ERR_PNAME_NULL;
        return (0);
    }
#endif
    switch (pevent->OSEventType) {
        case OS_EVENT_TYPE_SEM:
        case OS_EVENT_TYPE_MUTEX:
        case OS_EVENT_TYPE_MBOX:
        case OS_EVENT_TYPE_Q:
             break;

        default:
             OS_EXIT_CRITICAL();
             *err = OS_ERR_EVENT_TYPE;
             return (0);
    }
    len  = OS_StrCopy(pname, pevent->OSEventName);    /* Copy name from OS_EVENT                       */
    OS_EXIT_CRITICAL();
    *err = OS_NO_ERR;
    return (len);
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                         ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE
*
* Description: This function assigns a name to a semaphore, mutex, mailbox or queue.
*
* Arguments  : pevent    is a pointer to the event group.  'pevent' can point either to a semaphore,
*                        a mutex, a mailbox or a queue.  Where this function is concerned, it doesn't
*                        matter the actual type.
*
*              pname     is a pointer to an ASCII string that will be used as the name of the semaphore,
*                        mutex, mailbox or queue.  The string must be able to hold at least 
*                        OS_EVENT_NAME_SIZE characters.
*
*              err       is a pointer to an error code that can contain one of the following values:
*
*                        OS_NO_ERR                  if the requested task is resumed
*                        OS_ERR_EVENT_TYPE          if 'pevent' is not pointing to the proper event 
*                                                   control block type.
*                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
*                        OS_ERR_PEVENT_NULL         if you passed a NULL pointer for 'pevent'
*
* Returns    : None
*********************************************************************************************************
*/

#if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)
void  OSEventNameSet (OS_EVENT *pevent, char *pname, INT8U *err)
{
    INT8U      len;
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr;



    cpu_sr = 0;                                  /* Prevent compiler warning                           */
#endif    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -