#include
#define DISPLAYPortH P2 //定义数据端口
#define DISPLAYPortL P0 //定义数据端口
sbit OutPutPin = P2^7;
sbit KeyPin = P3^7;
// 显示段码值01234567
unsigned char code ShuZhi[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //对应bit位为0则点亮,最高bit对应小数点
unsigned char pinstatus;
unsigned char timecount1,timecount2;
unsigned char temp;
void Display(unsigned char port,unsigned char num); //函数声明
/*------------------------------------------------
主函数
------------------------------------------------*/
main()
{
timecount1 = 0;
timecount2 = 0;
TMOD = 1;
TH0 = 0x3C;
TL0 = 0xB0;
ET0 = 1;
EA = 1;
TR0 = 1;
OutPutPin = 0;
pinstatus = 0;
while(1);
}
void Display(unsigned char port,unsigned char num)
{
unsigned char numcode;
numcode = ShuZhi[num];
if(port ==0)
{
if(pinstatus)
{
numcode|=0x80;
}
else
{
numcode&=0x7f;
}
DISPLAYPortH = numcode;
}
else
{
DISPLAYPortL = numcode;
}
return;
}
void T0INTERRUPT(void) interrupt 1
{
TH0 = 0x3C;
TL0 = 0xB0;
timecount1++;
if(KeyPin== 0)
{
timecount1 = 0;
timecount2 = 0;
OutPutPin = 0;
pinstatus = 0;
}
if(timecount1>=20)
{
timecount1=0;
timecount2++;
}
switch(timecount2)
{
case 10:
OutPutPin = 1;
pinstatus = 1;
break;
case 13:
OutPutPin = 0;
pinstatus = 0;
timecount2 = 0;
default:break;
}
if(timecount1 == 0)
{
if(timecount2<10)
{
temp = 10-timecount2;
Display(0,temp/10);
temp = 10-timecount2;
Display(1,temp%10);
}
if((timecount2>=10)&&(timecount2<13))
{
Display(0,0);
Display(1,13-timecount2);
}
}
}
p2口接数码管,...,p2口的28引脚输出维持10s的0电平
------------
P2口,还是两用的呀?
不能换一个接口吗?
赞 1 楼!
建议 去 我的领地 5d6d 的 proteus 论坛看看
那里有很多 单片机仿真实例,包括仿真图 和 源码
搜 5d6d 和 proteus 2个关键词
LED1 EQU P0
LED2 EQU P2
OUTP BIT P2.7
COUNT EQU 30H
CNT0 EQU 31H
CNT EQU 32H
DISL EQU 33H
DISH EQU 34H
TEND BIT 00H ;计时到标志
SBIT BIT 01H ;1S到标志
ORG 0000H
SJMP STA
ORG 000BH
LJMP TIM0
ORG 0050H
STA:
MOV SP,#6FH
MOV TMOD,#01H
MOV TH0,#3CH ;50ms
MOV TL0,#0B0H
SETB ET0
CLR TEND
MOV DISL,#0
MOV DISH,#0
MOV COUNT,#0
MOV CNT,#200 ;10S
CLR OUTP
CLR SBIT
SETB EA
SETB TR0
LOOP1:
JBC,SBIT,STA00
JNB TEND,LOOP1
CLR TEND
SJMP STA01
STA00:
LCALL DISPLAY
SJMP LOOP1
STA01:
MOV CNT,#60 ;3S
CLR OUTP
SETB OUTP
LOOP2:
JNB TEND,LOOP2
CPL OUTP
CLR TEND
SJMP LOOP2
;
TIM0:
PUSH ACC
PUSH PSW
INC COUNT
INC TCNT0
MOV A,CNT0
CJNE A,CNT,TIM01
SETB TEND
MOV CTN0,#0
TIM01:
MOV B,#20
DIV AB
MOV A,B
JNZ TIM0E
SETB SBIT
TIM01E:
POP PSW
POP ACC
RETI
DISPLAY:
MOV A,COUNT
MOV B,#10
DIV AB
MOV DISH,A
MOV DISL,B
MOV DPTR,#LEDTAB
MOV A,DISL
MOVC A,@A+DPTR
MOV P0,A
MOV A,DISH
MOVC A,@A+DPTR
ANL A,#7FH
MOV B,A
MOV A,P2
ORL A,B
MOV P2.A
RET
LEDTAB:
DB 0C0H ;"0" 00H
DB 0F9H ;"1" 01H
DB 0A4H ;"2" 02H
DB 0B0H ;"3" 03H
DB 99H ;"4" 04H
DB 92H ;"5" 05H
DB 82H ;"6" 06H
DB 0F8H ;"7" 07H
DB 80H ;"8" 08H
DB 90H ;"9" 09H
;
END