原创 17.99秒马表设计

2008-10-27 21:43 2282 3 3 分类: MCU/ 嵌入式

1.             实验任务<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


(1.       开始时,显示“00”,第1次按下SP1后就开始计时。


(2.       2次按SP1后,计时停止。


(3.       3次按SP1后,计时归零。


5.           汇编源程序


TCNTA            EQU 30H


TCNTB           EQU 31H


SEC       EQU 32H


KEYCNT          EQU 33H


SP1       BIT P3.5


        ORG 00H


        LJMP START


           ORG 0BH


        LJMP INT_T0


START:    MOV KEYCNT,#00H


        MOV SEC,#00H


        MOV A,SEC


        MOV B,#10


        DIV AB


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P0,A


        MOV A,B


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P2,A


        MOV TMOD,#02H


        SETB ET0


        SETB EA


WT:       JB SP1,WT


        LCALL DELY10MS


        JB SP1,WT


        INC KEYCNT


        MOV A,KEYCNT


        CJNE A,#01H,KN1


        SETB TR0


        MOV TH0,#06H


        MOV TL0,#06H


        MOV TCNTA,#00H


        MOV TCNTB,#00H


        LJMP DKN


KN1:      CJNE A,#02H,KN2


        CLR TR0


        LJMP DKN


KN2:      CJNE A,#03H,DKN


        MOV SEC,#00H


        MOV A,SEC


        MOV B,#10


           DIV AB


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P0,A


        MOV A,B


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P2,A


        MOV KEYCNT,#00H


DKN:    JNB SP1,$


        LJMP WT


DELY10MS:


           MOV R6,#20


D1:        MOV R7,#248


        DJNZ R7,$


        DJNZ R6,D1


        RET


INT_T0:


        INC TCNTA


        MOV A,TCNTA


        CJNE A,#100,NEXT


        MOV TCNTA,#00H


        INC TCNTB


        MOV A,TCNTB


        CJNE A,#4,NEXT


        MOV TCNTB,#00H


        INC SEC


        MOV A,SEC


        CJNE A,#100,DONE


        MOV SEC,#00H


DONE:             MOV A,SEC


        MOV B,#10


        DIV AB


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P0,A


        MOV A,B


        MOV DPTR,#TABLE


        MOVC A,@A+DPTR


        MOV P2,A


NEXT:   RETI


TABLE:  DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH


        END


6.           C语言源程序


#include <AT89X51.H>


 


unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,


                               0x66,0x6d,0x7d,0x07,


                               0x7f,0x6f,0x77,0x7c,


                               0x39,0x5e,0x79,0x71,0x00};


unsigned char second;


unsigned char keycnt;


unsigned int tcnt;


 


void main(void)


{


  unsigned char i,j;


 


  TMOD=0x02;


  ET0=1;


  EA=1;


  second=0;


  P0=dispcode[second/10];


  P2=dispcode[second%10];


  while(1)


    {


      if(P3_5==0)


        {


          for(i=20;i>0;i--)


          for(j=248;j>0;j--);


          if(P3_5==0)


            {


              keycnt++;


              switch(keycnt)


                {


                  case 1:


                    TH0=0x06;


                    TL0=0x06;


                    TR0=1;


                    break;


                  case 2:


                    TR0=0;


                    break;


                  case 3:


                    keycnt=0;


                    second=0;


                    P0=dispcode[second/10];


                    P2=dispcode[second%10];


                    break;


                }


              while(P3_5==0);


            }


        }


    }


}


 


void t0(void) interrupt 1 using 0


{


  tcnt++;


  if(tcnt==4000)


    {


      tcnt=0;


      second++;


      if(second==100)


        {


          second=0;


        }


      P0=dispcode[second/10];


      P2=dispcode[second%10];


    }


}


 

点击看大图


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条