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

📄 subfunctions.c

📁 μC/OS-II实验程序说明 软件版本:V1.0 日期:2005-05-25 多任务是指多个任务在操作系统的控制下同时运行
💻 C
字号:
/****************************************************************************
		Copyright (c) 深圳市民德电子科技有限公司  http://www.szminde.cn

 文件名称:subfunctions.c
 版本号:  1.0
 日期:	   2005-05-25
 说明:	   此文件包含demo程序中多数的应用函数。
 调用列表:sys_LCD.c
		   sys_RTC.c
		   sys_IO.c
		   sys_Timer.c
		   sys_UART.c
		   sys_IIC.c
		   sys_ADC.c
		   sys_KeyBoard.c
 修改历史:--
****************************************************************************/

#include <string.h>
#include "def.h"
#include "44b.h"
#include "subfunctions.h"
#include "sys_KeyBoard.h"
#include "sys_LCD.h"
#include "sys_RTC.h"
#include "sys_IO.h"
#include "sys_Timer.h"
#include "sys_UART.h"
#include "sys_IIC.h"
#include "sys_ADC.h"

TIME_STRUC SysTime;
extern int LCDCurrentPrnTxt;
extern void Delay(int time);


/****************************************************************************
  函数名称:ShowMenu()
  说明:	在屏幕上显示菜单。
  调用函数:LCD_Printf()
  输入参数:无
  输出参数:无
****************************************************************************/
void ShowMenu(void)
{
	LCD_Printf("\n");
	LCD_Printf("ES-TAD7100 Board Demo V1.0\n");
    LCD_Printf("\n");
    LCD_Printf("Press on keyboard to select function:\n");
    LCD_Printf(" 1                 Adjust TouchScreen\n");
    LCD_Printf(" 2                 LED_Display\n");
    LCD_Printf(" 3                 LED7_Display\n");
    LCD_Printf(" 4                 Chess Game\n");
    LCD_Printf(" 5                 Config Clock\n");
    LCD_Printf(" 6                 Button Test\n");
    LCD_Printf(" 7                 IIC Test\n");
    LCD_Printf(" 8                 UART Test\n");
    LCD_Printf(" 9                 ADC Test\n");
    LCD_Printf("Cancel             Back to Menu\n");
    LCD_Printf("\n\n\n\n");
}


/****************************************************************************
  函数名称:Beep()
  说明:	让ES-TAD7100开发板上的蜂鸣器响。
  调用函数:SetPWM()
  			Delay()
			StopPWM()
  输入参数:time 让蜂鸣器响的时间
  输出参数:无
****************************************************************************/
void Beep(int time)
{
	SetPWM(1000,50);
	Delay(time);
	StopPWM();
}


/****************************************************************************
  函数名称:LEDRun()
  说明:	跑马灯,让4个LED循环的交替亮灭。
  调用函数:LCD_Cls()
  			Delay()
			LCD_Printf()
			LED_Display()
			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/	
void LEDRun(void)
{	
	int i=1;
	
	LCD_Cls();
    LCD_Printf("\n\n2  LED_Display\n\n");
    LCD_Printf("Please press Cancel to return.");
		
	while(1)
	{	
		for(i=1;i<5;i++)
		{
			LED_Display(i);
			Delay(2000);
			if(GetKey()==15)
			{			
				LED_Display(0);
	    		LCD_Printf("\b");
				return;
			}
		}
	}
}


/****************************************************************************
  函数名称:LED7Run()
  说明:	七段数码管测试,让两个七段数码管循环的显示数字。
  调用函数:LCD_Cls()
  			Delay()
			LCD_Printf()
			LED7A_Display()
			LED7B_Display()
			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/
void LED7Run(void)
{	
	int i=0;
	
	LCD_Cls();
    LCD_Printf("\n\n3  LED7_Display\n\n");
    LCD_Printf("Please press Cancel to return.");
	
	 while(1)
   	 {	
   		LED7A_Display(i%10);
   		LED7B_Display(i/10);
   		
   		i++;
   		
   		if(i>99)
   		{
   			i=0;
   		}
   		
   		Delay(2000);
   		
   		if (GetKey()==15)
		{
			EXIO_82C55A_PORTA=0x00;
    		EXIO_82C55A_PORTB=0x00;
    		LED_Display(0);
    		LCD_Printf("\b");
			return;
		}
   	}  	
}


/****************************************************************************
  函数名称:ButtonTest()
  说明:	按键测试,按不同的按键时让不同的LED点亮。
  调用函数:LCD_Cls()
			LCD_Printf()
			LED_Display()
			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/
void ButtonTest(void)
{
	unsigned char which_key=0xf0;
	
	LCD_Cls();
	LCD_Printf("\n\n6  Button Test\n\n");
	LCD_Printf("Press button S1/2/3/4 to turn on the\n");
    LCD_Printf("corresponding LED1/2/3/4.\n\n");
    LCD_Printf("\n\nPlease press Cancel to return.");
    
    while(1)
    {
    	which_key=0xf0;
    	if (GetKey()==15)
		{	
			LCD_Printf("\b");
			LED_Display(0);
			return;
		}
		
    	which_key=rPDATG&0xf0;
    	
    	 switch(which_key)
        {
	    	case 0xe0:
	    	    LED_Display(1);
	    	    break;
	    	case 0xd0:
	    	    LED_Display(2);
	    	    break;
	    	case 0xb0:
	    	    LED_Display(3);
	    	    break;
	    	case 0x70:
	    	    LED_Display(4);
	    	    break;
	    	default :
	    	    break;
        }              
    }
}


/****************************************************************************
  函数名称:strtobdc()
  说明:	数字的ASCII字符串转换为数字。
  调用函数:无
  输入参数:*s 该字符串
  输出参数:返回转换好的数字
****************************************************************************/
unsigned int strtobdc(char *s)
{
	unsigned long ret;
	int i;

	ret = 0;

	while (*s != '\0') {
		if (*s >= '0' && *s <= '9')
			i = *s - '0';		
		else
			return -1;
		ret = (ret<<4) + i;
		s++;
	}

	return ret;
}


