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

#include "init.h"
#include "timer.h"
#include "led.h"
#include "seg.h"
#include "key.h"
#include "iic.h"
#include "onewire.h"
#include "Uart.h"
#include "stdio.h"

unsigned char ucLed[8]={0,0,0,0,0,0,0,0};
unsigned char pos;
unsigned char seg_buf[8];
unsigned char seg_string[10];
unsigned char Seg_Slow,Key_Slow;
unsigned char Key_Val,Key_Down,Key_Up,Key_Old;
unsigned char Uart_Recv[3];
unsigned char Uart_Recv_Index;
unsigned char Uart_Send[16];

bit Seg_Disp_Mode;
bit Led_flag;
bit lock_flag;//锁定是1,解锁0

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

float temperature;
float ad;  
unsigned char t_ms;

void main(void)
{
	All_Init();
	rd_temperature();
	Delay750ms();
	Timer0_Init();
	UartInit();	
	while(1)
	{
		Led_Proc();
		Key_Proc();
		Seg_Proc();
		Uart_Proc();
	}
}

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

void Uart() interrupt 4  //按波特率获取
{
	if(RI)
	{
		Uart_Recv[Uart_Recv_Index]=SBUF;
		Uart_Recv_Index++;
		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:
			lock_flag=1;
		break;
		
		case 5:
			if(lock_flag==1)lock_flag=0;
		break;
		
		case 12:
			if(Seg_Disp_Mode==0)
			{
				sprintf(Uart_Send,"TEMP:%.1f℃\r\n",temperature);
			}
			else
			{				
				sprintf(Uart_Send,"ad:%.2fV\r\n",ad);
			}
			Uart_Send_String(Uart_Send);
			break;
	}
}

void Seg_Proc(void)
{
	if(Seg_Slow) return;
	Seg_Slow=1;
	
	temperature = rd_temperature()/16.0;
	ad = PCF8591_ADC(0x43)/51.0;
	
	if(Seg_Disp_Mode==0)
	{
		sprintf(seg_string,"U1   %3.1f",temperature);
	}
	else
	{
		sprintf(seg_string,"U2   %3.2f",ad);
	}

	
	Seg_Trans(seg_buf,seg_string);
	
}

void Uart_Proc(void)
{
	if(Uart_Recv_Index)
	{
		if(lock_flag==0)
		{
			if(Uart_Recv[0]=='A') Seg_Disp_Mode=0;
			if(Uart_Recv[0]=='B') Seg_Disp_Mode=1;
		}
		Uart_Recv_Index=0;
	}
}

void Led_Proc(void)
{
	ucLed[0]= ~Seg_Disp_Mode;
	ucLed[1]= Seg_Disp_Mode;
	ucLed[2] = Led_flag?lock_flag:0;
	
	if((unsigned char)temperature>=28) Relay_Disp(1);
	else Relay_Disp(0);
	
	if(ad>3.6) Buzz_Disp(1);
	else Buzz_Disp(0);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值