当前位置:网站首页>Construction of running water lamp experiment with simulation software proteus

Construction of running water lamp experiment with simulation software proteus

2022-06-12 07:10:00 luffy5459

    In fact, the water lamp in the development of single chip microcomputer uses the principle of diode light , Build a row of diodes , Turn on one diode in turn , In the middle, delay is used to achieve a transitional effect , cycle , This is the effect of running water lamp we see .

    Simulation software Proteus Build hardware projects in , choice 8051 Single chip microcomputer type , Finally, draw the circuit diagram as shown below :

    In the source code file main.c Write the following code in :

#include <reg51.h>
#include <stdio.h>
unsigned char leddata[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay()
{
  unsigned int i,j;
  for(i=1000;i>0;i--)
  {
    for(j=110;j>0;j--);
  }
}
void main(void)
 { 
    unsigned int i;
    for(i=0;i<8;i++)
    {
      P3 = leddata[i];
      delay();
    }
 }

    compile , structure . Finally, the simulation is carried out , The effect is as follows :

      The diode here is connected to P3 Pin 8 One pin , Here, the negative pole of the diode is uniformly grounded , To make them glow in turn , here P3 a row;Row 1 8 Pins must be input with high level in turn . When a pin is high , All other pins are low level . Therefore, each cycle is combined with delay lighting LED When , Need to give P3 assignment , here 8 The relationship between the lighting of the pins in turn is as follows :

0000 0001   -> 0x01
0000 0010   -> 0x02
0000 0100   -> 0x04
0000 1000   -> 0x08
0001 0000   -> 0x10
0010 0000   -> 0x20
0100 0000   -> 0x40
1000 0000   -> 0x80

      So in the code, we declare an array as follows :

unsigned char leddata[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

    Give... In turn P3 Pin assignment , You can light up a diode .

    This implementation uses arrays , In fact, every value of the array , All are 2 The power of , Based on this feature , You can also use a shift to give P3 Pin assignment , It's moving left 1<<1,1<<2,1<<3,1<<4,1<<5,1<<6,1<<7,1<<8, No more details here .

    Here's what's interesting , If the common end of the diode is connected to the power supply , Here, the design drawing needs to modify the direction of the diode , And the code needs to be modified , Every time you need to light up LED Low level , So here's right P3 Assignment needs to be negated :

P3 = ~leddata[i]

    proteus Design and code the water flow lamp , Let us once again feel the joy of SCM programming . Mainly used Proteus Simulation software design circuit , Check electrical rules , code , Simulation , A series of operations , Finally, I was really excited to see the results of the experiment , Very excited , This is so much fun .

原网站

版权声明
本文为[luffy5459]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010559328964.html