/****************************************************************************
  函数名称:ConfigClk()
  说明:	根据输入数字设置RTC。
  调用函数:LCD_Cls()
			LCD_Printf()
			LED_Display()
			ShowMenu()
			GetKey()
			strtobdc()
			RTCSetTime()
  输入参数:无
  输出参数:无
****************************************************************************/
void ConfigClk(void)
{
	int ky;
	static char str[3]={0};
	int i=0;
	unsigned int hour, min;
	rINTMSK=BIT_GLOBAL;
	
	LCDCurrentPrnTxt=LCDCurrentPrnTxt-3;
	LCD_Printf("Config the clock?\n");
	LCD_Printf("(Enter or Cancel)");
	while(1)
	{
		if(GetKey()==15)
		{
			LCD_Printf("\b");
			LCD_Cls();
			ShowMenu();
			rINTMSK=~(BIT_GLOBAL|BIT_TICK);
			return;
		}
		
		if(GetKey()==14)
		{
			Delay(4000);
			LCDCurrentPrnTxt--;
			LCD_Printf("Input 2 digits followed by Enter.  \n");
			LCD_Printf("New Hour:                          \n");
			Delay(4000);
			
			while(1)
			{	
				ky=GetKey();
				if(ky>=0&&ky<10)
				{
					if(i<2)
					{
						str[i]=ky+'0';
						LCD_Printf("           %2s",str);
						i++;
					}
				}
				else if(ky==14)
				{
					str[i]='\0';
					LCD_Printf("\b");
					hour=strtobdc(str);
					if(hour>=0x24)
					{
					   hour=0;
					}
					SysTime.hour = hour;
					RTCSetTime(&SysTime);
					LCDCurrentPrnTxt--;
					LCDCurrentPrnTxt--;
					LCD_Printf("\b");
					LCD_Printf("Input 2 digits followed by Enter. \n");
					LCD_Printf("New Minute:                       \n");				
					break;
				}
				else if(ky==15)
				{
					i--;
					if(i<0)i=0;
					str[i]='\0';
					LCD_Printf("           %2s",str);
				}
			}
			
			i=0;
			str[1]=0;
			str[2]=0;
			while(1)
			{
				ky=GetKey();
				if(ky>=0&&ky<10)
				{
					if(i<2)
					{
						str[i]=ky+'0';
						LCD_Printf("           %2s",str);
						i++;
					}
				}
				else if(ky==14)
				{
					str[i]='\0';
					LCD_Printf("\b");
					min=strtobdc(str);
					if(min>=0x60)
					{ 
					  min=0;
					}
					SysTime.min =min;
					RTCSetTime(&SysTime);
					LCD_Printf("\b");
					LCDCurrentPrnTxt--;
					LCD_Printf("\b");
					LCD_Cls();
					ShowMenu();
					rINTMSK=~(BIT_GLOBAL|BIT_TICK);
									
					break;
				}
				else if(ky==15)
				{
					i--;
					if(i<0)i=0;
					str[i]='\0';
					LCD_Printf("           %2s",str);
				}
			}
			return;
		}	
	}
}


/****************************************************************************
  函数名称:Display_RTC()
  说明:	显示RTC的时间。
  调用函数:LCD_Printf()
  输入参数:无
  输出参数:无
****************************************************************************/
void Display_RTC(void)
{
	int year;
	int month,day,weekday,hour,min,sec;
	rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
	while(1)
	{
		if(rBCDYEAR == 0x99)
			year = 0x1999;
		else
			year = 0x2000 + rBCDYEAR;
		month=rBCDMON;
		day=rBCDDAY;
		weekday=rBCDDATE;
		hour=rBCDHOUR;
		min=rBCDMIN;
		sec=rBCDSEC;
		if(sec!=0)
			break;
	}
	LCD_Printf("\b");
	LCD_Printf("                           %4x:%2x:%2x",hour,min,sec);
	rRTCCON = 0x00; // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
}


