定义:
#define Yellow R75
#define Green R74
#define Red R73
/**全局变量**/
uchar tcc_count = 0; //计时到50次,为1秒;
uchar second = 0; //秒初始值;
uchar set_state = 0; //系统状态标致;
ushort key_time = 0;
uchar key_num = 0; //键盘扫描次数;
ushort user_time_second = 1; //调节,用户自己设定的时间;键盘设定的值;
ushort user_time_minute = 1; //用户自己设定的加油等待时间;
uchar H_second_buf = 0;
uchar L_second_buf = 1;
uchar H_minute_buf = 0;
uchar L_minute_buf = 1;
uchar H_second = 0; //超过256时的用户设置的秒user_time的高位;
uchar L_second = 1;
uchar H_minute = 0; //超过256时的用户设置的分user_time的高位;
uchar L_minute = 1;
//百位,十位,个位;
uchar dis_num[3] = {0,0,1}; //初始化显示程序;显示存储器;
ushort dis_buf = 1; //显示缓冲数据;
/**位定义**/
bit skey_flag = 0; //20MS键盘扫描标致位;
bit wait_flag = 0; //等待时间;加油标致位"1时";
//bit aotu_flag = 0; //手动加油标致位;
/***常量定义***/
const uchar seg_duan[13] = {
//0 1 2 3 4 5 6 7 8 9 //0x40"-",0xff"open",0x00"close"
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff,0x00
};
const uchar seg_wei[3] = {
//seg1,seg2,seg3;
0x10,0x20,0x40
};
const uchar duan_bit[7] = {
//R71,R67,R73, R74, R75, R70, R72;
0x01,0x02,0x04,0x08,0x10,0x20,0x40
};
________________________________________________
显示;
void delay(uchar de)
{
for(;de>0;de--){NOP();}
}
/**************************************************
* display
*
*R70~R75,R67 ARE duan out;R64,R65,R66 ARE wei out;
*
*
**************************************************/
void display(uchar wei,uchar duan) //写SEG段;write wei;
{
uchar j;
//write duan;
NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();
P7CR &= 0XC0;
P6CR &= 0X07;
NOP();NOP();NOP();NOP();
P6CR |= 0X04;
NOP();NOP();NOP();NOP();
PORT6&= 0X8F;
NOP();NOP();
NOP();NOP();NOP();NOP();
Led_cr=1;
NOP();NOP();
NOP();NOP();NOP();NOP();
if(duan & duan_bit[0])R71 = 1;
else R71 = 0;
if(duan & duan_bit[1])R67 = 1;
else R67 = 0;
if(duan & duan_bit[2])R73 = 1;
else R73 = 0;
if(duan & duan_bit[3])R74 = 1;
else R74 = 0;
if(duan & duan_bit[4])R75 = 1;
else R75 = 0;
if(duan & duan_bit[5])R70 = 1;
else R70 = 0;
if(duan & duan_bit[6])R72 = 1;
else R72 = 0;
//write wei;
NOP();NOP();
NOP();NOP();NOP();NOP();
PORT6 |= wei;
WDTC();NOP();
for(j=100;j>0;j--){NOP();}
NOP();
WDTC();
for(j=100;j>0;j--){NOP();}
NOP();NOP();WDTC();
PORT6 &= 0X0F;
PORT7 &= 0XC0;
NOP();NOP();
for(j=100;j>0;j--){NOP();}
NOP();WDTC();
}
void dip_seg3(ushort num)
{
uchar i = 0;
dis_num[0] = (uchar)(num/100);
if(dis_num[0] == 0)dis_num[0] = 12;
dis_num[1] = (uchar)(num%100/10);
if(dis_num[0] == 12)
if(dis_num[1] == 0)dis_num[1] = 12;
dis_num[2] = (uchar)(num%10);
if(dis_num[0] == 12)
if(dis_num[1] == 12)
if(dis_num[2] == 0)dis_num[2] = 12;
WDTC();
for(i=0;i<3;i++){
display(seg_wei[i],~seg_duan[dis_num[i]]);
WDTC();
}
}
显示程序;
---------------------------------------------------------
void _intcall INTTERRUPT(void) @ int 0
{
// Write your code (inline assembly or C) here
TCC = 178;
_asm{
BC 0x4,7
BC 0x4,6
CLR 0x3f
}
DISI();
skey_flag = 1;
tcc_count++;
if(wait_flag == 0){
if(tcc_count == 50){
tcc_count = 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{
if(tcc_count == 50){
tcc_count = 0;
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;
}
}
}
}
//restore ACC,R3,R4
_asm
{
reti //tell Compiler to recover common registers here
BS 0X4,6 //If switch to register page 3 in restore C system inline assembly,
BS 0X4,7 //in this inline assembly can neglect.
MOV A, 0X3C //使用2字节C类型数据,C系统恢复
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 //使用2字节C类型数据,C系统恢复
MOV 0X16, A
MOV A, 0X35
MOV 0X17, A
MOV A, 0X34
MOV 0X18, A
MOV A, 0X33
MOV 0X19, A
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
MOV A, 0X10 //使用1字节C数据类型,C系统备份
MOV 0X3C, A //将0x10~0x19保存到bank 3的0x3C,0X3B, 0X3A,
MOV A, 0X11 //0X39, 0X38, 0X37,因为在intcall INTERRUPT1_l
MOV 0X3B, A //子程式里已将ram切换到了bank 3
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 //使用2字节C数据类型,C系统备份
MOV 0X36, A //将0x10~0x19保存到bank 3的0x3C,0X3B, 0X3A,
MOV A, 0X17 //0X39, 0X38, 0X37,因为在intcall INTERRUPT1_l
MOV 0X35, A //子程式里已将ram切换到了bank 3
MOV A, 0X18
MOV 0X34, A
MOV A, 0X19
MOV 0X33, A
BC 0X03,5
BC 0X03,6
}
}
中断程序,递减计数; |