#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);
}
考点串写(五) 第十四届第二套模拟题
最新推荐文章于 2024-07-24 22:47:03 发布