/****************************************************************************
  函数名称:UartTest()
  说明:	测试UART的通信功能。
  调用函数:LCD_Printf()
  			UART_Printf()
  			UART_SendByte()
  			UART_GetKey()
  			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/
void UartTest(void)
{
	static char GetData[5]={0};
	UART_Printf("Type on your PC keyboard\n");
	UART_Printf("Type exit to exit\n");
	
	LCD_Cls();
	LCD_Printf("\n\n8  UART Test\n\n");
	LCD_Printf("This test requires the connecttion with\n");
	LCD_Printf("the PC's hyper-terminal.\n\n");
	LCD_Printf("Please read the tutorial for details.\n\n\n\n");
	LCD_Printf("Exit from the operation on PC's keyboard,\n");
	LCD_Printf("or press Cancel to return.");
	
	while(1)
	{
		GetData[0]=UART_GetKey();
		if(GetData[0]==0x0d)		//Return
			GetData[0]='\n';
		if(GetData[0]==0x08)		//BackSpace
			{UART_SendByte(GetData[0]);
			UART_SendByte(0x20);}
		if(GetData[0]!=0)
		{
			UART_SendByte(GetData[0]);
			if(GetData[4]=='e'&&GetData[3]=='x'&&GetData[2]=='i'
					&&GetData[1]=='t'&&GetData[0]=='\n')
			{
				UART_Printf("\nUART TEST end.\n");
				return;
			}
			GetData[4]=GetData[3];
			GetData[3]=GetData[2];
			GetData[2]=GetData[1];
			GetData[1]=GetData[0];
		}
		
	    if(GetKey()==15)
	    {
	        UART_Printf("\nUART TEST end.\n");      
	        return;
	    }
	}
}


/****************************************************************************
  函数名称:IICTest()
  说明:	测试IIC通信功能。
  调用函数:LCD_Cls()
  			LCD_Printf()
  			IIC_Init()
  			IIC_Write()
  			IIC_Read()
  			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/
void IICTest(void)
{
    U8 read=0,i=0;
    
    LCD_Cls();
    LCD_Printf("\n\n7  IIC Test\n\n");
    LCD_Printf("Watch the LED7s!\n\n");
    LCD_Printf("Please read the tutorial for details.\n\n\n\n");
    LCD_Printf("Press Enter to test it once more.\n");
    LCD_Printf("Or press Cancel to return.");
	
	IIC_Init();
	for(i=0;i<10;i++)
		IIC_Write(i,i);
	
	for(i=0;i<10;i++)
	{
		read=IIC_Read(i);
		LED7A_Display((int)read);
		Delay(1200);
	}
	EXIO_82C55A_PORTA=0x00;
	
	while(1)
	{
		if(GetKey()==15)
		{
			return;
		}
		else if(GetKey()==14)
		{
			for(i=0;i<10;i++)
				IIC_Write(i,i);
	
			for(i=0;i<10;i++)
			{
				read=IIC_Read(i);
				LED7A_Display((int)read);
				Delay(1200);
			}
			EXIO_82C55A_PORTA=0x00;
		}
	}
}


/****************************************************************************
  函数名称:ADCTest()
  说明:	测试ADC的模数转换。
  调用函数:LCD_Cls()
  			LCD_Printf()
  			ADC_Init()
  			ADC_Result()
  			GetKey()
  输入参数:无
  输出参数:无
****************************************************************************/
void ADCTest(void)
{
    U16 result=0;
    ADC_Init(0);

    LCD_Cls();
    LCD_Printf("\n\n9  ADC Test\n");
    LCD_Printf("\nNotes:\n");
    LCD_Printf("The first few results could be wrong.\n");
    LCD_Printf("Please repeat this operation for a few\n");
    LCD_Printf("more times.\n");
    LCD_Printf("\n");
    LCD_Printf("The R65 on the board can be used to\n");
    LCD_Printf("change the ADC value.\n");
    LCD_Printf("\n\nPress Enter to do A/D conversion again\n");
    LCD_Printf("Or press Cancel to return.\n\n\n");
    
    result=ADC_Result();
    LCD_Printf("  ADC result is %4d",result);
    
    while(1)
	{
		if(GetKey()==15)
		{
			return;
		}
		else if(GetKey()==14)
		{
			result=ADC_Result();
    		LCD_Printf("  ADC result is %4d",result);
		}
	}
}

⌨️ 快捷键说明

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