原创 5.广告灯(利用取表方式)

2008-10-18 10:40 2319 3 3 分类: MCU/ 嵌入式

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


利用取表的方法,使端口P1做单一灯的变化:左移,右移


2.      电路原理图


    同实验四原理图


3、实现程序


1.      汇编源程序


                            ORG 0000H


START:               MOV DPTR,#TABLE


<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />LOOP:                CLR A


                            MOVC A,@A+DPTR


                            CJNE A,#01H,LOOP1


                            JMP START


LOOP1:              MOV P1,A


                           MOV R3,#20


                            LCALL DELAY


                            INC DPTR


                           JMP LOOP


DELAY:              MOV R4,#20


D1:                     MOV R5,#248


                            DJNZ R5,$


                            DJNZ R4,D1


                           DJNZ R3,DELAY


                            RET


TABLE:              DB 0FEH,0FDH,0FBH,0F7H


                            DB 0EFH,0DFH,0BFH,07FH


                           DB 07FH,0BFH,0DFH,0EFH


                          DB 0F7H,0FBH,0FDH,0FEH


                          DB 01H


                            END


2.      C语言源程序


#include <AT89X51.H>


unsigned char code table[]={0xfe,0xfd,0xfb,0xf7,   0xef,0xdf,0xbf,0x7f,


                                               0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x01};


unsigned char i;


 


void delay(void)


{


  unsigned char m,n,s;


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


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


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


}


 


void main(void)


{


  while(1)


    {


      if(table!=0x01)


        {


          P1=table;


          i++;


          delay();


        }


        else


          {


            i=0;


          }


    }


}


点击开大图

4、总结


      使用查表程序实现相对左右移位更加简单容易理解


      对IO高电平点亮LED只需要修改table表中的十六机制数字即可,需要将停止位修改为0xff


unsigned char code table[]=    {0x01,0x02,0x04, 0x08,0x10,0x20,0x40, 0x80                                                                                0x80,0x40,0xdf,0x20,0x10,0x08,0x04,0x02,0x01,0xff};


 


<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /> 

PARTNER CONTENT

文章评论0条评论)

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