Let's rollNow 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.
|
;------------------------------------------------------------------------ ; ; 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.
|
;------------------------------------------------------------------------ ; ; 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] | |||