考点串写(四) 第十四届第一套模拟题

#include "init.h"
#include "led.h"
#include "timer.h"
#include "seg.h"
#include "key.h"
#include "Ultrasonic.h"
#include "uart.h"
#include "stdio.h"

unsigned char Uart_Buf[16];
unsigned char Uart_Buf_Index;
unsigned char ucLed[8]={0,0,0,0,0,0,0,0};
unsigned char seg_buf[8],seg_string[10];
unsigned char pos=0;
unsigned int Seg_Slow;
unsigned char Key_Slow;
unsigned char Key_Val,Key_Down,Key_Up,Key_Old;
unsigned char t_ms;

void Led_Proc();
void Seg_Proc();
void Key_Proc();

bit Led_flag;
bit Seg_Disp_Mode;

unsigned char ucDist;
unsigned char Dist_param=30;
unsigned char Dist_param_control=30;

void main(void)
{
	All_Init();
	Timer0Init();
	Timer1Init();
	UartInit();
	
	while(1)
	{
		Led_Proc();
		Key_Proc();
		Seg_Proc();
	}
}


void tm0_isr() interrupt 1 
{
	if(++Key_Slow==10) Key_Slow=0;
	if(++Seg_Slow==200) Seg_Slow=0;
	
	if(++pos==8) pos=0;
	Seg_Disp(seg_buf,pos);
	Led_Disp(pos,ucLed[pos]);
	
	if(++t_ms==200)
	{
		t_ms=0;
		Led_flag^=1;
	}
}

void Uart() interrupt 4
{
	if(RI)
	{
		Uart_Buf[Uart_Buf_Index++] = SBUF;
		RI=0;
	}
}

void Key_Proc(void)
{
	if(Key_Slow) return;
	Key_Slow=1;
	
	Key_Val = Read_Key();
	Key_Down = Key_Val & (Key_Val ^ Key_Old);
	Key_Up = ~Key_Val & (Key_Val ^ Key_Old);
	Key_Old =Key_Val;
	
	switch(Key_Down)
	{
		case 4: 
			Seg_Disp_Mode^=1;
			if(Seg_Disp_Mode==0)Dist_param_control=Dist_param;
		break;
		
		case 8:
			if(!Seg_Disp_Mode)
			{
				Dist_param = ucDist;
			}
		break;
			
		case 12:
			if(Seg_Disp_Mode)
			{
				if(Dist_param<=244)Dist_param+=10;
			  else Dist_param=254;
			}
		break;
		
		case 16:
			if(Seg_Disp_Mode)
			{
				if(Dist_param>=10) Dist_param-=10;
				else  Dist_param=0;
			}
		break;
			
		case 9:
			sprintf(Uart_Buf,"Distance:%3dcm\r\n",(unsigned int)ucDist);
			Uart_Send_String(Uart_Buf);
		
		break;
			
	}
}

void Seg_Proc(void)
{
	if(Seg_Slow) return;
	Seg_Slow=1;
	
	
	ucDist=Rec_Wave();
	
	if(!Seg_Disp_Mode)
	{
		sprintf(seg_string,"U1   %3d",(unsigned int)ucDist);
	}
	else
	{
		sprintf(seg_string,"U2   %3d",(unsigned int)Dist_param);
	}
	
	Seg_Trans(seg_buf,seg_string);
}

void Led_Proc(void)
{
	ucLed[0] = ~Seg_Disp_Mode;
	ucLed[1] = Seg_Disp_Mode;
	
	if(ucDist>Dist_param_control)
	{
		ucLed[2] = Led_flag; 
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值