WOSEN LIGHTING TECHNOLOGY LIMITED

WOSEN LIGHTING TECHNOLOGY LIMITED

Dom> Blog> Single-chip controlled LED street light design (circuit, program)

Single-chip controlled LED street light design (circuit, program)

April 29, 2023

1. Hardware composition According to the expansion of single-chip system and system configuration, single-chip application system can be divided into minimum system, minimum power consumption system and typical system. AT89C51 single-chip microcomputer is a low-voltage, high-performance CMOS 8-bit single-chip microcomputer produced by American ATMEL Company. It has abundant internal resources: 4kB flash memory, 128BRAM, 32 I/O lines, two 16-bit timer/counters, and five vector levels. The interrupt structure and two full-duplex serial ports have a voltage operating range of 4.25 to 5.50V and a working frequency of 0 to 24 MHz. When using the AT89C51 microcontroller, there is no need to expand the memory. Therefore, the current water lamp is actually a minimum application system of a single-chip microcomputer with eight light-emitting diodes, that is, a single-chip microcomputer composed of a circuit such as a light-emitting diode, a crystal oscillator, a reset, a power supply, and the necessary software. Its specific hardware composition is shown in Figure 1.



As can be seen from the schematic diagram, if the LED1 connected to the P1.0 port is to be lit, then the level of the P1.0 port can be changed to a low level; on the contrary, if it is to be connected to the P1.0. When the LED1 of the port is turned off, it is necessary to change the level of the P1.0 port to a high level; similarly, the other 7 LEDs connected to the P1.1 to P1.7 ports are lit and extinguished in the same manner as the LED1. Therefore, in order to realize the function of the water light, we only need to turn on and off the LEDs LED1~LED8 in sequence, and the 8 LED lights will be light and dark. Here we should also note that due to the visual persistence effect of the human eye and the short time that the MCU executes each instruction, we should delay the control diode for a period of time, otherwise we will not see the "flowing water". The effect is.


2 software programming


The application system of the single-chip microcomputer is composed of hardware and software. After the above-mentioned hardware schematic diagram is completed and built, we can't see the phenomenon that the running light is cycled. We also need to tell the microcontroller how to work, that is, write the program to control the single-chip pin. The level of the level changes to achieve the light-emitting diodes. Software programming is an important part of the application system of single-chip microcomputer, which is the key point and difficulty of learning single-chip microcomputer. Below we use the simplest flow light control function to realize the cycle lighting of 8 LED lights, to introduce several software programming methods to realize the flow light control. [Attachment: C Program]


2.1 position control method


This is a relatively stupid but most understandable method. It uses a sequential program structure to control the output of each bit of the P1 port with a bit instruction to control the on and off of the corresponding LED. The procedure is as follows:
ORG 0000H; execution from 0000H address after power-on
AJMP START ; jump to the main program storage address
ORG 0030H ; set the main program start address
START:MOV SP,#60H ;Set the stack start address to 60H
CLR P1.0 ; p1.0 output low level, LED1 is lit
ACALL DELAY ; call delay subroutine
SETB P1.0 ; p1.0 output high level, make LED1 off
CLR P1.1 ; p1.1 output low level, make LED2 light
ACALL DELAY ; call delay subroutine
SETB P1.1 ; p1.1 output high level, make LED2 off
CLR P1.2 ; p1.2 output low level, make LED3 light
ACALL DELAY ; call delay subroutine
SETB P1.2 ; p1.2 output high level, make LED3 off
CLR P1.3; p1.3 output low level, LED4 lights up
ACALL DELAY ; call delay subroutine
SETB P1.3; p1.3 output high level, make LED4 go out
CLR P1.4 ; p1.4 output low level, make LED5 light
ACALL DELAY ; call delay subroutine
SETB P1.4 ; p1.4 output high level, make LED5 off
CLR P1.5; p1.5 output low level, LED6 lights up
ACALL DELAY ; call delay subroutine
SETB P1.5 ; p1.5 output high level, make LED6 off
CLR P1.6 ; p1.6 output low level, LED7 lights up
ACALL DELAY ; call delay subroutine
SETB P1.6 ; p1.6 output high level, make LED7 off
CLR P1.7 ; p1.7 output low level, LED8 lights up
ACALL DELAY ; call delay subroutine
SETB P1.7 ; p1.7 output high level, make LED8 go out
ACALL DELAY ; call delay subroutine
AJMP START; 8 LEDs flow back and return to the label START for recycling
DELAY: ; delay subroutine
MOV R0, #255; delay for a while
D1: MOV R1, #255
DJNZ R1, $
DJNZ R0, D1
RET ; subroutine return
END; the program ends


2.2 cyclic shift method


