闪烁灯

来源:互联网 发布:国外病理软件 编辑:程序博客网 时间:2024/04/28 05:19

程序:

#include<reg52.h>
 
sbitP1_0=P1^0;                  //定义IO口
voiddelay02s(void)              //延时0.2秒子程序
        {
          unsigned char i,j,k;  //定义3个无符号字符型数据。
          for(i=20;i>0;i--)    //作循环延时
          for(j=20;j>0;j--)
          for(k=248;k>0;k--);
         }
  voidmain(void)  //每一个C语言程序有且只有一个主函数,
  {
  
  while(1)  //循环条件永远为真,以下程序一直执行下去。
    {
    P1_0=0;    // I/O口P1.0输出低电平,小灯被点亮。
    delay02s();  //延时经过0.2秒。
    P1_0=1;    // I/O口P1.0输出高电平,小灯熄灭。
    delay02s();  //延时经过0.2秒。
    }
  }

闪烁灯闪烁灯

以上的一段代码没什么好说的,关于延时方面的参考网址(http://blog.21ic.com/user1/322/archives/2005/4428.html)板上的8个小的流水灯旁接了一个74HC753锁存器,发光二极管为共阳极,所以给低电平点亮,锁存器的原理当时并不是很懂,但是现在学了数电了,并不难理解。

These octal transparentD-type latches feature3-state outputs designed specifically fordrive in highly capacitive or relatively low-impedance
loads. They are particularly suitable for
implementing buffer registers, I/O ports,
bidirectional bus drivers, and working registers.
While the latch-enable (LE) input is high, the
Q outputs respond to the data (D) inputs. When
LE is low, the outputs are latched to retain the data
that was set up.
A buffered output-enable (OE) input can be used
to place the eight outputs in either a normal logic
state (high or low logic levels) or the
high-impedance state. In the high-impedance
state, the outputs neither load nor drive the bus
lines significantly. The high-impedance state and
increased drive provide the capability to drive bus
lines without interface or pullup components.
OE does not affect the internal operations of the latches. Old datacan be retained or new data can be entered
while the outputs are in the high-impedancestate.

 

FUNCTION TABLE
(each latch)
INPUTS OUTPUT
OE LE D Q
H H
L
 Q0
Z


0 0
原创粉丝点击