68HC11 Project Part 2.

The numbers now all display for a moment, and then a decision will be run whether at least three digits are the same. If at least numbers are the same a “fun-” is show on the LCD. I also don’t have a Schmitt trigger I.C. so I use an Arduino to act as my switch de-bouncer.

68HC11 Assembly CODE

—————- Arduino Debouncing Code below ——————-


const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 8;      // the number of the LED pin

// Variables will change:
int ledState = LOW;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 900;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial LED state
  digitalWrite(ledPin, ledState);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
  // long enough since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        ledState = !ledState;
      }
    }
  }

  // set the LED:
  digitalWrite(ledPin, ledState);

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState = reading;
}

—————- End of Arduino CODE ——————–

————— 68HC11 Assembly CODE ——————–

********* Author Daniel D. Wilcox ************
******* Dr. Hassoun Assignment, (http://neuron.eng.wayne.edu/) ********

* The purpose of this program is to have four seven sigment
* displays running through random numbers. As PC0, a push button
* is pressed each display will stop, sequentially. If the final
* value displayed is the exact same for at least three screens
* the program display “Fun-” and will, after a short period of time
* restart again. Compensation for the bounching affect at PC0 has been
* solved by placing a capacitor across PC0 and STRA on P1F2.

* Generation of numbers on the 4 seven segment displays *

* Global Variables

PORTB EQU $1004
STACK EQU $8FFF
PIOC EQU $1002
PORTCL EQU $1005
WINNER EQU $D030 Stores the Number of Same digits
IRQCTR EQU $D020
SLOTNM EQU $D010 Current Slot Number sent to Displays
DISNM4 EQU $D004 Display 4 Saved Number Location
DISNM3 EQU $D003 Display 3 Saved Number Location
DISNM2 EQU $D002 Display 2 Saved Number Location
DISNM1 EQU $D001 Display 1 Saved Number Location

ORG $C000
LDS STACK

LDAA #%00111100 PD2-PD5 LCD-7-SEG are output
STAA $1009

LDAB #%00000000 Configure PCO is INPUT
STAB $1007 DDRC for PORT C implemented as input

LDAA PIOC CLEAR ALL SETTINGS
LDAA PORTCL

LDAA #$40 STAI is Set in PIOC, EGA is 0 for falling EDGE
STAA PIOC Store PIOC Settings

LDAB #$05 Set IRQ Counter to FIVE
STAB IRQCTR This will be decremented later

* Display 4 contents are set by default to FF, since 00 is used by digit 0

LDAA #$FF
STAA DISNM4 $FF Value to 4 Container
STAA DISNM3 $FF Value to 3 Container
STAA DISNM2 $FF Value to 3 Container
STAA DISNM1 $FF Value to 1 Container

CLI CLEAR I BIT

********************** Divider ***************************
* IRQDES be the IRQ number current active
* Compaires each displays container (saved number) against the default #FF
* if the container is zero (no button was pressed) it goes to the Specific
* display section DISP 4/3/2/1 and activates it, then it runs through 0-9
* then comes back and checks if any values have changed.

* If the value has changed, it goes to HEL 4/3/2/1, each time displaying the value
* that was last saved from the numgen (number generator) and then in turn turns on
* and off the rest of the displays after going the the numbers 0-9.

IRQDES LDAA DISNM4
CMPA #$FF Count Presses
BNE HEL4 IF branches, then it was pressed once
JMP DISP4

HEL4 LDAA #%00011100 Display 4 Selected
STAA $1008 Display 4 is activated
LDAB DISNM4 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA DISNM3
CMPA #$FF Have pressed ?
BNE HEL3
JMP DISP3

HEL3 LDAA #%00011100 Display 4 Selected
STAA $1008 Display 4 is on
LDAB DISNM4 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA #%00101100 Display 3 Selected
STAA $1008 Display 3 is activated
LDAB DISNM3 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA DISNM2
CMPA #$FF Have pressed? if so go to HEL2
BNE HEL2
JMP DISP2

HEL2 LDAA #%00011100 Display 4 Selected
STAA $1008 Display 4 is activated
LDAB DISNM4 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA #%00101100 Display 3 Selected
STAA $1008 Display 3 is on
LDAB DISNM3 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA #%00110100 Display 2 Selected
STAA $1008 Display 2 is on
LDAB DISNM2 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELL

LDAA DISNM1
CMPA #$FF Have pressed the button for the last time
* This would be the 4th time (1st display)
* BNE HEL0
JMP DISP1

** Single Number Delay **

Dell LDX #1000
DECXAG DEX
BNE DECXAG
RTS Return to Next Letter

*—————-IRQ Values Scroll ——————-*

* Activated the display in a desending numerical fassion, and then
* runs through the numbers 0-9. After DISP1 is completed, goes to
* confirm IRQ destinations have not changed.

DISP4 LDAA #%00011100 Display 4 Selected
STAA $1008 Display 4 is on
JSR NUMGEN

DISP3 LDAA #%00101100 Display 3 Selected
STAA $1008 Display 3 is on
JSR NUMGEN

DISP2 LDAA #%00110100 Display 2 Selected
STAA $1008 Display 2 is on
JSR NUMGEN

DISP1 LDAA #%00111000 Display 1 Selected
STAA $1008 Display 1 is on
JSR NUMGEN
JMP IRQDES

*—————————————————-*

*********************** Divider ***********************

* Number Generator 0-9 Digits
* SLOTNM ($D010) Stores the Most current Number Sent to PORTB
* SLOTNM is the current number sent to displays

ORG $C300
NUMGEN LDAA #$3F NUMBER 0
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay

LDAA #$06 NUMBER 1
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$5B NUMBER 2
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$4F NUMBER 3
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$66 NUMBER 4
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$6D NUMBER 5
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$7D NUMBER 6
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$07 NUMBER 7
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$7F NUMBER 8
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
LDAA #$67 NUMBER 9
STAA PORTB
STAA SLOTNM Number Stored (Most Current)
JSR Delay
RTS

*********************** Divider ***********************

* DELAY Script for Slot Number Generator
* Slow Settings: Delay#19 manlp#10000
* Live Settings: Delay#4 manlp#10

ORG $C500
Delay LDAB #7
manlp LDX #10
sublp DEX
BNE sublp
DECB
BNE manlp
RTS

*********************** Divider ***********************

* IRQ Specifications
* $D020 IRQ Counter – How many times it has been activated by pusbbutton PC0

ORG $00EE Interrupt vector recogized for PC0
JMP $C600

* IRQ to STAF
ORG $C600
LDAA PIOC
LDAA PORTCL Clears STAF Bit

* Decrement IRQ Counter. This is important as this dictates which display
* number to record as well as what line of code to execute

LOOP LDAB IRQCTR Load IRQ Counter, initially $05
DECB Decrement ACCB
STAB IRQCTR Saves Decremented Number

* What display should have its numbers recorded, predicated on IRQ Counter
* DISDRX Display Code Direction
* DISP_X Display Number

LDAB IRQCTR Loads Counter back to ACCB for comparison
CMPB #$04
BNE DISDR3 If this is for 3rd Display
JMP DISP_4 IF not for the 3rd Display

DISDR3 CMPB #$03
BNE DISDR2 If this is for 2nd Display
JMP DISP_3

DISDR2 CMPB #$02
BNE DISDR1 If this is for 1st Display
JMP DISP_2

DISDR1 JMP DISP_1 Goes to Display 1 code.

* Records number on DISP_x and returns to program; unless,
* DISP_1 is finally selected.

DISP_4 LDAA SLOTNM
STAA DISNM4 Store in Display 4 location
RTI Return to Slot Program

DISP_3 LDAA SLOTNM
STAA DISNM3 Store in Display 3 location
RTI Return to Slot Program

DISP_2 LDAA SLOTNM
STAA DISNM2 Store in Display 2 Location
RTI Return to Slot Program

* If IRQ COUNTER (IRQCTR) is 1, the program will continue BELOW
* Else, RTI for DISP_4/_3/_2

DISP_1 LDAA SLOTNM
STAA DISNM1

LDY #400

AGAI LDAA #%00011100 Display 4 Selected
STAA $1008 Display 4 is actiavted
LDAB DISNM4 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELLi

LDAA #%00101100 Display 3 Selected
STAA $1008 Display 3 is actiavted
LDAB DISNM3 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELLi

LDAA #%00110100 Display 2 Selected
STAA $1008 Display 2 is actiavted
LDAB DISNM2 Displays Value from Button press
STAB PORTB Display Contents of [DISNM4]
JSR DELLi

LDAA #%00111000 Display 1 Selected
STAA $1008 Display 1 is actiavted
LDAB DISNM1 Displays Value from Button press
STAB PORTB
JSR DELLi Display Contents of [DISNM4]
DEY
BNE AGAI
JMP HERE

** Single Number Delay **

Delli LDX #1000
DECXAi DEX
BNE DECXAi
RTS Return to Next Letter

* Compare if Numbers are same by calculating the difference between all possible differences
* $D030 Stores the Number of Zeros (Same Numbers), as an increment integers

HERE LDAA DISNM4 Display 4 saved number
CMPA DISNM3
BNE NXTNUM1 Analysis Next number since they are not same
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP NXTNUM1

NXTNUM1 LDAA DISNM4
CMPA DISNM2
BNE NXTNUM2
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP NXTNUM2

NXTNUM2 LDAA DISNM4
CMPA DISNM1
BNE NXTNUM3
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP NXTNUM3

NXTNUM3 LDAA DISNM3
CMPA DISNM1
BNE NXTNUM4
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP NXTNUM4

NXTNUM4 LDAA DISNM2
CMPA DISNM1
BNE NXTNUM5
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP NXTNUM5

* Last step, goes to ANALYS After this

NXTNUM5 LDAA DISNM3
CMPA DISNM2
BNE ANALYS
LDAB WINNER
INCB Increment B, Since number was the same
* i.e. difference was ZERO
STAB WINNER
JMP ANALYS

* WINNER ($D030) Stores the Number of Same digits
* IF WINNER is greater then two, then three of the 4 displays
* has the same number and “Fun-” is displayed for a period of time

ANALYS LDAB WINNER Loads Values that were the exact same
CMPB #03 Any value in [WINNER] greater then three means at least two numbers similiar
BGE FUN Branch if Greater then or Equal to
JMP CLEAR

* Display FUN as three matched numbers

********** Above End of Part 1/2 of Delay Global

LDY #0001

***** Secondary “FUN-” Delay, per letter
Delayi LDAB #2
manlpi LDX #3
sublpi DEX
BNE sublpi
DECB
BNE manlpi
RTS

FUN LDAA #%00011100 Display 4 is ON
STAA $1008 Save Display Settings
LDAA #$71 Letter F ($71)
STAA PORTB
JSR Delayi

LDAA #%00101100 Display 3 is ON
STAA $1008 Save Display Settings
LDAA #$1C Letter U ($1c)
STAA PORTB
JSR Delayi

LDAA #%00110100 Display 2 is ON
STAA $1008 Save Display Settings
LDAA #$54 Letter N ($54)
STAA PORTB
JSR Delayi

LDAA #%00111000 Display 4 is ON
STAA $1008 Save Display Settings
LDAA #$40 Letter – ($40)
STAA PORTB
JSR Delayi

DEY
BNE FUN

* If Numbers are not same, SET Tempory Storage Containers to FF

CLEAR LDAA #$FF
STAA DISNM4 $FF Value to 4 Container
STAA DISNM3 $FF Value to 3 Container
STAA DISNM2 $FF Value to 3 Container
STAA DISNM1 $FF Value to 1 Container

* Clear IRQ\
LDAB #$05 Set IRQ Counter to FIVE
STAB IRQCTR This will be decremented

* Clear WINNER Values
LDAA #00
STAA WINNER
CLI
RTI

*** RETURN TO PROGRAM ****

————– END OF ASSEMBLY PROGRAM —————

Leave a Comment

Your email address will not be published. Required fields are marked *