In the previous program, we implemented each bit of the P1 port one by one, so the program is a bit complicated. Below we use the cyclic shift instruction to program using the cyclic program structure. We send a number to the P1 port at the beginning of the program. This number itself makes P1.0 low first, the other bits high, then delay for a period of time, then let the data move to the high position, and then output to the P1 port. This will achieve the "flowing" effect. Since the instructions of the 8051 series MCU only have the instruction to shift the data to the left or right of the accumulator ACC, in actual programming, we should put the data to be moved into the ACC first, let it move, and then move the data after the ACC. Then transfer to the P1 port, which can also achieve the "flowing water" effect. The specific programming is as follows, the program structure is really a lot simpler.
ORG 0000H; execution from 0000H address after power-on
AJMP START ; jump to the main program storage address
ORG 0030H ; set the main program start address
START:MOV SP,#60H ;Set the stack start address to 60H
MOV A, #0FEH ; ACC first loads LED1 bright data (binary 11111110)
MOV P1, A ; send ACC data to P1 port
MOV R0, #7 ; move the data 7 more times to complete an 8-bit flow process
LOOP: RL A ; shift the data in the ACC to the left by one bit
MOV P1, A ; send data sent by ACC to p1 port display
ACALL DELAY ; call delay subroutine
DJNZ R0, LOOP; no movement enough to move 7 times
AJMP START; after 7 moves, jump to start to return to achieve circular flow effect
DELAY: ; delay subroutine
MOV R0, #255; delay for a while
D1: MOV R1, #255
DJNZ R1, $
DJNZ R0, D1
RET ; subroutine return
END; the program ends


2.3 lookup table method


The above two programs are relatively simple flow light programs, and the "flowing water" pattern can only achieve a single "left to right" flow mode. The flow light program written by the look-up table method can realize the flow of water in any way, and the flow pattern is infinite. As long as the flow data of the flow pattern data table is changed, the flow pattern can be added or changed at will, and the desired flow light effect can be realized. We first set the data to display the flow pattern in a TAB-labeled data table, then take the data to the accumulator A by looking up the table instruction "MOVC A, @A+DPTR", and then send it to the P1 port. display. The specific source program is as follows, and the data table at the TAB label can be arbitrarily modified according to the requirements of the implementation effect.
ORG 0000H; execution from 0000H address after power-on
AJMP START ; jump to the main program storage address
ORG 0030H ; set the main program start address
START:MOV SP,#60H ;Set the stack start address to 60H
MOV DPTR, # TAB ; flow pattern table first address to send DPTR
LOOP: CLR A ; accumulator clear
MOVC A, @A+DPTR ; take the value in the data table
CJNE A, #0FFH, SHOW; check the end of flow sign
AJMP START ; all patterns are finished, then repeat the flow from the beginning
SHOW: MOV P1, A ; send data to port P1
ACALL DELAY ; call delay subroutine
INC DPTR ; point the data table pointer to the next data
AJMP LOOP; continue to look up the data
DELAY: ; delay subroutine
MOV R0, #255; delay for a while
D1: MOV R1, #255
DJNZ R1, $
DJNZ R0, D1
RET ; subroutine return
TAB: ; The following is a flow pattern data table, the user can write it as required
DB 11111110B ; binary representation of the pipeline pattern data, moving from low to high left
DB 11111101B
DB 11111011B
DB 11110111B
DB 11101111B
DB 11011111B
DB 10111111B
DB 01111111B
DB 01111111B ; binary representation of the flow pattern data, moving from high to low right
DB 10111111B
DB 11011111B
DB 11101111B
DB 11110111B
DB 11111011B
DB 11111101B
DB 11111110B
DB 0FEH, 0FDH, 0FBH, 0F7H; pipe pattern data expressed in hexadecimal
DB 0EFH, 0DFH, 0BFH, 7FH
DB 7FH, 0BFH, 0DFH, 0EFH
DB 0F7H, 0FBH, 0FDH, 0FEH
......
DB 0FFH ; flow pattern end mark 0FFH
END; the program ends
3. Conclusion After one of the above programs is written, we need to compile it with the compiler software, get the binary code that the MCU can recognize, and then use the programmer to burn the binary code to the AT89C51 MCU, and finally connect the circuit to power. We will see the "flowing" effect of LED1~LED8. The functions implemented in this article are relatively simple, and are designed to be used to expand the more complex flow lights control, such as keyboard control flow patterns, control flow lights to display numbers or patterns, and so on.


The above content is provided by WOSEN. WOSEN is a professional manufacturer and supplier of Led Flood Light, Led Street Light, Led Solar Light, etc. For more information, please visit https://www.wosenled.com/ or contact admin@wosenled.com or WhatsApp +86-13425434349

Skontaktuj się z nami

Author:

Ms. Mandy

Phone/WhatsApp:

+8613425434349

Wszystkie produkty
You may also like
Related Categories

Wyślij je do tym dostawcy

Przedmiot:
Email:
wiadomość:

Your message must be betwwen 20-8000 characters

  • Wyślij zapytanie

Copyright © 2024 WOSEN LIGHTING TECHNOLOGY LIMITED All rights reserved.

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

Wysłać