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

📄 example_io.c

📁 C8051F020单片机开发板演示程序
💻 C
字号:
/************************************************************************************
*  Copyright (c), 2004-2007,西安铭朗电子科技有限责任公司
*            All rights reserved.
*
* Http:  www.mlarm.com
* Email: mlarm@mlarm.com
*
* File name: Example_IO.c
*
* Project  : ML-F020ICB
* Processor: C8051F020
* Compiler : Keil C51 Compiler
* 
* Author:  EagleC
* Version: 1.00
* Date:    2007.07.05
* Email:   
* 
* Description: 本文件是IO端口测试程序文件;
*
* Others: none;
*
* Function List:
*
* History:
*   1. Author:       Eagle Cao
*	   Version: 	 1.00
*      Date:         2007.07.05
*      Modification: 建立文件
*
*************************************************************************************/
/************************************************************************************/
// 引用外部头文件
#include  "driver.h"
#include  "api.h"
#include  "ShowLCD.h"
/************************************************************************************/

/************************************************************************************/
// 常量及全局变量定义
extern unsigned long			g_nTimer4s;		//定时器4的次数
/************************************************************************************/

/*************************************************************************************/
//
// 							IO端口测试程序函数定义
//
/*************************************************************************************/

/***********************************************************************************
* Function: IO_Proc;
*
* Description: IO端口测试程序;
*              
* Input:  none;
*
* Return: none;
*
* Note:   none;
************************************************************************************/
void IO_Proc(void)
{
	unsigned char i,cmd;
	unsigned char ucAttri;		//单路IO的属性,0: IO口为漏极开路输出; 1: IO口为推挽输出;
	unsigned char ucDir;		//IO方向   0:输入;  1:输出;
	unsigned char ucSetVal;		//Put IO输出值
	unsigned char  val;			//Get IO输入值
	unsigned int  nSet;			//设置16路IO的整体属性,0, IO口为漏极开路输出; 1, IO口为推挽输出;
	unsigned char flag_;		//是否显示IO数据
	unsigned char *pDraw;
	unsigned char nX;
	unsigned char *pItem; 
	LCDB_ClearScreen();
	Show_Title();
	LCDB_DispFWord(32,8*(20-3),"IO 监 测");
	ucAttri = 0;
	nSet = 0;
	ucSetVal = 0;
	ucDir = 0;
	flag_ = 1;
	Show_IO();
	g_nTimer4s=51;

	while(1)
	{
		EWachdog_Clear();
		cmd = Key_Read();
		if(cmd != CH452_KEY_INVAL)
		{
			ALARM_Ctrl(1);
			Delay_ms(20);
			ALARM_Ctrl(0);			
			switch (cmd)
			{
			case 0x00:			//设置IO端口输出0
				ucSetVal = 0;
				g_nTimer4s=51;
				break;
			case 0x01:			//设置IO端口输出1
				ucSetVal = 1;
				g_nTimer4s=51;
				break;
			case 0x0A:			//设置IO端口的硬件为推挽输出
				nSet = 0xFFFF;
				IO_SetDir(nSet);
				g_nTimer4s=51;
				break;
			case 0x0B:			//设置IO端口的硬件为漏极开路输出
				nSet = 0;
				IO_SetDir(nSet);
				g_nTimer4s=51;
				break;
			case 0x0C:			//更改IO端口的操作方向
				ucDir = !ucDir;
				g_nTimer4s=51;
				break;
			case 0x0D:			//确认
				flag_ = 1;
				Show_ClareX64();
				Show_IO();
				g_nTimer4s=51;
				break;				
			case 0x0E:			//显示说明文件
				flag_ = 0;				
				Show_ClareX64();
				nX = 64;
				pItem = "本测试程序主要测试IO端口的输出、输入"; 
				LCDB_DispFWord(nX, 32,pItem);
				
				pItem = "0:设置IO端口输出0";
				LCDB_DispFWord(nX+16*2, 56,pItem);
				pItem = "1:设置IO端口输出1";
				LCDB_DispFWord(nX+16*3, 56,pItem);
				pItem = "A:设置IO端口的硬件为推挽输出";
				LCDB_DispFWord(nX+16*4, 56,pItem);
				pItem = "B:设置IO端口的硬件为漏极开路输出";
				LCDB_DispFWord(nX+16*5, 56,pItem);
				pItem = "C:更改IO端口的操作方向";
				LCDB_DispFWord(nX+16*6, 56,pItem);
				pItem = "D:确认";
				LCDB_DispFWord(nX+16*7, 56,pItem);
				pItem = "E:帮助";
				LCDB_DispFWord(nX+16*8, 56,pItem);
				pItem = "F:返回";
				LCDB_DispFWord(nX+16*9, 56,pItem);	
				break;
			case 0x0F:
				return;
			}
		}
		if(flag_)
		{
			if(g_nTimer4s<50) continue;
			g_nTimer4s = 0;
			for(i=1;i<=8;i++)
			{
				nX = ORIGIN_X+16*i;
				ucAttri = (nSet>>(i-1)) & 0x01;
				if(ucAttri)
				{
					IOx_PutVal(i,ucSetVal);
					pDraw = "推挽";
					LCDB_DispFWord(nX, ORIGIN_0Y+8*5,pDraw);
					pDraw = "输出";
					LCDB_DispFWord(nX, ORIGIN_0Y+8*10,pDraw);
					if(ucSetVal)
						pDraw = "1";
					else
						pDraw = "0";
					LCDB_DispFWord(nX, ORIGIN_0Y+8*16,pDraw);
				}
				else
				{
					if(ucDir)
					{
						IOx_PutVal(i,ucSetVal);
						pDraw = "漏极";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*5,pDraw);
						pDraw = "输出";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*10,pDraw);
						if(ucSetVal)
							pDraw = "1";
						else
							pDraw = "0";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*16,pDraw);
					}
					else
					{
						val=IOx_GetVal(i);
						pDraw = "漏极";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*5,pDraw);
						pDraw = "输入";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*10,pDraw);
						if(val)
							pDraw = "1";
						else
							pDraw = "0";
						LCDB_DispFWord(nX, ORIGIN_0Y+8*16,pDraw);
					}
				}
			}
			for(i=9;i<=16;i++)
			{
				nX = ORIGIN_X+16*(i-8);
				ucAttri = (nSet>>(i-1)) & 0x01;
				if(ucAttri)
				{
					IOx_PutVal(i,ucSetVal);
					pDraw = "推挽";
					LCDB_DispFWord(nX, ORIGIN_1Y+8*5,pDraw);
					pDraw = "输出";
					LCDB_DispFWord(nX, ORIGIN_1Y+8*10,pDraw);
					if(ucSetVal)
						pDraw = "1";
					else
						pDraw = "0";
					LCDB_DispFWord(nX, ORIGIN_1Y+8*16,pDraw);
				}
				else
				{
					if(ucDir)
					{
						IOx_PutVal(i,ucSetVal);
						pDraw = "漏极";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*5,pDraw);
						pDraw = "输出";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*10,pDraw);
						if(ucSetVal)
							pDraw = "1";
						else
							pDraw = "0";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*16,pDraw);
					}
					else
					{
						val=IOx_GetVal(i);
						pDraw = "漏极";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*5,pDraw);
						pDraw = "输入";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*10,pDraw);
						if(val)
							pDraw = "1";
						else
							pDraw = "0";
						LCDB_DispFWord(nX, ORIGIN_1Y+8*16,pDraw);
					}
				}
			}
		}
	}
	
}

/***********************************************************************************/
// 文件结束
/***********************************************************************************/

⌨️ 快捷键说明

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