One of the SITCOM training computer prototypes
 SITCOM 85 Training Computer
 
 

Let's roll

Now we are going to try to make a LED walk across the total 16 LEDs only when push button 0 is pressed.

 
   

;------------------------------------------------------------------------
;
; LESSON5C.ASM
;
; Shift LED one position to the left if push button 0 is pressed
;
;------------------------------------------------------------------------

            .IN   INIT02           Initialize the assembler

;------------------------------------------------------------------------

            LXI   D,1111111111111110B   Initialize shift register
            MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA

LOOP        IN    PORTC            Get the push buttons
            ANI   00000001B        Is push button 0 pressed?
            JNZ   LOOP             No it is not!

            STC                    Shift LED one position to the left
            MOV   A,E
            RAL
            MOV   E,A
            MOV   A,D
            RAL
            MOV   D,A
            JC    OUTPUT           No need to reload!
            LXI   D,1111111111111110B   Reload shift register

OUTPUT      MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA
            JMP   LOOP             Repeat endlessly
 
 

There is a big problem with this program. The shifting itself works, but the program keeps shifting as long as we hold the key. We intended to shift the LED one position each time the key is pressed.
It is tempting to add a for instance a 1 second delay, which remedy the problem partially. But that is not the proper way to do it, for it would prohibit us from pressing the button quickly in succession. We have to find stall program operation after shifting until the key is released again.

 
   

;------------------------------------------------------------------------
;
; LESSON5D.ASM
;
; Shift LED one position to the left if push button 0 is pressed
;
;------------------------------------------------------------------------

            .IN   INIT02           Initialize the assembler

;------------------------------------------------------------------------

            LXI   D,1111111111111110B   Initialize shift register
            MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA

LOOP        IN    PORTC            Get the push buttons
            ANI   00000001B        Is push button 0 pressed?
            JNZ   LOOP             No it is not!

            STC                    Shift LED one position to the left
            MOV   A,E
            RAL
            MOV   E,A
            MOV   A,D
            RAL
            MOV   D,A
            JC    OUTPUT           No need to reload!
            LXI   D,1111111111111110B   Reload shift register

OUTPUT      MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA

WAIT        IN    PORTC            Get push button status again
            ANI   00000001B        Is push button 0 still down?
            JZ    WAIT             It is! Wait until it's released

            JMP   LOOP             Repeat endlessly
 
 

This program works a bit better, but it is not good enough. With my push buttons I get reasonable results, only if I press or release the key slowly I get some bounces and the LED is advanced more than one step at a time. Maybe your push buttons give better bouncing.
Explain why the LED advances more than one LED at a time occasionally due to bouncing.

 
   

;------------------------------------------------------------------------
;
; LESSON5E.ASM
;
; Shift LED one position to the left if push button 0 is pressed
;
;------------------------------------------------------------------------

            .IN   INIT02           Initialize the assembler

;------------------------------------------------------------------------

            LXI   D,1111111111111110B   Initialize shift register
            MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA

LOOP        IN    PORTC            Get the push buttons
            ANI   00000001B        Is push button 0 pressed?
            JNZ   LOOP             No it is not!

            STC                    Shift LED one position to the left
            MOV   A,E
            RAL
            MOV   E,A
            MOV   A,D
            RAL
            MOV   D,A
            JC    OUTPUT           No need to reload!
            LXI   D,1111111111111110B   Reload shift register

OUTPUT      MOV   A,D              Output shift register
            OUT   PORTB
            MOV   A,E
            OUT   PORTA

            MVI   B,1              Short delay to overcome make
            CALL  DELAY             bounce

WAIT        IN    PORTC            Get push button status again
            ANI   00000001B        Is push button 0 still down?
            JZ    WAIT             It is! Wait until it's released

            MVI   B,1              Short delay to overcome break
            CALL  DELAY             bounce

            IN    PORTC            See if push button is really
            ANI   00000001B         released
            JZ    WAIT             Still not released
            JMP   LOOP             Repeat endlessly
 
 

I had to add the release bounce loop too to get a 100% bounce free action of the keys. In fact I experienced more bounce when the key is released, than when it is pressed.

 
  Continue To Lesson 6 - Still more inputs
 
  [Home] [Latest News] [Essentials] [Hardware] [The Build] [Programs] [Projects] [Downloads] [Submissions]
 
  Made in the UK