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

📄 tree.c

📁 单片机系统上电后
💻 C
字号:

#include "KeilcBasicFun.h"	//
#include <stdio.h>

#define DEBUG 1 
//---------------------------------------------------
//全局变量及位标志定义
extern bit FINT0;	  //外部中断0标志//本程序仅使用此中断
extern bit FINT1;	  //外部中断1标志
extern bit FT0;	  //定时器0中断标志
extern bit FT1;	  //定时器1中断标志
extern bit FT2;	  //定时器2中断标志	

void printWrongNum(void);//打印函数,当输入密码错误时,打印此函数
void printError(void);//打印函数,同时按两次键时或无按时,打印此函数
void printTree (void);//密码成功,打印数

uchar data 	p1Interface _at_ 0x0028;//当中断时,读取存放P1口的数据
uchar data  p0Interface _at_ 0x0029;//当中断时,读取存放P0口的数据
uint data inputData	_at_ 0x28;//为对P0、P1口同时操作,将两个数据按无符号Int读出,统一操作。
void main (void){

	uint countNum = 0;//计数,记录输入正确密码的个数。
	ruptInit ();	    //中断函数初始化
	serialInit ();	  //串行口初始化
	INT0 = 1;		      //清外部中断p3.2口
	P0 = 0x00; 				//清P0口
	P1 = 0x00;
	
	while (1){
	if(FINT0){
		INT0 = 1;     //软件仿真时,清中断信号
		FINT0 = 0;    //清中断标志位

	 	p1Interface = P1;
		p0Interface = P0;
		
		switch (inputData)//密码对应的数值为256 、64 、4 、16 、1 、512,时正确。
		{
			case 1 : if (countNum == 4) //countNum为4表明输入正确密码个数为4,第五个为1则此时正确,正确密码个数再加1
						{
						 	countNum++;
//							p1Interface = 0x00;
//							p0Interface = 0x00;
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif
						}
						else countNum = 0;//如果不为4,说明此密码已不正确,则正确个数变为0;
						break;
			case 2 : printWrongNum(); //错误密码,提示出错。并把countNum归0
					 countNum = 0; 
					 break;
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif
			case 4 : if (countNum == 2) 
					 	countNum++; 
					 else countNum = 0;	
						
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif
					 break;
			case 8 : printWrongNum();
					 countNum = 0; break;
			case 16 : if (countNum == 3) 
					  	countNum++; 
					  else countNum = 0;
					  	#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif
					  break;
			case 32 : printWrongNum();
					  countNum = 0;
					  break;
			case 64 : if (countNum == 1) 
					  	countNum++ ; 
					  else countNum = 0;
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif					   
					  break;
			case 128 : printWrongNum(); 
					   countNum = 0;
					   break;
			case 256 : countNum = 1; 
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif
						break;
			case 512 : if (countNum == 5) 
									{
										countNum = 0;
										printTree ();
									}
							#if DEBUG
							printf("case %d countNumber=%d\n", inputData, countNum);
							#endif						 
						break;
		  case 1024 : printWrongNum(); countNum = 0; break;
			case 2048 : printWrongNum(); countNum = 0; break;
			case 4096 : printWrongNum(); countNum = 0; break;
			case 8192 : printWrongNum(); countNum = 0; break;
			case 16284 : printWrongNum(); countNum = 0; break;
			case 32768 : printWrongNum(); countNum = 0; break;
			default : {	printError();
							countNum = 0;
							#if DEBUG
							printf("default %d countNumber=%d\n", inputData, countNum);
							#endif
					  	p1Interface = 0x00;
					  	p0Interface = 0x00;
					  }
		}
	}
	}

}

void printWrongNum(void)
{
	 printf("the number is not correct!\n");
}
void printError(void)
{
	 printf("There are more than one number that are inputed, or there is not number !\n");
}
void printTree (void)
{
	  	 	printf("######/\\########\n");
			printf("#####/\\/\\#######\n");
			printf("###o.o..o.o#####\n");
			printf("###/@/\\/\\@\\#####\n");
			printf("##/~~~~~~~~\\####\n");
			printf("##//()\\/()\\\\####\n");
			printf("##/~~~~~~~~~\\#	\n");
			printf("#O,O,O,O,O,O,O##\n");
			printf("/~\\~/~\\~/~\\~/~\\#\n");
			printf("##//VVVVVVVV\\\\##\n");
			printf("#/VVVVVVVVVVVV\#\n");
			printf("////////\\\\\\\\\\\\\\\\\*\n");
			printf("######!!!!######\n");
			printf("######!!!!######\n");
			printf("######!!!!######\n");
			printf("######!!!!######\n");
}

⌨️ 快捷键说明

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