2021
Running Light

Running Light (M242)

Translated from German using DeepL.
Contains some German code sections and pictures.

Date: June 2021
Reading time: 5 minutes


Introduction

This document lists the contents of the project work by C. Damas, M. Müggler and K. Wild.

Notes

The source code is designed for the wedge simulator. In order for it to work properly on the Mesa device to work properly on the Mesa device, it must be adapted. The affected areas are marked in the code with the comment "CHANGE".

Block diagram

Basic requirements

block-extended

Extended requirements

State diagram

Basic requirements

state-diagram

Extended requirements

state-diagram-extended

Flowchart

flowchart

Structure diagram

Program code

program-code

General

structure

Principle sketch

principle-sketch

Testing

Test concept

We test the running light, which runs on MESA. To do this, we connect the board using the Silicon Laboratories USB debug adapter. We then pay close attention to how the LEDs move. Especially after pressing the various buttons, we check whether everything is working properly.

Test cases

| No. | Test case | Responsibility | Expectation | Result | Next steps | Priority | | --- | ----------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---- | | 1 | Press Keil Software | Kay | Chaser moves from left to right. It shifts every second. Once the chain has run through, the whole process starts again from the beginning. This means that the program does not stop. | The program does not stop. | | 2 | Press S0 while the LEDs are running | Kay | The LEDs stop. This means that the running light is paused. | The program does | - | must | | 3 | | Press S0 when the LEDs are stopped | Kay | The chaser continues to run where it was paused. If the chaser was previously stopped, it starts again. | When stopping, you must first press the stop button again. Then you can start it normally. Since there is no other way, we accept this. | - | must | | 4 | Press S1 | Kay | The process is stopped when this button is pressed. In contrast to pausing, no LED lights up here. The running light is therefore canceled. | The process must be stopped. | | 5 | Pressing S2 at slow speed | Kay | If the lights move slowly, the speed is increased using the S2 button. The running light therefore moves faster. Pressing it again resets the speed. | works | - | can | | 7 | Press S3 when moving to the left | Kay | The direction of movement is reversed. The running light moves from left to right. When the button is pressed again, the LEDs move from right to left again. | works | - | can | | 9 | Press S4 | Kay | The number of LEDs in the light chain increases. To have fewer lights in the chain again, simply press again. | works | - | can |

Operating instructions

Functions

If the wedge is connected to the software, a running light should already be visible. Otherwise, you must contact a developer. The running light is changed as follows.

Pause - S0

To pause the light, click once on the S0 button. This stops all LEDs.

Start - S0

Once the LEDs have been paused or stopped, you can restart the movement of the lights with lights can be restarted/resumed with S0.

Stop - S1

LEDs dark. The lights are interrupted with the S1 button. After clicking on this button, all

Speed - S2

S2 is available to adjust the speed. If the speed is slow (standard) speed, this can be increased with the button. All you have to do is keep the button pressed.

Running direction - S3

The S3 button is used to change the direction of the LEDs. If the button is pressed, the the light chain runs in the opposite direction. This continues until the button is button is released again.

Width - S4

The width of the moving lights can also be changed. To do this, press and hold S4 is pressed. This increases the size of the light chain.

Overview of the buttons

keys

Code

;********************************************************************************
; P R O G R A M M
;********************************************************************************
; Source-File:      	Lauflicht.a51
; Autor:            	C. Damas, M. Müggler, K. Wild
; Datum:            	05.06.2021
; Version:            	2.0
; Beschreibung:        	Lauflicht
; Eingaben:            	8 Schalter S0 bis S7
; Ausgaben:            	8 LEDs PA0 bis PA7
; HINWEIS				Alle Änderungen die noch für das Mesa gemacht werden
;						müssen, sind mit dem Keywort "ÄNDERN" gekennzeichnet
;********************************************************************************

$TITLE (Lauflicht)
$NOLIST
$NOMOD51
$INCLUDE (C8051F020.h)                		            ;hier werden alle Bezeichnungen definiert
$LIST

NAME Lauflicht

;----- Deklarationen
input       equ     P3                    	            ; P3 8 Eingänge
output      equ     P2                   	            ; P2 8 Ausgänge
llStatus	data	20h						            ; ll -> LaufLichtStatus
dStatus		data	21h						            ; DirectionStatus -> bool-Variable die sagt, ob als letztes das Licht Vor- oder rückwärts gegangen ist
fast		data	22h						            ; deklariert geschwindigkeit -> bool-Variable die entweder schnell oder langsam ist

;----- Intitialisierung
            ORG     0000h                	            ; Startadresse
            jmp     init                                ; geht zu init

            ORG     0100h                	            ; Programmanfang
