📄 5588.c
字号:
#include <REG52.H>
#include <intrins.h>
sbit B0=B^0;
sbit B1=B^1;
sbit B2=B^2;
sbit B3=B^3;
sbit B4=B^4;
sbit B5=B^5;
sbit B6=B^6;
sbit B7=B^7;
//P0^0-P0^3用于旋转编码器
sbit FootEnter=P0^4;
sbit LowFreEnter=P0^5;
sbit TestWater=P0^6;
sbit beep=P0^7;
//
sbit KnockPin1=P1^0;
sbit KnockPin2=P1^1;
sbit HeatPin=P1^2;
// P1^3保留
sbit PumpPin=P1^4;
sbit _0832_DATA=P1^5;
sbit _0832_CLK=P1^6;
sbit _0832_CS=P1^7;
//P2^0-P2^3用于低频控制
sbit _1625_CS=P2^4;
sbit _1625_WR=P2^5;
sbit _1625_Data=P2^6;
sbit _93C46_DATA=P2^7;
//
sbit _8563_SDA=P3^0;
sbit _8563_SCL=P1^3;
//P3^2保留
//P3^3保留
//P3^4(T0)检测水温
//P3^5(T1)检测环境湿度
sbit _93C46_CS=P3^6;
sbit _93C46_CLK=P3^7;
unsigned char Add10=0;
unsigned char Add26=0;
unsigned char Add34=0;
bit bdata KnockOut,KeyEnable,Direct,LowFreKeyEnable,LowFreDirect,RemoteKeyEnable;
bit bdata OldSecondDotState,SecondDotState,ReadSecondEnable;
bit bdata OldLightState,LightState,PauseLightState,IntensityLightState,RefreshLightState,PerfectLightState,SynthesizeLightState,ManualLightState;
bit bdata OneLightState,TwoLightState,ThreeLightState,FourLightState,FiveLightState,SixLightState,SevenLightState;
bit bdata SamplingComplete;
bit bdata DelayHeatCountEnable,DelayHeatCountComplete;
bit bdata DelayStopWaterCountEnable,DelayStopWaterCountComplete;
bit bdata KnockPause;
bit bdata SetParameterEnable;
bit bdata _4_beep;
bit bdata HoldTemperature;
bit bdata WrongState;
bit bdata LowWaterTemperatureFlag;
bit bdata _1Minute;
bit bdata FirstTime;
bit bdata WaterTemperatureShiftFlag;
#define ON 0
#define OFF 1
#define LIGHT 1
#define DARK 0
//对应ObjectBuf[15]
#define Cartoon 0
#define MainKey 1
#define Timer 2
#define Minute 3
#define Hour 4
#define WaterTemperatureSet 5
#define WaterTemperature 6
#define EnvTemperature 7
#define EnvHumidity 8
#define LowFreMainKey 9
#define LowFreTimer 10
#define LowFreIntensity 11
//#define PauseTime 12
//
#define other 30
#define Knock 31
#define TimeSum 32
#define SecondDot 33
#define PauseFlash 34
#define IntensityFlash 35
#define RefreshFlash 36
#define PerfectFlash 37
#define SynthesizeFlash 38
#define ManualFlash 39
#define OneFlash 40
#define TwoFlash 41
#define ThreeFlash 42
#define FourFlash 43
#define FiveFlash 44
#define SixFlash 45
#define SevenFlash 46
//*******************************
#define MainMenuMode 0
#define SetTimerMode 1
#define SetWaterTemperatureMode 2
#define SetHourMode 3
#define SetMinMode 4
#define LowFreMainMenuMode 0
#define SetLowFreIntensityMode 1
//*******************************
unsigned char LowFreOperateMode;
unsigned char LowFreSaveVal,LowFreCoderVal,LowFreCombiteVal;
unsigned char OldLowFreIntensityVal;
unsigned char OldLowFreMainKeyVal;
unsigned char LowFreRunMode;
unsigned char SaveVal,CoderVal,CombiteVal;
unsigned int KnockCount;
unsigned long idata TimeSumVal,OldTimeSumVal;
unsigned int T1CountVal,T0CountVal;
unsigned char _10msCount;
unsigned char SecondCount;
unsigned char Knock1Count,Knock2Count,BeepCount;
unsigned int CartoonCount;
unsigned int DelayHeatCount;
unsigned char ReceiveVal;
unsigned char SamplingCount;
unsigned char LowFreCommand;
unsigned int DelayStopWaterCount;
//unsigned char OldPauseTime;
unsigned char OldLowFreIntensity;
unsigned int _4_beepCount;
unsigned char WaterTemperatureShiftCount;
unsigned char OldTimerVal=255;
unsigned char OldLowFreTimerVal=255;
unsigned char OldWaterTemperatureSetVal;
unsigned char OldWaterTemperatureVal;
unsigned char OldHourVal;
unsigned char OldMinVal;
unsigned char OldSecondVal;
unsigned char OldEnvTemperatureVal;-----------------------------------------------------------------------------------------------
unsigned char OldEnvHumidityVal;
unsigned char OldMainKeyVal;
unsigned char OperateMode;//用于switch语句
unsigned char RunMode;//用于switch语句
unsigned char ClockBuf[3];
unsigned char ObjectBuf[15];
unsigned char code A5_SEG[11]={0xd7,0x06,0xe3,0xa7,0x36,0xb5,0xf5,0x07,0xf7,0xb7};
unsigned char code SEG[11]={0xdf,0x0e,0xeb,0xaf,0x3e,0xbd,0xfd,0x0f,0xff,0xbf};
unsigned int code WaterTemperatureList[121]={ //0-120度
424 ,
443 ,
462 ,
482 ,
502 ,
523 ,
544 ,
567 ,
590 ,
613 ,
638 ,
663 ,
689 ,
715 ,
742 ,
768 ,
799 ,
828 ,
859 ,
889 ,
921 ,
954 ,
987 ,
1021 ,
1055 ,
1091 ,
1127 ,
1164 ,
1202 ,
1240 ,
1280 ,
1320 ,
1361 ,
1402 ,
1444 ,
1487 ,
1531 ,
1575 ,
1621 ,
1673 ,
1713 ,
1760 ,
1808 ,
1856 ,
1905 ,
1955 ,
2005 ,
2056 ,
2107 ,
2159 ,
2211 ,
2263 ,
2316 ,
2370 ,
2424 ,
2478 ,
2532 ,
2587 ,
2642 ,
2697 ,
2752 ,
2808 ,
2863 ,
2943 ,
2974 ,
3030 ,
3085 ,
3141 ,
3196 ,
3251 ,
3306 ,
3361 ,
3415 ,
3469 ,
3523 ,
3576 ,
3629 ,
3681 ,
3733 ,
3785 ,
3836 ,
3886 ,
3936 ,
3985 ,
4033 ,
4081 ,
4131 ,
4180 ,
4230 ,
4278 ,
4327 ,
4374 ,
4422 ,
4468 ,
4515 ,
4560 ,
4604 ,
4648 ,
4691 ,
4733 ,
4775 ,
4815 ,
4855 ,
4894 ,
4932 ,
4970 ,
5006 ,
5043 ,
5079 ,
5115 ,
5150 ,
5186 ,
5222 ,
5258 ,
5295 ,
5332 ,
5366 ,
5399 ,
5432 ,
5464 ,
5495
};
unsigned int code EnvHumidityList[15]={
70,// 20%
130,// 25%
191,// 30%
251,// 35%60
376,// 40%125
611,// 45%235
841,// 50%230
1101,// 55%260
1321,// 60%220
1562,// 65%
1780,// 70%
1954,// 75%
2110,// 80%
2282,// 85%
2432// 90%
};
void delay_ms(unsigned char t)
{
unsigned char i;
while(t)
{
for(i=0;i<19;i++)
{
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
t--;
}
}
void WriteClockChip(unsigned char ChipRegisterAddr,unsigned char ByteLength)
{
unsigned char BitCount;
unsigned char ByteCount;
//MCU输出启动信号,启动I2C总线
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SDA=0;
_8563_SCL=0; _8563_SCL=0;
//MCU向总线上写地址A2,确定数据传输方向是从MCU到外设
B=0xa2;
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
//MCU发送与时钟芯片内的寄存器相对应的地址
B=ChipRegisterAddr;
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
for(ByteCount=0;ByteCount<ByteLength;ByteCount++)
{
B=ClockBuf[ByteCount];
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
}
//MCU输出停止信号,停止I2C总线
_8563_SDA=0;
_8563_SCL=1; _8563_SCL=1;
_8563_SDA=1;
}
void ReadClockChip(unsigned char ChipRegisterAddr,unsigned char ByteLength)//PCF8563
{
unsigned char BitCount;
unsigned char ByteCount;
//MCU输出启动信号,启动I2C总线
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SDA=0;
_8563_SCL=0; _8563_SCL=0;
//MCU向总线上写地址A2,确定数据传输方向是从MCU到外设
B=0xa2;
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
//MCU发送与时钟芯片内的寄存器相对应的地址
B=ChipRegisterAddr;
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
//MCU输出启动信号,启动I2C总线
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SDA=0;
_8563_SCL=0; _8563_SCL=0;
//MCU向总线上写地址A3,确定数据传输方向是从外设到MCU
B=0xa3;
for(BitCount=0;BitCount<8;BitCount++)
{
_8563_SDA=B7;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
B=B<<1;
}
//MCU发送标志位1
_8563_SDA=1;
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
//WaitAck();
for(ByteCount=0;ByteCount<ByteLength;ByteCount++)
{
_8563_SDA=1;//MCU接收数据之前必须先向数据线写一,使上拉电阻开路,这时数据才能输入,否则输入线总是0,
for(BitCount=0;BitCount<8;BitCount++)
{
B=B<<1;
_8563_SCL=1; _8563_SCL=1;
B0=_8563_SDA;
_8563_SCL=0; _8563_SCL=0;
}
ClockBuf[ByteCount]=B;
if(ByteCount<ByteLength-1)//除最后一个字节外,其他都要从MASTER发应答
{
_8563_SDA=0;
}
else
{
_8563_SDA=1;
}
_8563_SCL=1; _8563_SCL=1;
_8563_SCL=0; _8563_SCL=0;
}
//MCU输出停止信号,停止I2C总线
_8563_SDA=0;
_8563_SCL=1; _8563_SCL=1;
_8563_SDA=1;
}
void WriteLCD(unsigned char LCD_Addr,unsigned char _1625_Datata) //LCD写字节//
{
unsigned char temp;
_1625_CS=0;
//101
_1625_Data=1;
_1625_WR=0; _1625_WR=1;
_1625_Data=0;
_1625_WR=0; _1625_WR=1;
_1625_Data=1;
_1625_WR=0; _1625_WR=1;
B=LCD_Addr;
B=B<<1;//地址只有7位
for (temp=0;temp<7;temp++)
{
_1625_Data=B7;
_1625_WR=0; _1625_WR=1;
B=B<<1;
}
B=_1625_Datata;
for (temp=0;temp<4;temp++)
{
_1625_Data=B0;
_1625_WR=0; _1625_WR=1;
B=B>>1;//先写低位
}
_1625_CS=1;
}
void Write_LCD_Command(unsigned char LCD_Command) //LCD写命令//
{
unsigned char temp;
_1625_CS=0;
//100
_1625_Data=1;
_1625_WR=0; _1625_WR=1;
_1625_Data=0;
_1625_WR=0; _1625_WR=1;
_1625_Data=0;
_1625_WR=0; _1625_WR=1;
B=LCD_Command;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -