各位前辈好!(新人向大家问好)我现在手上有一个板子,有个OLED,用51单片机控制,用DS18B20测温的。要求上电屏幕显示85度。电流显示0.84A。。。几秒延时过后,应该测得实际温度,电流在‘DS18B20设置的最低温度’以下时显示电流是0.00A。
但是我的在‘DS18B20设置的最低温度’以下时显示电流不是0.00A,我只要一按设置键,进入设置界面退出来后显示就是0.00A。程序不知道哪里有点小问题。哪位大神指点指点啊。程序付上:
/**********************程序如下*************************/
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include
#include
#include "intrins.h"
#include
#define uchar unsigned char
#define uint unsigned int
//ISP/IAP 特殊功能寄存器
sfr IAP_DATA = 0xC2;
sfr IAP_ADDRH = 0xC3;
sfr IAP_ADDRL = 0xC4;
sfr IAP_CMD = 0xC5;
sfr IAP_TRIG = 0xC6;
sfr IAP_CONTR = 0xC7;
//定义Flash 操作等待时间及允许IAP/ISP/EEPROM 操作的常数
//#define ENABLE_ISP 0x80 //系统工作时钟<30MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x81 //系统工作时钟<24MHz 时,对IAP_CONTR 寄存器设置此值
#define ENABLE_ISP 0x82 //系统工作时钟<20MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x83 //系统工作时钟<12MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x84 //系统工作时钟<6MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x85 //系统工作时钟<3MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x86 //系统工作时钟<2MHz 时,对IAP_CONTR 寄存器设置此值
//#define ENABLE_ISP 0x87 //系统工作时钟<1MHz 时,对IAP_CONTR 寄存器设置此值
//#define DEBUG_DATA 0x5A //本测试程序最终存储在 EEPROM 单元的数值
#define DATA_FLASH_START_ADDRESS 0x00 //STC5Axx 系列 EEPROM 测试起始地址
union union_temp16
{
unsigned int un_temp16;
unsigned char un_temp8[2];
}my_unTemp16; // BS1=1; BS2=1
// OLED
sbit RES=P0^3; //使能端
sbit CS=P0^4; //
sbit DC=P0^5;
sbit SCLK=P0^ 7;
sbit SDIN=P0^6; // "℃"
sbit DQ=P3^2; //温度输入口
// 继电器
sbit EN=P2^3; // 低电平有效,大的LT1374使能端
sbit M1=P2^4; // 最大档控制继电器 J11
sbit M2=P2^5; // 第二档控制继电器 J12
sbit M3=P2^6; // 第三档控制继电器 J13
sbit M4=P2^7; // 最小档控制继电器 J14
//按键
sbit key0=P3^3;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
uint count;
uint temp,add;
uint Low=10,High=35; //默认初始工作范围在20~45°之间
bit HI_Alarm=0; // 报警标志位
bit flag=0; // 工作模式选择标志位,为0时为自动工作模式,为1时为网络工作模式,
bit query_wendu=0;
bit query_dianliu=0;
bit shut=0;
char Alarm_Temp=35; // 报警温度
uchar temp11=0;
int temp10=0;
unsigned int b;
uchar data temp_data[2]={0x00,0x00};
uchar shi,ge,xiao,temp1,temp2,temp3,temp4,cankaozhi; //显示单元数据,共4个数据和一个运算暂用
uchar code df_Table[]={0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9}; //温度小数位对照表
//uchar flg1=0,flg2=0,flg3=0,flg4=0,flg5=0;
uchar rec[6]={0};
unsigned char code *a1,*a2,*a3,*a4,*b1,*b2,*aemp1,*c1,*c2,*c3,*c4,*c5;
signed char m1,m2,m3,m4,n1,n2,p1,p2,p3,p4,p5,d1,d2,t1,t2,bao1,bao2;
bit flag0=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0,flag6=0,DIS_flag;//按键标志位
unsigned char i=0;
void scan(); // 函数声明
/*****************11us延时函数*************************/
//
void _delay1(uchar z)
{
uchar x,y,c;
for(c=z;c>0;c--)
for(x=50;x>0;x--)
for(y=91;y>0;y--);
}
/*****************串口初始化*************************/
void init_serial()
{
TMOD=0x21; //定时器/计数器工作方式设置,只能是字节传送,不能位寻址;这里用到2个定时器。
//GATE C/’T M1 M0(定时器1) GATE C/’T M1 M0(定时器0)
//0 0 1 0 工作方式2 0001 工作方式1 (用于定时)
//在串行口进行串行通信时,作波特率发生器使用
TH1=0xfd; // 串口工作模式1或3的波特率=T1的溢出率*2smod/32
TL1=0xfd; // =2smod/32*fosc/(12*(256-TH1)=>TH1=256--12M/(9600*12*32/2)=253=oxfd;
TR0=1;
ET0=1; //允许定时器/计数器0中断
TH0=0xff;
TL0=0xf6;
TR1=1; // TR1,TR0分别是定时器/计数器T1,T0的运行控制位,通过软件置1后,定时器/计数器才开始工作,在系统复位时被清0;
SM0=0;
SM1=1; //串口工作方式1
REN=1; //允许串行接收
EA=1; //中断总控制位,
// ES=0; //串行口中断控制位,为1时设置;
ES=1;
EN=1;
M1=1; //用于继电器调试
M2=1 ; //一上电时,工作在最大档进行抽风,测(风温)下面的72机箱温度,否则所测的不是风温是机器的温度很低,风扇会一直不转
M3=1;
M4=1;
SBUF=0xaa;while(!TI);TI=0;
}
/****************DS18B20复位函数************************/
/***********根据DS18B20中文PDF来写初始化程序***********/
ow_reset(void)
{
char presence=1;
while(presence)
{
while(presence)
{
DQ=1;
_nop_();_nop_(); //稍作延时,要尽可能短
DQ=0; count=0; //从高拉到低
do{}while(count<23); //低电平保持550 us(总线控制器拉低总线并保持 480us以上,发出(TX)一个复位脉冲,然后释放总线,进入接受状态(RX))
DQ=1;count=0; // 释放总线,即拉高了总线
do{}while(count<3); //66 us 此处延时有足够确保能让DS18B20发出存在脉冲。
presence=DQ; //presence=0 复位成功,继续下一步 ?
}
count=0;
do{}while(count<20); //延时500 us,通过定时器0中断1来 延时 interrupt 1
presence=~DQ;
}
DQ=1; //拉高电平
}
//
/****************DS18B20写命令函数************************/
//向1-WIRE 总线上写1个字节
void write_byte(uchar val)
{
uchar i;
for(i=8;i>0;i--) //一个字节有8位,一位一位的写
{
DQ=1;_nop_();_nop_();_nop_(); //从高拉到低
DQ=0;_nop_();_nop_();_nop_();_nop_();_nop_(); //5 us
DQ=val&0x01; //最低位移出 从字节的最低位开始传输
count=0;
do{}while(count<3); //66 us 因为15us后DS18B20会对总线采样。必须让写时序持续至少60us
val=val/2; //右移1位
}
DQ=1; //写完后,必须释放总线,将数据线拉高
}
//
/****************DS18B20读1字节函数************************/
//从总线上取1个字节 读数据时,数据以字节的最低有效位先从总线移出
uchar read_byte(void)
{
uchar i;
uchar value=0;
for(i=8;i>0;i--)
{
DQ=1;_nop_();_nop_();
value>>=1;
DQ=0;_nop_();_nop_();_nop_();_nop_(); //4 us
DQ=1;_nop_();_nop_();_nop_();_nop_(); ;_nop_(); //4 us
if(DQ) //控制器进行采样
{value|=0x80;} // 若总线为1,即DQ为1,那就把dat的最高位置1;若为0,则不进行处理,保持为0
count=0;
do{}while(count<3); //66 us
}
DQ=1;
return(value);
}
//
/****************读出温度函数************************/
//
void read_temp()
{
ow_reset();
do{}while(count<93); //_delay1(20);
write_byte(0xcc); //发命令:跳过读ROM指令
write_byte(0x44); //发温度转换命令
ow_reset(); //18B20总线复位
_delay1(1);
write_byte(0xcc); //发命令
write_byte(0xbe); //读暂存器和CRC字节
temp_data[0]=read_byte(); //读温度值的低字节
temp_data[1]=read_byte(); //读温度值的高字节
temp=temp_data[1]; //先把高八位有效数据赋于temp
temp<<=8; // 把以上8位数据从temp低八位移到高八位
temp=temp|temp_data[0]; // 两字节合成一个整型变量。
// SBUF=temp;
// return temp; //返回温度值
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Delay Time
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void uDelay(unsigned char l)
{
while(l--);
}
void Delay(unsigned char n)
{
unsigned char i,j,k;
for(k=0;k
{
for(i=0;i<131;i++)
{
for(j=0;j<15;j++)
{
uDelay(203);
}
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Write_Command
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Write_Command(unsigned char Data) //屏写命令
{
unsigned char i;
CS=0;
DC=0; // data\command#=00 数据/命令 控制字节 发命令
for (i=0; i<8; i++) // 先写入高位bit
{
SCLK=0;
SDIN=(Data&0x80)>>7; //第一次写入最高位,D7 送入SDIN
Data = Data << 1; // 左移一位
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1; //关断"写命令"
CS=1;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Write_Data
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Write_Data(unsigned char Data) //屏写数据
{
unsigned char i;
CS=0;
DC=1; // data\command#=01 数据/命令 控制字节 写数据
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Instruction Setting
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Start_Column(unsigned char d) //列开始位置设置 :0x"xy"
{
Write_Command(0x00+d%16); // Set Lower Column Start Address for Page Addressing Mode = "y "
// Default => 0x00
Write_Command(0x10+d/16); // Set Higher Column Start Address for Page Addressing Mode ="x"
// Default => 0x10
}
void Set_Addressing_Mode(unsigned char d) //地址寻址模式选择
{
Write_Command(0x20); // Set Memory Addressing Mode
Write_Command(d); // Default => 0x02
// 0x00 => Horizontal Addressing Mode
// 0x01 => Vertical Addressing Mode 三种方式
// 0x02 => Page Addressing Mode
}
void Set_Column_Address(unsigned char a, unsigned char b)
{
Write_Command(0x21); // Set Column Address
Write_Command(a); // Default => 0x00 (Column Start Address)
Write_Command(b); // Default => 0x83 (Column End Address)
}
void Set_Page_Address(unsigned char a, unsigned char b)
{
Write_Command(0x22); // Set Page Address
Write_Command(a); // Default => 0x00 (Page Start Address)
Write_Command(b); // Default => 0x07 (Page End Address)
}
void Set_Start_Line(unsigned char d)
{
Write_Command(0x40|d); // Set Display Start Line
// Default => 0x40 (0x00)
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Set_Area_Brightness
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Contrast_Control(unsigned char d)
{
Write_Command(0x81); // Set Contrast Control for Bank 0
Write_Command(d); // Default => 0x80
}
void Set_Area_Brightness(unsigned char d)
{
Write_Command(0x82); // Set Brightness for Area Color Banks
Write_Command(d); // Default => 0x80
}
void Set_Segment_Remap(unsigned char d)
{
Write_Command(0xA0|d); // Set Segment Re-Map
// Default => 0xA0
// 0xA0 (0x00) => Column Address 0 Mapped to SEG0
// 0xA1 (0x01) => Column Address 0 Mapped to SEG131
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// xianshi
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Entire_Display(unsigned char d)
{
Write_Command(0xA4|d); // Set Entire Display On / Off
// Default => 0xA4
// 0xA4 (0x00) => Normal Display
// 0xA5 (0x01) => Entire Display On
}
void Set_Inverse_Display(unsigned char d)
{
Write_Command(0xA6|d); // Set Inverse Display On/Off
// Default => 0xA6
// 0xA6 (0x00) => Normal Display
// 0xA7 (0x01) => Inverse Display On
}
void Set_Multiplex_Ratio(unsigned char d)
{
Write_Command(0xA8); // Set Multiplex Ratio
Write_Command(d); // Default => 0x3F (1/64 Duty)
}
void Set_Dim_Mode(unsigned char a, unsigned char b)
{
Write_Command(0xAB); // Set Dim Mode Configuration
Write_Command(0X00); // => (Dummy Write for First Parameter)
Write_Command(a); // Default => 0x80 (Contrast Control for Bank 0)
Write_Command(b); // Default => 0x80 (Brightness for Area Color Banks)
Write_Command(0xAC); // Set Display On in Dim Mode
}
void Set_Master_Config(unsigned char d)
{
Write_Command(0xAD); // Set Master Configuration
Write_Command(0x8E|d); // Default => 0x8E
// 0x8E (0x00) => Select External VCC Supply
// 0x8F (0x01) => Select Internal DC/DC Voltage Converter
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Set_Area_Brightness
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Display_On_Off(unsigned char d)
{
Write_Command(0xAE|d); // Set Display On/Off
// Default => 0xAE
// 0xAE (0x00) => Display Off
// 0xAF (0x01) => Display On
}
void Set_Start_Page(unsigned char d)
{
Write_Command(0xB0|d); // Set Page Start Address for Page Addressing Mode
// Default => 0xB0 (0x00)
}
void Set_Common_Remap(unsigned char d)
{
Write_Command(0xC0|d); // Set COM Output Scan Direction
// Default => 0xC0
// 0xC0 (0x00) => Scan from COM0 to 63
// 0xC8 (0x08) => Scan from COM63 to 0
}
void Set_Display_Offset(unsigned char d)
{
Write_Command(0xD3); // Set Display Offset
Write_Command(d); // Default => 0x00
}
void Set_Display_Clock(unsigned char d)
{
Write_Command(0xD5); // Set Display Clock Divide Ratio / Oscillator Frequency
Write_Command(d); // Default => 0x70
// D[3:0] => Display Clock Divider
// D[7:4] => Oscillator Frequency
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Precharge_Period(unsigned char d)
{
Write_Command(0xD9); // Set Pre-Charge Period
Write_Command(d); // Default => 0x22 (2 Display Clocks [Phase 2] / 2 Display Clocks [Phase 1])
// D[3:0] => Phase 1 Period in 1~15 Display Clocks
// D[7:4] => Phase 2 Period in 1~15 Display Clocks
}
void Set_Common_Config(unsigned char d)
{
Write_Command(0xDA); // Set COM Pins Hardware Configuration
Write_Command(0x02|d); // Default => 0x12 (0x10)
// Alternative COM Pin Configuration
// Disable COM Left/Right Re-Map
}
void Set_VCOMH(unsigned char d)
{
Write_Command(0xDB); // Set VCOMH Deselect Level
Write_Command(d); // Default => 0x34 (0.77*VCC)
}
void Set_Read_Modify_Write(unsigned char d)
{
Write_Command(0xE0|d); // Set Read Modify Write Mode
// Default => 0xE0
// 0xE0 (0x00) => Enter Read Modify Write
// 0xEE (0x0E) => Exit Read Modify Write
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Global Variables
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#define XLevelL 0x04
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 32
#define Brightness 0xcF
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Patterns
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
unsigned char code wendu_set[]= {
0x00,0x20,0x44,0x08,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xFC,0x08,0x00,0x00,0x00,0x00,
0xF8,0x08,0x28,0x28,0xF8,0xAC,0xA8,0xF8,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x3E,0x21,0x3E,0x22,0x3E,0x22,
0x22,0x3E,0x22,0x3E,0x20,0x00,0x00,0x30,0x0F,0x20,0x20,0x22,0x16,0x0A,0x0A,0x16,
0x22,0x20,0x20,0x00,0x00,0x00,0x1B,0x1B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // “温度”代码
unsigned char code dianliu_set[]={
0x00,0xE0,0x20,0x20,0x20,0xF8,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x40,0x88,
0x10,0x00,0x90,0xD0,0xB0,0x98,0x90,0xD0,0x90,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x09,0x09,0x09,0x3F,0x49,0x49,
0x49,0x4F,0x40,0x70,0x00,0x00,0x08,0x7C,0x42,0x20,0x10,0x0E,0x00,0x7E,0x00,0x3E,
0x41,0x78,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //“电流” 代码
unsigned char code fuhao_set[][32]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
// (.)! - 0x0021 Exclamation Mark
{0x00,0x70,0x50,0x70,0xC0,0x20,0x10,0x10,0x10,0x20,0x70,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0x08,0x10,0x10,0x10,0x10,0x0C,0x00,0x00,0x00,0x00,0x00},
// (℃)! - 0x0021 Exclamation Mark
{0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x38,0x26,0x05,0x04,0x05,0x26,0x38,0x20,0x00,0x00,0x00,0x00},
// (A)! - 0x0021 Exclamation Mark
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
// ( )! - 0x0021 Exclamation Mark 空格
};
unsigned char code dian_set[]= {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x38,0x00,0x00,0x00};
unsigned char code Ascii[][32]={
{0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00},
// (0)! - 0x0021 Exclamation Mark
{0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x00,0x00},
// (1) ! - 0x0021 Exclamation Mark
{0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x00,0x00,0x00},
// (2) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00},
// (3) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00},
// (4) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00},
// (5) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00},
// (6) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
// (7) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00},
// (8) " - 0x0022 Quotation Mark
{0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,0x00,0x00,0x00,0x00},
// (9) " - 0x0022 Quotation Mark
};
unsigned char code one[]=
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
unsigned char code two[]=
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};
unsigned char code three[]=
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};
unsigned char code four[]=
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};
unsigned char code five[]=
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};
unsigned char code six[]=
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};
unsigned char code seven[]=
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};
unsigned char code eight[]=
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};
unsigned char code nine[]=
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};
unsigned char code zero[]=
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};
unsigned char code one_box[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1F,0x10,0x00,0x00,0x00,0x00,0x00};
unsigned char code two_box[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x10,0x10,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x14,0x12,0x11,0x10,0x00,0x00,0x00,0x00,0x00};
unsigned char code three_box[]=
{0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x21,0x21,0x1E,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code baojing[]=
{0x00,0x00,0x40,0x44,0xD8,0x00,0x40,0xA0,0x9C,0x84,0x84,0xBC,0xA0,0x20,0x00,0x40,
0x5C,0x54,0x54,0x5C,0xF4,0x54,0x5C,0x54,0x54,0x5C,0x40,0x00,0x20,0x20,0xFC,0x20,
0x20,0xFC,0x84,0x84,0xA4,0xA4,0x9C,0x00,0x00,0x28,0xF8,0xAC,0xE8,0x8C,0x78,0x08,
0xB0,0x4C,0x68,0x98,0x88,0x00,0x20,0x44,0x08,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xFC,
0x08,0x00,0x00,0x00,0xF8,0x08,0x28,0x28,0xF8,0xAC,0xA8,0xF8,0x28,0x28,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0x08,0x24,0x11,0x0A,0x04,0x0A,0x11,0x20,0x20,0x00,0x20,
0x20,0x20,0x3F,0x29,0x2B,0x2D,0x29,0x3F,0x20,0x20,0x20,0x00,0x02,0x22,0x3F,0x01,
0x00,0x3F,0x10,0x0B,0x04,0x0A,0x11,0x20,0x00,0x02,0x02,0x3A,0x2A,0x2A,0x2A,0x2B,
0x2A,0x2A,0x3A,0x02,0x02,0x00,0x04,0x3E,0x21,0x3E,0x22,0x3E,0x22,0x22,0x3E,0x22,
0x3E,0x20,0x00,0x30,0x0F,0x20,0x20,0x22,0x16,0x0A,0x0A,0x16,0x22,0x20,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code sdata[]=
{0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0xC0,0xE0,0x60,0x20,0x20,0x60,0xE0,0xE0,0xC0,0x80,0x00,0x00,0x80,0xC0,
0xE0,0x60,0x20,0x20,0x60,0xE0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0x07,0x07,0x06,0x80,0xC0,0xE0,0x78,0x3F,0x1F,0x07,0x00,0x00,0x03,0x03,
0x03,0x12,0x10,0x10,0x38,0x7F,0xEF,0xE7,0x80,0x00,0x80,0xC0,0xF0,0x38,0x1E,0x07,
0x03,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x00,0x00,
0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x30,0x38,0x3E,0x3E,0x00,0x00,0x0E,0x1E,
0x3E,0x34,0x20,0x20,0x30,0x38,0x1F,0x1F,0x0F,0x00,0x01,0x01,0x01,0x01,0x21,0x21,
0x21,0x3F,0x3F,0x3F,0x21,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code wendu2_set[]=
{0x00,0x00,0x40,0x44,0xD8,0x00,0x40,0xA0,0x9C,0x84,0x84,0xBC,0xA0,0x20,0x00,0x40,
0x5C,0x54,0x54,0x5C,0xF4,0x54,0x5C,0x54,0x54,0x5C,0x40,0x00,0x00,0x08,0x08,0x08,
0x08,0xF8,0x08,0x08,0x08,0x0C,0x08,0x00,0x00,0x80,0x40,0xF0,0x0C,0x40,0x20,0x1C,
0xF0,0x90,0x90,0x90,0x10,0x00,0x08,0x08,0x08,0xE8,0xA8,0xAC,0xA8,0xA8,0xE8,0x08,
0x08,0x08,0x00,0x20,0x44,0x08,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xFC,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0x08,0x24,0x11,0x0A,0x04,0x0A,0x11,0x20,0x20,0x00,0x20,
0x20,0x20,0x3F,0x29,0x2B,0x2D,0x29,0x3F,0x20,0x20,0x20,0x00,0x10,0x10,0x10,0x10,
0x10,0x1F,0x10,0x10,0x10,0x10,0x18,0x10,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
0x3F,0x04,0x04,0x04,0x04,0x00,0x00,0x3F,0x01,0x01,0x1D,0x15,0x15,0x1D,0x01,0x21,
0x3F,0x00,0x00,0x04,0x3E,0x21,0x3E,0x22,0x3E,0x22,0x22,0x3E,0x22,0x3E,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code du[]=
{0x00,0x00,0x38,0x28,0x38,0xC0,0x20,0x10,0x10,0x10,0x10,0x10,0x20,0xF0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x08,0x00,0x00};
unsigned char code ESC[]=
{0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x00,0x70,0x88,
0x08,0x08,0x08,0x38,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,0x00,0x38,0x20,
0x21,0x21,0x22,0x1C,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00,0x00};
unsigned char code wait[]=
{0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,
0xC0,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,
0xC0,0x80,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0xF1,0xF3,0xF3,0x20,0x22,0xAA,0xAA,
0xAA,0x2A,0x3F,0x3F,0x2A,0xAA,0xAF,0xAF,0x3B,0x73,0x60,0x00,0x10,0x11,0x11,0xD1,
0xFF,0xFF,0xFF,0xD8,0x98,0x19,0xFF,0xF7,0x96,0x9F,0x9F,0x9F,0x9F,0xFF,0xF9,0x11,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x23,0x23,0x21,0x21,0x21,0x21,0x21,0x21,
0x20,0x20,0x30,0x39,0x39,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x7F,
0x38,0x0C,0xFF,0xFF,0xFF,0x15,0x15,0x95,0x95,0x95,0xFF,0xFF,0x01,0x00,0x00,0x00,
0x10,0x1C,0x0F,0x07,0xFF,0xFF,0xFF,0x01,0x01,0x00,0xFF,0xFF,0x08,0x08,0x88,0x88,
0x88,0xFF,0xFF,0x00,0x00,0x00,0x00,0x80,0xE0,0x7F,0x3F,0x0F,0x00,0xFF,0xFF,0x41,
0x41,0x41,0x41,0x41,0x41,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x60,
0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,
0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,
0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char code wendu1_set[]= {
0x00,0x00,0x40,0x44,0xD8,0x00,0x40,0xA0,0x9C,0x84,0x84,0xBC,0xA0,0x20,0x00,0x40,
0x5C,0x54,0x54,0x5C,0xF4,0x54,0x5C,0x54,0x54,0x5C,0x40,0x00,0x00,0x08,0x08,0x08,
0x08,0xF8,0x08,0x08,0x08,0x0C,0x08,0x00,0x00,0x80,0x40,0xF0,0x0C,0x40,0x20,0x1C,
0xF0,0x90,0x90,0x90,0x10,0x00,0x80,0x40,0xF0,0x0C,0xF0,0x90,0x90,0xF0,0x88,0x8C,
0x88,0x80,0x00,0x20,0x44,0x08,0x00,0xF8,0xA8,0xA8,0xA8,0xA8,0xFC,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0x08,0x24,0x11,0x0A,0x04,0x0A,0x11,0x20,0x20,0x00,0x20,
0x20,0x20,0x3F,0x29,0x2B,0x2D,0x29,0x3F,0x20,0x20,0x20,0x00,0x10,0x10,0x10,0x10,
0x10,0x1F,0x10,0x10,0x10,0x10,0x18,0x10,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
0x3F,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x3F,0x00,0x1F,0x10,0x08,0x10,0x07,0x08,
0x10,0x38,0x00,0x02,0x3E,0x21,0x3E,0x22,0x3E,0x22,0x22,0x3E,0x22,0x3E,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Regular Pattern (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fill_RAM(unsigned char Data)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
Set_Start_Page(i);
Set_Start_Column(0x00);
for(j=0;j<132;j++) //列数从4开始,4~132,正好128列
{
Write_Data(Data);
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Regular Pattern (Partial or Full Screen)
//
// a: Start Page
// b: End Page
// c: Start Column
// d: Total Columns
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fill_Block(unsigned char Data, unsigned char a, unsigned char b, unsigned char c, unsigned char d)
{
unsigned char i,j;
for(i=a;i<(b+1);i++)
{
Set_Start_Page(i);
Set_Start_Column(c);
for(j=0;j
{
Write_Data(Data);
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// SShow_Pattern 显示汉字与数字
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Show_Pattern(unsigned char *Data_Pointer, unsigned char a, unsigned char b, unsigned char c, unsigned char d,unsigned char np)
{
unsigned char *Src_Pointer;
unsigned char i,j;
Src_Pointer=Data_Pointer; // Show_Pattern(&UniV,0x00,0x03,XLevel+0x28,0x30);
for(i=a;i<(b+1);i++)
{
Set_Start_Page(i);
Set_Start_Column(c);
for(j=0;j
{ if(np==0)
{
Write_Data(*Src_Pointer); //显示数字 ,比如是黑字黄底
}
Src_Pointer++;
if(np==1)
{
Write_Data(~*Src_Pointer); // 光标移走后,数字为黄字黑底,即取反
}
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Fade In (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fade_In()
{
unsigned int i;
Set_Display_On_Off(0x01);
for(i=0;i<(Brightness+1);i++)
{
Set_Contrast_Control(i);
uDelay(200);
uDelay(200);
uDelay(200);
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Fade Out (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Fade_Out()
{
unsigned int i;
for(i=(Brightness+1);i>0;i--)
{
Set_Contrast_Control(i-1);
uDelay(200);
uDelay(200);
uDelay(200);
}
Set_Display_On_Off(0x00); // 关闭屏显示
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Initialization
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void OLED_Init()
{
unsigned char i;
RES=0;
for(i=0;i<200;i++)
{
uDelay(200);
}
RES=1;
Set_Display_On_Off(0x00); // Display Off (0x00/0x01)
Set_Display_Clock(0xA0); // Set Clock as 160 Frames/Sec
Set_Multiplex_Ratio(0x1F); // 1/32 Duty (0x0F~0x3F)
Set_Display_Offset(0x00); // Shift Mapping RAM Counter (0x00~0x3F)
Set_Start_Line(0x00); // Set Mapping RAM Display Start Line (0x00~0x3F)
Set_Master_Config(0x00); // Disable Embedded DC/DC Converter (0x00/0x01)
Set_Addressing_Mode(0x02); // Set Page Addressing Mode (0x00/0x01/0x02)
Set_Segment_Remap(0x01); // Set SEG/Column Mapping (0x00/0x01)
Set_Common_Remap(0x08); // Set COM/Row Scan Direction (0x00/0x08)
Set_Common_Config(0x10); // Set Alternative Configuration (0x00/0x10)
Set_Contrast_Control(Brightness); // Set SEG Output Current
Set_Area_Brightness(Brightness); // Set Brightness for Area Color Banks
Set_Precharge_Period(0xD2); // Set Pre-Charge as 13 Clocks & Discharge as 2 Clock
Set_VCOMH(0x08); // Set VCOM Deselect Level
Set_Entire_Display(0x00); // Disable Entire Display On (0x00/0x01)
Set_Inverse_Display(0x00); // Disable Inverse Display On (0x00/0x01)
Fill_RAM(0x00); // Clear Screen
Set_Display_On_Off(0x01); // Display On (0x00/0x01)
}
void IAP_Disable()
{
//关闭IAP 功能, 清相关的特殊功能寄存器,使CPU 处于安全状态,
//一次连续的IAP 操作完成之后建议关闭IAP 功能,不需要每次都关
IAP_CONTR = 0; //关闭IAP 功能
IAP_CMD = 0; //清命令寄存器,使命令寄存器无命令,此句可不用
IAP_TRIG = 0; //清命令触发寄存器,使命令触发寄存器无触发,此句可不用
IAP_ADDRH = 0;
IAP_ADDRL = 0;
}
//读一字节,调用前需打开IAP 功能,入口:DPTR = 字节地址,返回:A = 读出字节
unsigned int Byte_Read(unsigned int add)
{
IAP_DATA = 0x00;
IAP_CONTR = ENABLE_ISP; //打开IAP 功能, 设置Flash 操作等待时间
IAP_CMD = 0x01; //IAP/ISP/EEPROM 字节读命令
my_unTemp16.un_temp16 = add;
IAP_ADDRH = my_unTemp16.un_temp8[0]; //设置目标单元地址的高8 位地址
IAP_ADDRL = my_unTemp16.un_temp8[1]; //设置目标单元地址的低8 位地址
//EA = 0;
IAP_TRIG = 0x5A; //先送 5Ah,再送A5h 到ISP/IAP 触发寄存器,每次都需如此
IAP_TRIG = 0xA5; //送完A5h 后,ISP/IAP 命令立即被触发起动
_nop_();
//EA = 1;
IAP_Disable(); //关闭IAP 功能, 清相关的特殊功能寄存器,使CPU 处于安全状态,
//一次连续的IAP 操作完成之后建议关闭IAP 功能,不需要每次都关
return (IAP_DATA); //返回IAP_DATA值
}
//字节编程,调用前需打开IAP 功能,入口:DPTR = 字节地址, A= 须编程字节的数据
void Byte_Program(unsigned int add, unsigned char ch)
{
IAP_CONTR = ENABLE_ISP; //打开 IAP 功能, 设置Flash 操作等待时间
IAP_CMD = 0x02; //IAP/ISP/EEPROM 字节编程命令
my_unTemp16.un_temp16 = add;
IAP_ADDRH = my_unTemp16.un_temp8[0]; //设置目标单元地址的高8 位地址
IAP_ADDRL = my_unTemp16.un_temp8[1]; //设置目标单元地址的低8 位地址
IAP_DATA = ch; //要编程的数据先送进IAP_DATA 寄存器
//EA = 0;
IAP_TRIG = 0x5A; //先送 5Ah,再送A5h 到ISP/IAP 触发寄存器,每次都需如此
IAP_TRIG = 0xA5; //送完A5h 后,ISP/IAP 命令立即被触发起动
_nop_(); //空等待,稍作延迟
//EA = 1;
IAP_Disable(); //关闭IAP 功能, 清相关的特殊功能寄存器,使CPU 处于安全状态,
//一次连续的IAP 操作完成之后建议关闭IAP 功能,不需要每次都关
} //In Application Programming 是指在应用编程,单片机程序自己可以往程序存储器里写数据或修改程序!
//擦除扇区, 入口:DPTR = 扇区地址
void Sector_Erase(unsigned int add)
{
IAP_CONTR = ENABLE_ISP; //打开IAP 功能, 设置Flash 操作等待时间
IAP_CMD = 0x03; //IAP/ISP/EEPROM 扇区擦除命令
my_unTemp16.un_temp16 = add;
IAP_ADDRH = my_unTemp16.un_temp8[0]; //设置目标单元地址的高8位地址
IAP_ADDRL = my_unTemp16.un_temp8[1]; //设置目标单元地址的低8位地址
//EA = 0;
IAP_TRIG = 0x5A; //先送 5Ah,再送A5h 到ISP/IAP 触发寄存器,每次都需如此
IAP_TRIG = 0xA5; //送完A5h 后,ISP/IAP 命令立即被触发起动
_nop_();
//EA = 1;
IAP_Disable(); //关闭IAP 功能, 清相关的特殊功能寄存器,使CPU 处于安全状态,
//一次连续的IAP 操作完成之后建议关闭IAP 功能,不需要每次都关
}
void shift()
{
switch(m2)
{
case 0x00:a2=zero;break;
case 0x01:a2=one;break;
case 0x02:a2=two;break;
case 0x03:a2=three;break;
case 0x04:a2=four;break;
case 0x05:a2=five;break;
case 0x06:a2=six;break;
case 0x07:a2=seven;break;
case 0x08:a2=eight;break;
case 0x09:a2=nine;break;
default:break;
}
switch(m3)
{
case 0x00:a3=zero;break;
case 0x01:a3=one;break;
case 0x02:a3=two;break;
case 0x03:a3=three;break;
case 0x04:a3=four;break;
case 0x05:a3=five;break;
case 0x06:a3=six;break;
case 0x07:a3=seven;break;
case 0x08:a3=eight;break;
case 0x09:a3=nine;break;
default:break;
}
switch(n1)
{
case 0x00:b1=zero;break;
case 0x01:b1=one;break;
case 0x02:b1=two;break;
case 0x03:b1=three;break;
case 0x04:b1=four;break;
case 0x05:b1=five;break;
case 0x06:b1=six;break;
case 0x07:b1=seven;break;
case 0x08:b1=eight;break;
case 0x09:b1=nine;break;
default:break;
}
switch(n2)
{
case 0x00:b2=zero;break;
case 0x01:b2=one;break;
case 0x02:b2=two;break;
case 0x03:b2=three;break;
case 0x04:b2=four;break;
case 0x05:b2=five;break;
case 0x06:b2=six;break;
case 0x07:b2=seven;break;
case 0x08:b2=eight;break;
case 0x09:b2=nine;break;
default:break;
}
switch(p1)
{
case 0x00:c1=zero;break;
case 0x01:c1=one;break;
case 0x02:c1=two;break;
case 0x03:c1=three;break;
case 0x04:c1=four;break;
case 0x05:c1=five;break;
case 0x06:c1=six;break;
case 0x07:c1=seven;break;
case 0x08:c1=eight;break;
case 0x09:c1=nine;break;
default:break;
}
switch(p2)
{
case 0x00:c2=zero;break;
case 0x01:c2=one;break;
case 0x02:c2=two;break;
case 0x03:c2=three;break;
case 0x04:c2=four;break;
case 0x05:c2=five;break;
case 0x06:c2=six;break;
case 0x07:c2=seven;break;
case 0x08:c2=eight;break;
case 0x09:c2=nine;break;
default:break;
}
}
void m_shift()
{
Sector_Erase(0x0000);
switch(m3)
{
case 0x00:Byte_Program(0x0004,0x00);break;
case 0x01:Byte_Program(0x0004,0x01);break;
case 0x02:Byte_Program(0x0004,0x02);break;
case 0x03:Byte_Program(0x0004,0x03);break;
case 0x04:Byte_Program(0x0004,0x04);break;
case 0x05:Byte_Program(0x0004,0x05);break;
case 0x06:Byte_Program(0x0004,0x06);break;
case 0x07:Byte_Program(0x0004,0x07);break;
case 0x08:Byte_Program(0x0004,0x08);break;
case 0x09:Byte_Program(0x0004,0x09);break;
default:break;
}
switch(m2)
{
case 0x00:Byte_Program(0x0002,0x00);break;
case 0x01:Byte_Program(0x0002,0x01);break;
case 0x02:Byte_Program(0x0002,0x02);break;
case 0x03:Byte_Program(0x0002,0x03);break;
case 0x04:Byte_Program(0x0002,0x04);break;
case 0x05:Byte_Program(0x0002,0x05);break;
case 0x06:Byte_Program(0x0002,0x06);break;
case 0x07:Byte_Program(0x0002,0x07);break;
case 0x08:Byte_Program(0x0002,0x08);break;
case 0x09:Byte_Program(0x0002,0x09);break;
default:break;
}
switch(p1)
{
case 0x00:Byte_Program(0x0008,0x00);break;
case 0x01:Byte_Program(0x0008,0x01);break;
case 0x02:Byte_Program(0x0008,0x02);break;
case 0x03:Byte_Program(0x0008,0x03);break;
case 0x04:Byte_Program(0x0008,0x04);break;
case 0x05:Byte_Program(0x0008,0x05);break;
case 0x06:Byte_Program(0x0008,0x06);break;
case 0x07:Byte_Program(0x0008,0x07);break;
case 0x08:Byte_Program(0x0008,0x08);break;
case 0x09:Byte_Program(0x0008,0x09);break;
default:break;
}
switch(p2)
{
case 0x00:Byte_Program(0x000a,0x00);break;
case 0x01:Byte_Program(0x000a,0x01);break;
case 0x02:Byte_Program(0x000a,0x02);break;
case 0x03:Byte_Program(0x000a,0x03);break;
case 0x04:Byte_Program(0x000a,0x04);break;
case 0x05:Byte_Program(0x000a,0x05);break;
case 0x06:Byte_Program(0x000a,0x06);break;
case 0x07:Byte_Program(0x000a,0x07);break;
case 0x08:Byte_Program(0x000a,0x08);break;
case 0x09:Byte_Program(0x000a,0x09);break;
default:break;
}
}
void n_shift()
{
Sector_Erase(0x0200);
switch(n1)
{
case 0x00:Byte_Program(0x0200,0x00);break;
case 0x01:Byte_Program(0x0200,0x01);break;
case 0x02:Byte_Program(0x0200,0x02);break;
case 0x03:Byte_Program(0x0200,0x03);break;
case 0x04:Byte_Program(0x0200,0x04);break;
case 0x05:Byte_Program(0x0200,0x05);break;
case 0x06:Byte_Program(0x0200,0x06);break;
case 0x07:Byte_Program(0x0200,0x07);break;
case 0x08:Byte_Program(0x0200,0x08);break;
case 0x09:Byte_Program(0x0200,0x09);break;
default:break;
}
switch(n2)
{
case 0x00:Byte_Program(0x0202,0x00);break;
case 0x01:Byte_Program(0x0202,0x01);break;
case 0x02:Byte_Program(0x0202,0x02);break;
case 0x03:Byte_Program(0x0202,0x03);break;
case 0x04:Byte_Program(0x0202,0x04);break;
case 0x05:Byte_Program(0x0202,0x05);break;
case 0x06:Byte_Program(0x0202,0x06);break;
case 0x07:Byte_Program(0x0202,0x07);break;
case 0x08:Byte_Program(0x0202,0x08);break;
case 0x09:Byte_Program(0x0202,0x09);break;
default:break;
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Display_current_Temperature
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Display_Temperature()
{
unsigned char ng=0;
int i=0;
//char Signed_current_Temp; // 负数标志位,如果为负数则取反加
if((temp_data[1]&0xf8)==0xf8)
{ temp_data[1]=~temp_data[1];
temp_data[0]=~temp_data[0]+1;
ng=1;
}
temp11=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x07)<<4); // 取中间八位,即整数部分的值
HI_Alarm=temp11 >=Alarm_Temp?1:0;
shi=temp11/10; // 取十位数据暂存
ge=temp11%10; // 取个位数据暂存
xiao=df_Table[temp_data[0]&0x0f]; // 取小数位据暂存
temp10=shi*100+ge*10+xiao; //温度数值扩大10倍,则没有小数,变为全整型
if( DIS_flag==0)
{
Show_Pattern(&wendu_set,0x00,0x01,XLevel+0x0c,0x28,0); //(Show Pattern - 温度)温度:
Show_Pattern(&Ascii[ge-1][32],0x00,0x01,XLevel+0x40,0x10,0); // 个位数
Show_Pattern(&dian_set,0x00,0x01,XLevel+0x50,0x08,0); //小数点
Show_Pattern(&Ascii[xiao-1][32],0x00,0x01,XLevel+0x58,0x10,0); //小位数
Show_Pattern(&fuhao_set[0][32],0x00,0x01,XLevel+0x68,0x10,0); // (℃)
if(shi=='0')
{Show_Pattern(&fuhao_set[3][32],0x00,0x01,XLevel+0x30,0x10,0);} //显示空格,高位为0不显示;
else
{Show_Pattern(&Ascii[shi-1][32],0x00,0x01,XLevel+0x30,0x10,0);} //高位正常显示;
// -------Show Pattern - 电流,----------//
Show_Pattern(&dianliu_set,0x02,0x03,XLevel+0x0c,0x28,0); // 电流:
Show_Pattern(&dian_set,0x02,0x03,XLevel+0x40,0x08,0);// .
Show_Pattern(&fuhao_set[1][32],0x02,0x03,XLevel+0x68,0x10,0);// A
switch(b)
{
case 0: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x48,0x10,0); //小数第一位“0”
Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“0”
break;
case 1: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[2][32],0x02,0x03,XLevel+0x48,0x10,0); //小数第一位“3”
Show_Pattern(&Ascii[5][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“6”
// SBUF=0xe5 ;while(!TI);TI=0;
break;
case 2: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[3][32],0x02,0x03,XLevel+0x48,0x10,0); //小数第一位“4”
Show_Pattern(&Ascii[7][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“8”
//SBUF=0xe9 ;while(!TI);TI=0;
break;
case 3: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[5][32],0x02,0x03,XLevel+0x48,0x10,0);//小数第一位“6”
Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“0”
break;
case 4: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[6][32],0x02,0x03,XLevel+0x48,0x10,0);//小数第一位“7”
Show_Pattern(&Ascii[1][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“2”
break;
case 5: Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[7][32],0x02,0x03,XLevel+0x48,0x10,0);//小数第一位“8”
Show_Pattern(&Ascii[3][32],0x02,0x03,XLevel+0x58,0x10,0); //小数第二位“4"
break;
default:break;
}
}
// -------查询 - 温度、电流,----------//
if(query_wendu) //温度发送标志
{
ES = 0; //发送数据时,关串口中断
SBUF=0xa1;while(!TI);TI=0;
SBUF=temp11;while(!TI);TI=0;
SBUF=xiao;while(!TI);TI=0;
query_wendu = 0;// 温度已发送标志
ES = 1; //串口中断打开
}
if(query_dianliu)
{ ES = 0;
query_dianliu=0;
if(EN==1)
{
//发送时关串口中断,//0.00A
SBUF=0xb0;while(!TI); TI=0; //当TI=0时,while条件一直成立,一直做后面的空等待{},
SBUF=0x00;while(!TI); TI=0; //即发送数据,直到数据发送完TI=1,才跳出此循环,向CPU申请中断,完成一次发送过程
SBUF=0x00;while(!TI); TI=0;
}
else if((M4==0)&&(M3==1)&&(M2==1)&&(M1==1)) //0.36A
{
// ES = 0; //关串口中断
SBUF=0xb0; while(!TI);TI=0;
SBUF=0x00; while(!TI);TI=0;
SBUF=0x24; while(!TI);TI=0;
// ES=1;
}
else if((M4==1)&&(M3==0)&&(M2==1)&&(M1==1)) //0.48A
{
// ES = 0; //关串口中断
SBUF=0xb0; while(!TI);TI=0;
SBUF=0x00; while(!TI);TI=0;
SBUF=0x30; while(!TI);TI=0;
// ES=1;
}
else if((M4==1)&&(M3==1)&&(M2==0)&&(M1==1)) //0.60A
{
// ES = 0; //关串口中断
SBUF=0xb0; while(!TI);TI=0;
SBUF=0x00; while(!TI);TI=0;
SBUF=0x3c; while(!TI);TI=0;
// ES=1;
}
else if((M4==1)&&(M3==1)&&(M2==1)&&(M1==0)) //0.72A
{
// ES = 0; //关串口中断
SBUF=0xb0; while(!TI); TI=0;
SBUF=0x00; while(!TI);TI=0;
SBUF=0x48; while(!TI);TI=0;
// ES=1;
}
else //0.84A
{
// ES=0; //关串口中断
SBUF=0xb0; while(!TI); TI=0;
SBUF=0x00; while(!TI);TI=0;
SBUF=0x54; while(!TI);TI=0;
// ES=1;
}
ES=1;
}
// -------报警函数- ,----------//
if(HI_Alarm)
{
Fade_Out();
Fade_In();
Fade_Out();
Fade_In();
Delay(1);
}
else
{
_nop_();_nop_();
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// 速度控制与显示函数
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void rade_control()
{
// SBUF=High;while(!TI);TI=0;
add=(High-Low)/5;
// L=10;H=35;
// SBUF=Low;while(!TI);TI=0;
// SBUF=Low;while(!TI);TI=0;
if((flag==0)&&(DIS_flag==0))
{
// SBUF=temp11;while(!TI);TI=0;
if((temp11
{
// SBUF=0xdd;while(!TI);TI=0;
b=0;
// SBUF=High;while(!TI);TI=0;
// SBUF=temp11;while(!TI);TI=0;
} //关断风机
//大于10度小于13,启动最小档,在10~15度工作在最小档,当温度降到8以下再关断风扇
else if((temp11<(Low+add-2))&&(temp11>=Low)&&(flag==0)) // 显示“0.36A”
{
b=1;
// SBUF=0xcc;while(!TI);TI=0;
}
//15
else if((temp11<(Low+add*2-2))&&(temp11>=(Low+add))&&(flag==0)) // 显示“0.48A”
{// SBUF=0xff;while(!TI);TI=0;
b=2;
// SBUF=0xb0;while(!TI);TI=0;
}
//20
else if((temp11<(Low+add*3-2))&&(temp11>=(Low+add*2))&&(flag==0)) // 显示“0.60A”
{
b=3;
}
//25
else if((temp11<(Low+add*4-2))&&(temp11>=(Low+add*3))&&(flag==0)) // 显示“0.72A”
{
b=4;
}
//30
else if(temp11>(Low+add*4)) // 显示“0.84A”
{
b=5;
}
switch(b)
{
case 0: EN=1;
break;
case 1: EN=0; M1=1; M2=1; M3=1; M4=0; // J14 继电器通 最小档 4.6V R并=5.6K
break;
case 2: EN=0; M1=1; M2=1; M3=0; M4=1; // J13 继电器通 6.5V R并=15K
break;
case 3: EN=0; M1=1; M2=0; M3=1; M4=1; // J12 继电器通 7.8V R并=27K
break;
case 4: EN=0; M1=0; M2=1; M3=1; M4=1; // J11 继电器通 9V R并=47K
break;
case 5: EN=0; M1=1; M2=1; M3=1; M4=1; //最大档 10.6V
break;
default:break;
}
}
if((flag==1)&&(rec[0]==0x02)&&(DIS_flag==0))//加了rec[0]==0x02语句,否则,手动加速后,flag=1,当你发查询语句55 01 01 00 00 57后,
// rec[1]=01,不管rec[0]是否==0x02,便又执行下面的case 1语句
{
switch(rec[1])
{
case 1: EN=0;M1=1;M2=1;M3=1;M4=0; // 开启风扇到最小档
b=1;
break;
case 2: EN=0;M1=1;M2=1;M3=0;M4=1;
b=2;
break;
case 3: EN=0;M1=1;M2=0;M3=1;M4=1;
b=3;
// SBUF=0xd3;while(!TI);TI=0;
break; //
case 4: EN=0; M1=0; M2=1; M3=1; M4=1;
// SBUF=0xd4;while(!TI);TI=0;
b=4;
break;
case 5: EN=0; M1=1; M2=1; M3=1; M4=1;
b=5;
break;
default:break;
}
}//flag=1;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// 速度控制与显示函数,上电时用
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void rade_controla(void)
{
add=(High-Low)/5;
if(flag==0)
{ // SBUF=0xa0;while(!TI);TI=0;
//if(temp11
if((temp11
{
b=0;
} //关断风机
//大于10度小于15
else if((temp11<(Low+add))&&(temp11>=Low)&&(flag==0)) // 显示“0.36A”
{
b=1;
// SBUF=0xa2 ;while(!TI);TI=0;
}
//15
else if((temp11<(Low+add*2))&&(temp11>=(Low+add))&&(flag==0)) // 显示“0.48A”
{
b=2;
}
//20
else if((temp11<(Low+add*3))&&(temp11>=(Low+add*2))&&(flag==0)) // 显示“0.60A”
{
b=3;
}
//25
else if((temp11<(Low+add*4))&&(temp11>=(Low+add*3))&&(flag==0)) // 显示“0.72A”
{
b=4;
}
//30
else if(temp11>(Low+add*4)) // 显示“0.84A”
{
b=5;
}
switch(b)
{
case 0: EN=1;
break;
case 1: EN=0; M1=1; M2=1; M3=1; M4=0; // J14 继电器通 最小档 4.6V R并=5.6K
break;
case 2: EN=0; M1=1; M2=1; M3=0; M4=1; // J13 继电器通 6.5V R并=15K
break;
case 3: EN=0; M1=1; M2=0; M3=1; M4=1; // J12 继电器通 7.8V R并=27K
break;
case 4: EN=0; M1=0; M2=1; M3=1; M4=1; // J11 继电器通 9V R并=47K
break;
case 5: EN=0; M1=1; M2=1; M3=1; M4=1; //最大档 10.6V
break;
default:break;
}
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// scan()
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void scan()//1~5按键用 按键扫描函数
{
if((key0==0)||(key1==0)||(key2==0)||(key3==0)||(key4==0))
// OLED_Init();
// InitUart();
{
// Delay(1);
DIS_flag=1;
//SBUF=0xa0;while(!TI);TI=0;
shift();
// SBUF=0xa0;while(!TI);TI=0;
//while(1)
//{
// SBUF=0xa0;while(!TI);TI=0;
if((flag0==0)&&(flag1==0)&&(flag2==0)&&(flag3==0)&&(flag4==0)&&(flag5==0)&&(flag6==0))
{
m1=Byte_Read(0x0000);
m2=Byte_Read(0x0002);
m3=Byte_Read(0x0004);
m4=Byte_Read(0x0006);
p1=Byte_Read(0x0008);
p2=Byte_Read(0x000a);
p3=Byte_Read(0x000c);
p4=Byte_Read(0x000e);
p5=Byte_Read(0x0010);
n1=Byte_Read(0x0200);
n2=Byte_Read(0x0202);
SBUF=m2;while(!TI);TI=0;SBUF=m3;while(!TI);TI=0;
//SBUF=m3;while(!TI);TI=0;SBUF=m4;while(!TI);TI=0;
SBUF=p1;while(!TI);TI=0;SBUF=p2;while(!TI);TI=0;
shift();
//一上电显示的界面
// Show_Pattern(&pinlv,0x00,0x01,XLevel,0x30,0);
// Show_Pattern(&dot,0x00,0x01,XLevel+0x48,0x08,0);
// Show_Pattern(&du,0x00,0x01,XLevel+0x5c,0x10,0);
// Show_Pattern(&gonglv,0x02,0x03,XLevel,0x30,0);
// Show_Pattern(&w,0x02,0x03,XLevel+0x40,0x10,0);
// Show_Pattern(a1,0x00,0x01,XLevel+0x30,0x08,0);
// Show_Pattern(a2,0x00,0x01,XLevel+0x38,0x08,0);
// Show_Pattern(a3,0x00,0x01,XLevel+0x40,0x08,0);
// Show_Pattern(a4,0x00,0x01,XLevel+0x50,0x08,0);
// Show_Pattern(b1,0x02,0x03,XLevel+0x30,0x08,0);
// Show_Pattern(b2,0x02,0x03,XLevel+0x38,0x08,0);
if((key0==0)||(key1==0)||(key2==0)||(key3==0)) //初始,只要有任何一个键按下去,都显示设置界面
{
Delay(1);
flag0=1;flag1=1;
Fill_RAM(0x00);
Show_Pattern(&wendu1_set,0x00,0x01,XLevel+0x1f,0x60,0); //设置低温
Show_Pattern(&one_box,0x00,0x01,XLevel+0x08,0x10,1); //数字“1”,显示被选中状态,黑字,黄色框子
Show_Pattern(&two_box,0x02,0x03,XLevel+0x08,0x10,0);
Show_Pattern(&wendu2_set,0x02,0x03,XLevel+0x1f,0x60,0); //设置高温
//DIS_flag=0;
}
}
if(flag0==1)
{
if(flag1==1)
{
if(key1==0) //下翻键,
{ //菜单往下翻,移到下一行,“2”,
Delay(1);
flag2=1;flag1=0;
Show_Pattern(&wendu1_set,0x00,0x01,XLevel+0x1f,0x60,0);
Show_Pattern(&one_box,0x00,0x01,XLevel+0x08,0x10,0);//“1”恢复原来的黄字
Show_Pattern(&wendu2_set,0x02,0x03,XLevel+0x1f,0x60,0);
Show_Pattern(&two_box,0x02,0x03,XLevel+0x08,0x10,1); //“2”被选中,返显示,黑字,黄色框子
}
if(key4==0) //设置ok确定键 ,对a2设置
{
Delay(1);
Fill_RAM(0x00);
flag4=1;flag1=0;aemp1=a2;i=0x18;a2=0;
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
a2=aemp1;
}
}
}
if(flag2==1) //标志位判读 ,“2” 被选中
{
if(key1==0) //若是key1按键按下,(下翻键,翻到下一行“3”)
{
Delay(1);
flag3=1;flag2=0;
Fill_RAM(0x00);
Show_Pattern(&three_box,0x00,0x01,XLevel+0x08,0x10,1); // 3 报警温度设置
Show_Pattern(baojing,0x00,0x01,XLevel+0x1f,0x60,0);
}
if(key0==0) //上翻键,翻到上一行
{
Delay(1);
flag1=1;flag2=0;
Fill_RAM(0x00);
Show_Pattern(&one_box,0x00,0x01,XLevel+0x08,0x10,1); //显示选中“1”
Show_Pattern(&wendu1_set,0x00,0x01,XLevel+0x1f,0x60,0);
Show_Pattern(&two_box,0x02,0x03,XLevel+0x08,0x10,0);
Show_Pattern(&wendu2_set,0x02,0x03,XLevel+0x1f,0x60,0);
}
if(key4==0) //设置ok确定键, 设置“2”
{
Delay(1);
Fill_RAM(0x00);
flag5=1;flag2=0;i=0x18;aemp1=b1;b1=0;
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
b1=aemp1;
}
}
if((flag5==1)&&(flag2==0))
{
if(i==0x18)
{
if(key0==0) //上翻键,“+1”
{
Delay(1);
n1+=1;
if(n1>9)
{
n1=0;
}
SBUF= n1;while(!TI);TI=0;
switch(n1)
{
case 0x00:b1=zero;break;
case 0x01:b1=one;break;
case 0x02:b1=two;break;
case 0x03:b1=three;break;
case 0x04:b1=four;break;
case 0x05:b1=five;break;
case 0x06:b1=six;break;
case 0x07:b1=seven;break;
case 0x08:b1=eight;break;
case 0x09:b1=nine;break;
default:break;
}
Delay(1);
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,1);
}
if(key1==0) //下翻键,数字减一 “-1”
{
Delay(1);
n1-=1;
if(n1<0)
{
n1=9;
}
SBUF= n1;while(!TI);TI=0;
switch(n1)
{
case 0x00:b1=zero;break;
case 0x01:b1=one;break;
case 0x02:b1=two;break;
case 0x03:b1=three;break;
case 0x04:b1=four;break;
case 0x05:b1=five;break;
case 0x06:b1=six;break;
case 0x07:b1=seven;break;
case 0x08:b1=eight;break;
case 0x09:b1=nine;break;
default:break;
}
Delay(1);
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,1);
}
if(key3==0) //右移键,->
{
Delay(1);
aemp1=b2;i=0x20;b2=0;
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
b2=aemp1;
}
}
if(i==0x20)
{
if(key0==0)
{
Delay(1);
n2+=1;
if(n2>9)
{
n2=0;
}
SBUF= n2;while(!TI);TI=0;
switch(n2)
{
case 0x00:b2=zero;break;
case 0x01:b2=one;break;
case 0x02:b2=two;break;
case 0x03:b2=three;break;
case 0x04:b2=four;break;
case 0x05:b2=five;break;
case 0x06:b2=six;break;
case 0x07:b2=seven;break;
case 0x08:b2=eight;break;
case 0x09:b2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,1);
}
if(key1==0)
{
Delay(1);
n2-=1;
if(n2<0)
{
n2=9;
}
SBUF= n2;while(!TI);TI=0;
switch(n2)
{
case 0x00:b2=zero;break;
case 0x01:b2=one;break;
case 0x02:b2=two;break;
case 0x03:b2=three;break;
case 0x04:b2=four;break;
case 0x05:b2=five;break;
case 0x06:b2=six;break;
case 0x07:b2=seven;break;
case 0x08:b2=eight;break;
case 0x09:b2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,1);
}
if(key2==0)// <- 由b2移到b1
{
Delay(1);
aemp1=b1;i=0x18;b1=0;
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
b1=aemp1;
}
if(key3==0) // ->由 b2移到“ESC”
{
Delay(1);
i=0x54;
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,1);
}
}
if(i==0x54)
{
if(key4==0) //返回初始界面
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0;
DIS_flag=0;
}
if(key2==0) // <- 由ESC移到b2
{
Delay(1);
aemp1=b2;i=0x20;b2=0;
Show_Pattern(b1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(b2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
b2=aemp1;
}
}
if((key4==0)&&(i!=0x54))
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0;
Show_Pattern(wait,0x00,0x03,XLevel+0x18,0x64,0);
Delay(2);
Fill_RAM(0x00);
n_shift();
shift();
DIS_flag=0;
}
}
if(flag3==1) //选中“3”
{
if(key0==0) //往上翻一行,界面显示“1,2“
{
Delay(1);
flag2=1;flag3=0; //选中“2”的标志位;
Show_Pattern(&one_box,0x00,0x01,XLevel+0x08,0x10,0);
Show_Pattern(&wendu1_set,0x00,0x01,XLevel+0x1f,0x60,0);
Show_Pattern(&two_box,0x02,0x03,XLevel+0x08,0x10,1);
Show_Pattern(&wendu2_set,0x02,0x03,XLevel+0x1f,0x60,0);
}
if(key4==0) //进入“3”设置
{
Delay(1);
flag6=1;flag3=0;Fill_RAM(0x00);
aemp1=c1;i=0x18;c1=0;
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(c2,0x00,0x01,XLevel+0x20,0x08,0);//后面的0代表数字显示为黄色亮
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1); //取反后,后面的1代表数字显示为黑色亮
c1=aemp1;
}
}
if((flag6==1)&&(flag3==0)) //进入“3”设置
{
if(i==0x18) //对c1第一位数字设置
{
if(key0==0) // +1,增加键
{
Delay(1);
p1+=1;
if(p1>9)
{
p1=0;
}
SBUF= p1;while(!TI);TI=0;
switch(p1)
{
case 0x00:c1=zero;break;
case 0x01:c1=one;break;
case 0x02:c1=two;break;
case 0x03:c1=three;break;
case 0x04:c1=four;break;
case 0x05:c1=five;break;
case 0x06:c1=six;break;
case 0x07:c1=seven;break;
case 0x08:c1=eight;break;
case 0x09:c1=nine;break;
default:break;
}
Delay(1);
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,1);
}
if(key1==0) // -1,自减
{
Delay(1);
p1-=1;
if(p1<0)
{
p1=9;
}
SBUF= p1;while(!TI);TI=0;
switch(p1)
{
case 0x00:c1=zero;break;
case 0x01:c1=one;break;
case 0x02:c1=two;break;
case 0x03:c1=three;break;
case 0x04:c1=four;break;
case 0x05:c1=five;break;
case 0x06:c1=six;break;
case 0x07:c1=seven;break;
case 0x08:c1=eight;break;
case 0x09:c1=nine;break;
default:break;
}
Delay(1);
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,1);
}
if(key3==0) //右移键->
{
Delay(1);
aemp1=c2;i=0x20;c2=0;
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(c2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
c2=aemp1;
}
}
if(i==0x20) //对c2第二位数字设置
{
if(key0==0) // +1,增加键
{
Delay(1);
p2+=1;
if(p2>9)
{
p2=0;
}
SBUF= p2;while(!TI);TI=0;
switch(p2)
{
case 0x00:c2=zero;break;
case 0x01:c2=one;break;
case 0x02:c2=two;break;
case 0x03:c2=three;break;
case 0x04:c2=four;break;
case 0x05:c2=five;break;
case 0x06:c2=six;break;
case 0x07:c2=seven;break;
case 0x08:c2=eight;break;
case 0x09:c2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(c2,0x00,0x01,XLevel+i,0x08,1);
}
if(key1==0) // -1,增加键
{
Delay(1);
p2-=1;
if(p2<0)
{
p2=9;
}
SBUF= p2;while(!TI);TI=0;
switch(p2)
{
case 0x00:c2=zero;break;
case 0x01:c2=one;break;
case 0x02:c2=two;break;
case 0x03:c2=three;break;
case 0x04:c2=four;break;
case 0x05:c2=five;break;
case 0x06:c2=six;break;
case 0x07:c2=seven;break;
case 0x08:c2=eight;break;
case 0x09:c2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(c2,0x00,0x01,XLevel+i,0x08,1);
}
if(key2==0) //←,左移,移到“c1”
{
Delay(1);
aemp1=c1;i=0x18;c1=0;
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(c2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
c1=aemp1;
}
if(key3==0)
{
Delay(1);
i=0x54;
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(c2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,1);
}
}
if(i==0x54) //选中“ESC”,
{
if(key4==0) //按下,ok键
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0; //返回一上电的初始界面
DIS_flag=0;
}
if(key2==0) //<-左移键,移到c2
{
Delay(1);
aemp1=c2;i=0x20;c2=0;
Show_Pattern(c1,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(c2,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1); // c2反显
c2=aemp1;
}
}
if((key4==0)&&(i!=0x54)) //如果选中的不是ESC,按下ok键,设置参数,显示“请稍后”
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0;
Show_Pattern(wait,0x00,0x03,XLevel+0x18,0x64,0);
Delay(2);
Fill_RAM(0x00);
m_shift();
shift();
DIS_flag=0;
}
}
if((flag4==1)&&(flag1==0)) //进入“2”设置界面
{
if(i==0x18) //对a2设置
{
if(key0==0) //+1,
{
Delay(1);
m2+=1;
if(m2>9)
{
m2=0;
}
SBUF=m2;while(!TI);TI=0;
switch(m2)
{
case 0x00:a2=zero;break;
case 0x01:a2=one;break;
case 0x02:a2=two;break;
case 0x03:a2=three;break;
case 0x04:a2=four;break;
case 0x05:a2=five;break;
case 0x06:a2=six;break;
case 0x07:a2=seven;break;
case 0x08:a2=eight;break;
case 0x09:a2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,1);
}
if(key1==0) //-1
{
Delay(1);
m2-=1;
if(m2<0)
{
m2=9;
}
SBUF=m2;while(!TI);TI=0;
switch(m2)
{
case 0x00:a2=zero;break;
case 0x01:a2=one;break;
case 0x02:a2=two;break;
case 0x03:a2=three;break;
case 0x04:a2=four;break;
case 0x05:a2=five;break;
case 0x06:a2=six;break;
case 0x07:a2=seven;break;
case 0x08:a2=eight;break;
case 0x09:a2=nine;break;
default:break;
}
Delay(1);
Show_Pattern(a2,0x00,0x01,XLevel+0x018,0x08,1);
}
if(key3==0) //->,右移一位,显示a3
{
Delay(1);
aemp1=a3;i=0x20;a3=0;
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
a3=aemp1;
}
}
if(i==0x20)
{
if(key0==0)
{
Delay(1);
m3+=1;
if(m3>9)
{
m3=0;
}
SBUF=m3;while(!TI);TI=0;
switch(m3)
{
case 0x00:a3=zero;break;
case 0x01:a3=one;break;
case 0x02:a3=two;break;
case 0x03:a3=three;break;
case 0x04:a3=four;break;
case 0x05:a3=five;break;
case 0x06:a3=six;break;
case 0x07:a3=seven;break;
case 0x08:a3=eight;break;
case 0x09:a3=nine;break;
default:break;
}
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,1);
}
if(key1==0)
{
Delay(1);
m3-=1;
if(m3<0)
{
m3=9;
}
SBUF= m3;while(!TI);TI=0;
switch(m3)
{
case 0x00:a3=zero;break;
case 0x01:a3=one;break;
case 0x02:a3=two;break;
case 0x03:a3=three;break;
case 0x04:a3=four;break;
case 0x05:a3=five;break;
case 0x06:a3=six;break;
case 0x07:a3=seven;break;
case 0x08:a3=eight;break;
case 0x09:a3=nine;break;
default:break;
}
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,1);
}
if(key2==0) // <-左移键,移到a2
{
Delay(1);
aemp1=a2;i=0x18;a2=0;
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
a2=aemp1;
}
if(key3==0) // ->右移键,移到ESC
{
Delay(1);
i=0x54;
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,1);
}
}
if(i==0x54)
{
if(key4==0) //返回初始界面
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0;
DIS_flag=0;
}
if(key2==0)
{
Delay(1);
aemp1=a3;i=0x20;a3=0;
Show_Pattern(a2,0x00,0x01,XLevel+0x18,0x08,0);
Show_Pattern(a3,0x00,0x01,XLevel+0x20,0x08,0);
Show_Pattern(du,0x00,0x01,XLevel+0x28,0x10,0);
Show_Pattern(ESC,0x02,0x03,XLevel+0X54,0x20,0);
Show_Pattern(aemp1,0x00,0x01,XLevel+i,0x08,1);
a3=aemp1;
}
}
if((key4==0)&&(i!=0x54))
{
Delay(1);
Fill_RAM(0x00);
flag0=0;flag1=0;flag2=0;flag3=0;flag4=0;flag5=0;flag6=0;
Show_Pattern(wait,0x00,0x03,XLevel+0x18,0x64,0);
Delay(2);
Fill_RAM(0x00);
m_shift();
shift();
DIS_flag=0;
}
}
d1=m2;d2=m3;
Low=d1*10+d2;//SBUF=Low;while(!TI);TI=0;
t1=n1;d2=n2;
High=n1*10+n2;//SBUF=High;while(!TI);TI=0;
bao1=p1;bao2=p2;
Alarm_Temp=bao1*10+bao2;//SBUF=Alarm_Temp; while(!TI);TI=0;
// DIS_flag=0;
}
}
/****************主函数************************/
void main()
{
init_serial(); //串口初始化
//SBUF=0xaa;while(!TI);TI=0;
ow_reset(); //开机先转换一次
OLED_Init();
Display_Temperature(); //屏初始化 , 显示一上电默认温度:85°
// -------Show Pattern - 电流,----------//
Show_Pattern(&dianliu_set,0x02,0x03,XLevel+0x0c,0x28,0); // 电流:
Show_Pattern(&dian_set,0x02,0x03,XLevel+0x40,0x08,0);// .
Show_Pattern(&fuhao_set[1][32],0x02,0x03,XLevel+0x68,0x10,0);// A
Show_Pattern(&Ascii[-1][32],0x02,0x03,XLevel+0x30,0x10,0); //个位“0”
Show_Pattern(&Ascii[7][32],0x02,0x03,XLevel+0x48,0x10,0);//小数第一位“8”
Show_Pattern(&Ascii[3][32],0x02,0x03,XLevel+0x58,0x10,0);//"4"一上电,显示最大电流
_delay1(250); _delay1(250);
_delay1(250); _delay1(250);
_delay1(250); _delay1(250); //开机最大档工作时间
_delay1(250); _delay1(250);
_delay1(250); _delay1(250);
_delay1(250); _delay1(250);
write_byte(0xcc); //Skip ROM
write_byte(0x44);//发转换命令
_delay1(250); _delay1(250); //加上延时,这样温度传感器采集的温度才是一上电的温度,要不它采来的是默认温度:85°
read_temp(); // 对一上电的温度处理
Display_Temperature(); //处理温度数据
rade_controla(); //上电后,对风温的第一次准确的采样
while(1)
{
scan();
read_temp(); //处理温度数据
Display_Temperature(); //显示函数
rade_control(); //速度控制
//SBUF=0xbb;while(!TI);TI=0;
}
}
void timer0 (void) interrupt 1 //程序写的是26us,示波器看的却是38us
{
EA=0; //关总中断
TH0=0xff;
TL0=0xf6;
count++;
EA=1; // 开总中断
}
bit IO1_FLG=0;
//uchar i=0;
void serialREC() interrupt 4
{
uchar a;
ES=0;
if(RI)
{
a=SBUF;
//SBUF=a;while(!TI);TI=0;
if(IO1_FLG) //第一个字节为0x55 时,开始接受下面的数据,否则不是命令,不接受数据,
{
rec[i]=a;i++;
if(i==5)
{
if(rec[4]==(0x55+rec[0]+rec[1]+rec[2]+rec[3]))
{
switch(rec[0])
{
case 0x00:flag=0; //参数设置
if(rec[1]==0x00) {Alarm_Temp=rec[2]; SBUF=0xaa;while(!TI);TI=0;}//报警温度
if(rec[1]==0x01) {Low=rec[2];High=rec[3]; SBUF=0xbb;while(!TI);TI=0;} //工作温度范围
if(rec[1]==0x02) {shut=1; SBUF=0xcc;while(!TI);TI=0;} //关风扇
if(rec[1]==0x03) {shut=0; SBUF=0xdd;while(!TI);TI=0;} //开风扇
break;
case 0x01:
if(rec[1]==0x00) query_wendu=1; //参数查询
if(rec[1]==0x01) query_dianliu=1;//参数电流
break;
case 0x02: {flag=1;SBUF=0xee;while(!TI);TI=0;} // 网络加速,手动发命令
break;
default:break;
}
}
IO1_FLG=0;i=0;
}
}
else if(a==0x55){
IO1_FLG=1;
}
RI=0;
}
ES=1;
}
//***********************结束**************************//