init:  	    mov     WDTCN,#0DEh
            mov     WDTCN,#0ADh            	            ; deaktiviert Watchdog
       	    mov     P2MDOUT,#0FFh        	            ; P2 8 Ausgänge
            mov     P3MDOUT,#000h        	            ; P3 8 Eingänge
            mov     XBR2,#040h            	            ; aktiviert crossbar (Koppelfeld)

;------ Hauptprogramm
main:       mov     output,#00h            	            ; LEDs ausschalten
		    mov     input, #00h							; ÄNDERN --> wenn man es auf dem Mesa laufen lässt muss man diese Zeile entfernen
		    mov     A,#0h

;------ Schleife
loop:
            jnb		input.2, fastFalse
		    mov		fast, #6h					        ; ÄNDERN --> Wert für Wait anpassen wenn schnell -> beim Mesa #6h mit #1h ersetzen
		    jmp		fastEnd

fastFalse:
		    mov     fast, #60h;	 					    ; ÄNDERN --> Wert für Wait anpassen wenn langsam (standard-geschwindigkeit) -> beim Mesa #60h mit #6h ersetzen

fastEnd:

            jb      input.3, CBitBack ;Endlosschleife
		    jmp		CBit

;------ Licht anschalten vorwärts
lightsUp:
		    CALL 	compare
		    jnb		input.4, lightsUpTrue
		    rl		A
		    add 	A, #1h

;------ Licht anschalten vorwärts breit
lightsUpTrue:
		    rl		A
		    add 	A, #1h
		    mov		output, A
		    CALL 	wait
		    jmp		loop

;------ Licht ausschalten vorwärts
lightsDown:
		    CALL 	compare
		    jnb		input.4, lightsDownTrue
		    rl		A
		    subb 	A, #1h

;------ Licht ausschalten vorwärts breit
lightsDownTrue:
		    rl		A
		    subb 	A, #1h
		    mov		output, A
		    CALL 	wait
		    jmp		loop

;------ Licht anschalten rückwärts
lightsUpBack:
		    CALL 	compare
		    jnb		input.4, lightsUpBackTrue
		    add 	A, #1h
		    rr		A

;------ Licht anschalten rückwärts breit
lightsUpBackTrue:
		    add 	A, #1h
		    rr		A
		    mov		output, A
		    CALL 	wait
		    jmp		loop

;------ Licht ausschalten rückwärts
lightsDownBack:
		    CALL 	compare
		    jnb		input.4, lightsDownBackTrue
		    subb 	A, #1h
		    rr		A

;------ Licht ausschalten rückwärts breit
lightsDownBackTrue:
		    subb 	A, #1h
		    rr		A
		    mov		output, A
		    CALL 	wait
		    jmp		loop

;----- überprüft ob stop oder pasue gedrückt wurde
compare:
            JB      input.0, compare
            JB      input.1, reset
            RET

;----- überprüft Richtung und wenn Schalter gedrückt geht zu CBitTrue (Wenn vorwärts)
CBit:
            jb		dStatus.0, CBitTrue
		    mov 	A, #0h
		    mov		dStatus, #1h

;----- Setzt neue Richtung (wenn vorwärts)
CBitTrue:
		    mov		llStatus, A
		    jb		llStatus.7, lightsDown
		    jmp 	lightsUp

;----- überprüft Richtung und wenn Schalter gedrückt geht zu CBitBackTrue (Wenn rückwärts)
CBitBack:
            jnb     dStatus.0, CBitBackTrue
			mov 	A, #0h
			mov		dStatus, #0h

;----- Setzt neue Richtung (wenn rückwärts)
CBitBackTrue:
			mov     llStatus, A
			jb      llStatus.0, lightsDownBack
			jmp	    lightsUpBack

;----- Start Delay
wait:       mov     R5, #0FFh		                    ; mit wait wird der Delay aufgerufen, und hier wird auf das Register verschiedene Werte gesetzt und Schleifen ineinander aufgerufen
wait1:      mov     R6, #0FFh
wait2:      mov     R7, #05h
wait3:	    mov     R4, fast			                ; ÄNDERN --> bei Mesa wait 4 wieder entfernen und "mov R4, fast" beim wait 3
wait4:      djnz    R4, wait4
		    djnz    R7, wait3
            djnz    R6, wait2
            djnz    R5, wait1
            ret

;----- Start Reset (Stop)
reset:      mov     output,#00h                         ; setzt die LEDs und den Akumulator zurück und geht wider in die Loop
		    mov	    A, #0h
		    jmp     loop
            END

Sources

All diagrams, test cases, texts and other graphics were designed by our group.