/****************************************
*
* the main; *
*
****************************************/
void main()@page 0
{
init();
tcc_init();
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
if(P&&T)Buzzer = 1;
delay(250);
P6CR |= 0X04;
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
WDTC();
c02_flag = 0;
while(c02_flag == 0)ircvstr(0,&H_minute_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)ircvstr(1,&L_minute_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)ircvstr(2,&H_second_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)ircvstr(3,&L_second_buf,1);
WDTC();
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
H_second = H_second_buf;
L_second = L_second_buf;
user_time_second = (ushort)H_second_buf*250 + (ushort)L_second_buf;
H_minute = H_minute_buf;
L_minute = L_minute_buf;
user_time_minute = (ushort)H_minute_buf*250 + (ushort)L_minute_buf;
wait_flag = 1;
set_state = 0;
second = 0;
TCC = 178;
ENI();
while(1){
WDTC();
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
/*扫描键盘*/
scankey();
/**长击计数**/
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
if((Cont & time_KEY1)||(Cont & add_KEY2)||(Cont & sub_KEY3)){
key_time++;
}else{
key_time=0;
}
/**按键鸣响**//**液位报警控制**/
if(((key_time == 100)&&(Cont & time_KEY1))||(Trg != 0)||(Cont & liquid_KEY5)||(Cont & liquid_KEY6)){
Buzzer = 1;
}else{
Buzzer = 0;
}
WDTC();
/**状态设置**/
if((key_time == 100) && (Cont & time_KEY1)){
On_delay = 0;
set_state++;
if(set_state == 3){
H_second_buf = (uchar)(user_time_second/250);
L_second_buf = (uchar)(user_time_second%250);
H_minute_buf = (uchar)(user_time_minute/250);
L_minute_buf = (uchar)(user_time_minute%250);
WDTC();
DISI();
H_second = H_second_buf;
L_second = L_second_buf;
H_minute = H_minute_buf;
L_minute = L_minute_buf;
P6CR |= 0X04;
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
WDTC();
c02_flag = 0;
while(c02_flag == 0)isendstr(0,&H_minute_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)isendstr(1,&L_minute_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)isendstr(2,&H_second_buf,1);
WDTC();
c02_flag = 0;
while(c02_flag == 0)isendstr(3,&L_second_buf,1);
wait_flag = 1;
set_state = 0;
second = 0;
TCC = 178;
ENI();
}
}
WDTC();
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
/**用户手动加油,启动和停止**/
/**按一下启动,加油状态再按一下停止加油**/
if((set_state == 0) && (Cont & aotu_KEY4)){
H_second = H_second_buf;
L_second = L_second_buf;
wait_flag = 1;
}
if((set_state == 0) && (Trg & time_KEY1)){
H_minute = H_minute_buf;
L_minute = L_minute_buf;
wait_flag = 0;
}
/*设置加油时间*/
if(set_state == 1){
On_delay = 0;
if((key_time > 80)||Trg){
if((Cont & add_KEY2) || (Trg & add_KEY2)){ //短击,长击;
user_time_second++;
if(user_time_second == 1000)
user_time_second = 1;
}
if((Cont & sub_KEY3) || (Trg & sub_KEY3)){
user_time_second--;
if(user_time_second == 0)
user_time_second = 999;
}
}
}
/*设置等待时间*/
if(set_state == 2){
On_delay = 0;
if((key_time > 80) || Trg){ //短击,长击;
if((Cont & add_KEY2) || (Trg & add_KEY2)){
user_time_minute++;
if(user_time_minute == 1000)
user_time_minute = 1;
}
if((Cont & sub_KEY3) || (Trg & sub_KEY3)){
user_time_minute--;
if(user_time_minute == 0)
user_time_minute = 999;
}
}
}
/**增强程序抗干挠*
if((set_state == 1)||(set_state == 2)||(set_state == 0)){NOP();} //注;第一次写时出错处;
else{
set_state = 0;
}
if(set_state > 3)set_state = 0;*/
while(1){
/**灯指示及显示程序**/
WDTC();
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
P7CR &= 0xc0;
P6CR = 0X77;
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
R63 = 0;
R67 = 1;
PORT7 |= 0X07;
NOP();NOP();NOP();NOP();
NOP();WDTC();NOP();
if((Cont & liquid_KEY5)||(Cont & liquid_KEY6)){
On_delay = 0;
Yellow = 0;
Red = 1;
Green = 0;
delay(200);
NOP();WDTC();
Led_cr = 1;
NOP();NOP();
PORT7 |= 0X38;
delay(100);WDTC();
NOP();NOP();
dip_seg3(888);
}else{
if(set_state == 0){ //正常模式;
if(wait_flag){
On_delay = 1;
Yellow = 0;
Red = 0;
Green = 1;
delay(200);NOP();WDTC();
Led_cr = 1;
NOP();NOP();
PORT7 |= 0X38;
delay(100);WDTC();
NOP();NOP();
dis_buf = (ushort)H_second*250 + (ushort)L_second;
dip_seg3(dis_buf);
}else{
On_delay = 0;
Yellow = 1;
Red = 0;
Green = 0;
delay(200);NOP();WDTC();
Led_cr = 1;
NOP();NOP();
PORT7 |= 0X38;
delay(100);WDTC();
NOP();NOP();
dis_buf = (ushort)H_minute*250 + (ushort)L_minute;
dip_seg3(dis_buf);
}
}else{
On_delay = 0;
if(set_state == 1){ //设置自动加油时间;
Red = 1;
Yellow = 0;
Green = 1;
delay(200);NOP();WDTC();
Led_cr = 1;
NOP();NOP();
PORT7 |= 0X38;
delay(100);WDTC();
dip_seg3(user_time_second);
}
if(set_state == 2){ //设置等待时间;
Yellow = 1;
Red = 1;
Green = 0;
delay(200);NOP();WDTC();
Led_cr = 1;
NOP();NOP();
PORT7 |= 0X38;
delay(100);WDTC();
dip_seg3(user_time_minute);
}
}
}
WDTC();
if(set_state!=0)On_delay=0;
// if(wait_flag == 0)On_delay = 0;
/*执行大循环条件*/
if(skey_flag){
skey_flag=0;
break;
}
if(set_state == 0){
if(tcc_count >= 50){
tcc_count = 0;
if(wait_flag == 0){
second++;
if(second == 60){
second = 0;
L_minute--;
if(L_minute == 0){
if(H_minute == 0){
wait_flag = 1;
H_second = H_second_buf;
L_second = L_second_buf;
}else{
H_minute--;
L_minute = 250;
}
}
}
}else{
L_second--;
if(L_second == 0){
if(H_second == 0){
wait_flag = 0;
H_minute = H_minute_buf;
L_minute = L_minute_buf;
}else{
H_second--;
L_second = 250;
}
}
}
}
}
}
}
}
void _intcall INTTERRUPT(void) @ int
{
// Write your code (inline assembly or C) here
_asm{
MOV A, 0X10
MOV 0X3C, A
MOV A, 0X11
MOV 0X3B, A
MOV A, 0X12
MOV 0X3A, A
MOV A, 0X13
MOV 0X39, A
MOV A, 0X14
MOV 0X38, A
MOV A, 0X15
MOV 0X37, A
MOV A, 0X16
MOV 0X36, A
MOV A, 0X17
MOV 0X35, A
MOV A, 0X18
MOV 0X34, A
MOV A, 0X19
MOV 0X33, A
MOV A, 0X1a
MOV 0X32, A
}
TCC = 178;
_asm{
CLR 0x3f
}
skey_flag = 1;
tcc_count++;
//restore c systerm
_asm{
BS 0X04, 6
BS 0X04, 7
MOV A, 0X3C
MOV 0X10, A
MOV A, 0X3B
MOV 0X11, A
MOV A, 0X3A
MOV 0X12, A
MOV A, 0X39
MOV 0X13, A
MOV A, 0X38
MOV 0X14, A
MOV A, 0X37
MOV 0X15, A
MOV A, 0X36
MOV 0X16, A
MOV A, 0X35
MOV 0X17, A
MOV A, 0X34
MOV 0X18, A
MOV A, 0X33
MOV 0X19, A
MOV A, 0X32
MOV 0X1a, A
}
//restore ACC,R3,R4
_asm
{
reti
BS 0X4,6 //If switch to register page 3 in restore C system inline assembly,
BS 0X4,7 //in this inline assembly can neglect.
SWAPA 0X3E-1
MOV 0X3,A
SWAPA 0X3F-1
MOV 0X4,A
SWAP 0X1F
SWAPA 0X1F
}
}
void _intcall INTERRUPT_l(void) @ 0x1:low_int 0
{
//backup ACC,R3,R4
_asm
{
MOV 0X1F,A
SWAPA 0X4
BS 0X4,6
BS 0X4,7
MOV 0X3F-1,A
SWAPA 0X3
MOV 0X3E-1,A
BC 0X03,5
BC 0X03,6
}
} |