Saturday, February 1, 2020

"Car Simulation" on MicroController using Freescale HCS12(X) Assemble Code


Assignment Details


Car Peripheral Simulation


Objective:
Write an assembly program to simulate a Car Peripheral  with V6 Engine.(Engine and Transmission).

Peripheral Simulations:
1.      Stepper-Motor: Output of transmission.  Clockwise for forward, Counter-Clockwise for reverse. 
2.
      DC-Motor: Engine.
3.
      Keypad: Select different options and provide functionality for:
a)
      Set the time: The user should be able to set the time (hh:mm:ss Day).
b)
      Enter the password for starting
c)
      Be able to change password
d)
     Select to repair engine through the menu options
4.
      Potentiometer: Controls engine rpm(rotation per minute).
5.
      LCD: 
a)      Menu
b)
      Display: Fuel Level, RPMs
c)
      View time and mileage
6.
      Push Button: Start engine.
7.
      Switches: Shift gears 1, 2, 3, N and reverse. Turn power on to engine. Add Fuel.
8.
      Speaker (Port T): music (3 different songs >5seconds each)
9.
      LEDs: 4 LEDs will simulate the sparkplug of a 6 cylinder engine, 1 LED will show power to engine.
10.
  IRQ: Throws an engine rod and a knocking sound must be sent to speaker.  If engine does not shut off within 6 seconds then the engine breaks and automatically shuts off. 
11.
  RTI control timing.

Requirements:
1 The engine (DC motor) used to simulate engine rpms.
·         In order to start the car the transmission must be in neutral.
·         The DC motor will increase in Revolutions Per Minute when the potentiometer resistance increases.
·         If the IRQ is pressed then the engine throws a rod and a knocking sound must be sent to speaker.  If engine does not shut off within 5 seconds then the engine breaks and automatically shuts off. 
·         If this happens threw the menu, using the hex keypad, select to perform a repair before the engine can restart.


2.      The transmission (Stepper motor) will turn clockwise for forward or counterclockwise for reverse.  In order for the car to move it must start in first gear or reverse.  If in forward direction as the gears increase the stepper motor rotation speed will increase.  Also, you cannot skip a gear must start at 1 then 2 then 3.  If a gear is skipped both the DC motor and the Stepper motor stop.  At this time the engine must restart.  To switch directions the car must return to neutral and the stepper motor must not be rotating.
 

3.      No delay loops are allowed, you must utilize the Real Time Interrupt.  DELAY LOOPS ARE ONLY ALLOWED OR HEX KEYPAD DE-BOUNCE.


 FINAL REPORT:
            The Goal of this project is to write an assembly program for this HCS12 microcontroller to simulate a car with V6 engine (Engine and Transmission), by doing this project we can learn many things and improve our assembly language skills, for instance we learned to use Real Time Interupt, switch debouncing, LEDs, LCD, hex keypad, switches, DC motor, stepper motor, amplifier, speaker, and many more thing not listed here. This final project pretty much use all of the knowledge we learned from lab 1 to lab 7.
We try to follow the peripheral simulations in the final project guide but we have to modify some of it because the wording is a little bit confusing and some of the stuffs don’t really make sense. So this is out peripheral simulations after we modify the one given to us.
1.      Stepper-Motor:
Output of transmission.  Clockwise for forward, Counter-Clockwise for reverse. 

2.      DC-Motor: Engine; it showed the speed of the car.

3.      Keypad:
a)      Set the time: The user should be able to set the time (hh:mm:ss Day).
b)      Enter the password for starting
c)      change password
d)     Select song

4.      Potentiometer: Controls engine rpm(rotation per minute).

5.      LCD:
a)      Menu
b)      Display: Fuel Level, RPMs, time, mileage

6.      Push Button: Start engine.

7.      Switches: Shift gears D,R,N . Turn power on to engine. Add Fuel.

8.      Speaker (Port T):
music (3 different songs >5seconds each)

9.      LEDs: 4 LEDs will simulate the sparkplug of a 6 cylinder engine, 1 LED will show power to engine.

10.  IRQ: Throws an engine rod and a knocking sound must be sent to speaker.  If engine does not shut off within 6 seconds then the engine breaks and automatically shuts off. 


11.  RTI control timing.
Below is the detail explaining what each switch does, and what each LEDs simulate.

7
6
5
4
3
2
1
0
Extra LED: this one do nothing
These four LEDs will simulate the sparkplug of a 6 cylinder engine. So when the car start it will go on then go off a few moment later.

This is the left turn signal.
This LED will show power to engine. So as long as the car is running this LED will be on.
This is the right turn signal.


7
6
5
4
3
2
1
0
Turn on left turn signal
Turn on hazard  signal
Turn speaker on
Turn stepper motor
clock wise
Turn engine on
Turn stepper motor
Counter clock wise
Add fuel
Turn on right turn signal

1.      Most of the time the switch 5 and 3 will be one, because most of the time car engine should be running and music should be on.
2.      Switches 4 and 2 can’t be on at the same time. There are only one gear at a time: D, R, N.
3.      Switched 7 and 0 can’t be on at the same time because left turn and right turn switches can’t be on at the same time.
4.      When shifting gear you must turn the current gear off first – therefore go to neutral first, then you turn the new gear on.
5.      Also, you must be in neutral when adding fuel or else you can’t add fuel. So the switched 4 and 2 must be off if switch 1 is on.
            The main.asm file is the main file it control the program, and this is where most of the variable, constant is declare and initialize.
            Basically, this is what the main.asm file does, it first initialize all the variable, and then it initialize all the ports that we will be using, then it initialize the interrupts that we will be using then it go start by asking user for password then tell user to set time, set password, select song. Then it enable the RTI and go into a loop displaying the stuff to the LCD, therefore it refresh the LCD every time in loop. So it just keep on looping.  In that same loop there is also subroutine to check switches, increment time , check potential meter every time it go through the loop. So that is all the main.asm does. Other files are mostly just place to put the subroutine that the main.asm will be calling.
            The next important file is the RTI.asm that is where the real time interrupt is. The real time interrupt control the music, the stepper motor, the DC motor, and it increment the seconds. Below is the flow of the RTI.
1.      Check if fuel is zero or not if it is then just increment seconds and exit the RTI.
2.      If fuel not zero, then the next step is check what is the gear variable, then set the sequence to send to the stepper motor according to the gear.
3.      Check the speed variable for the speed. And send the high or low voltage to the DC motor accordingly, also the speed is used to control how fast the distance traveled increased.
4.      Increment second
5.      Exit RTI
So that is what happened during each RTI interrupt. The rest of the files are C code that was given to us to control the LCD stuff and to output the potential meter, we also have the C code controlling the sound for the speaker. And there is other parameter file that we edit too.
The extra features we added to this project are below:
1.      Welcome displayed on the LCD screen
2.      The Right, Left, Hazard signal


1.      First when you open everything, you will see a welcome screen saying something like this “WELCOME TO MY CAR”
2.      After that just put in the password, the password should be 1234
3.      Setup a new password by pressing four number on the hex keypad
4.      Choose song: press 1 or 2 or 3
5.      Then you should arrive at a normal display screen on that screen you will see these acronym:
D = distance traveled
RPM = rotation per minute
GAS = Gasoline level
DD:HH:MM:SS = it displayed the time and date
IRQ button:
Pressing the IRQ button will break your engine, so you must press “5” to repair your engine.
NO GAS:
If you run out of GAS then turn on the bit1 of dip switch to refill after finish refiling then turn it off.
***NOTE: no gear can be on when refiling the gas, therefore, the switch 4 and 2 must be off.
Other information about LEDS, and switches are already given in the pages before this.
These are all of the important codes in the important files.
Not all files are included here, for instance code from these file are not included here:
Derivative.h, derivative.inc, main_asm.h, burner.bbl
Those are just some of the examples of the files that did not have in this final project reports. There are many other unimportant files that were also not included here.
Below you will find all of the important codes that we wrote.
******Note that with these code alone the program will not run properly.



            INCLUDE 'derivative.inc'
    XDEF Entry, _Startup, variable  , array,array2 ,port_p ,port_t,DC_dirc
    XDEF second,  min ,hour,display_string,disp ,potvalue ,RTIFLAG,step_point, tonevalue
            Xdef port_u,newpassword,password,row,table,keyInput,fuel,count,position1
            xDEF VAR,fuel_latch,LED_Blink,depth, Count1, Count2,position,IRD_LED,pointer
            xdef speed,IRQcounter,target_depth,array,noPress,LEDFlag,Port_S,change
            XDEF sound1,sound2,menucount,count1,noPress,padScan ,port_TDDR ,day,divedecide
            xdef gear,speedvar, currentspeed, distancetraveled, distancetraveledvar
    XDEF Wipers, WiperCount, WiperDelay, WiperOnDelay, second2
    XDEF WiperOffDelay, Engine, HornPB, HornCount, HornFreq
    XDEF LEDS, LeftTurnSwitch, RightTurnSwitch, HIBeamSwitch, LowBeamSwitch, OnOffSignal
 
            XREF __SEG_END_SSTACK, init_LCD, read_pot, display_string, pot_value ,NOMOVE ,displaytime
            XREF LCD_normal,loadspeed ,call_speaker,decide_speed,stepMotor,callmenu
            XREF speed_reverse, speed_forward  ,LCD_start,fuel_latch ,change_password, enter_password,setmenu
                XREF xv,xv2,settime, SendsChr,keypadcheck2,lastone, LCDwelcome,debounceswitch,string1
            XREF ControlWiper, checkPAD2, checkPAD

my_variable: SECTION
gear: ds.b  1
distancetraveled: ds.b 1
distancetraveledvar:  ds.b 1
disp: ds.b 33
LEDFlag:    ds.b  1     ; flag for RTI controlled LEDs
;time
hour  ds.b  1
min   ds.b  1
second      ds.b  1
day ds.b 1
second2 ds.b  1
variable:        ds.b     1
potvalue    ds.b  1
;password
newpassword ds.w  4;use to replace password
password    ds.w  4   ;4 digit password
position      ds.b     1
position1     ds.w  1
;*********keypad
keyInput  ds.w  1
;*************fuel
fuel      ds.b  1   ;fuel level
;***********speed
Count1 ds.b 1
Count2 ds.b 1
;*****************notsure
count ds.b  1
count1 ds.b    1
Counter     ds.b     1
VAR   ds.b      1
menucount ds.b    1
IRQcounter ds.b 1
IRD_LED ds.b 1
;***********LED
LED_Blink ds.b 1
depth ds.b 1
speed ds.b 1
;*******stepmotor
target_depth ds.w 1
change  ds.w  1
pointer ds.w 1
divedecide ds.b 1
step_point ds.b 1
DC_dirc ds.b 1
currentspeed: ds.b 1   ;speed value that the dc motor is running right now
speedvar:     ds.b 1   ;this variable is used to control the speed
tonevalue:    ds.b 1
WiperOnDelay:       ds.b    1
WiperOffDelay:       ds.b    1
WiperDelay:           ds.b    1
WiperCount:           ds.b    1
HornCount:            ds.w    1
      HornFreq:             ds.w    1
      OnOffSignal:         ds.b    1
      Engine:                ds.b    1
      LeftTurnSwitch:          ds.b    1
      RightTurnSwitch:         ds.b    1
      HIBeamSwitch:            ds.b    1
      LowBeamSwitch:            ds.b    1
     
      HornPB:               ds.b    1
      AmPmFlag:              ds.b    1   
      Wipers:                ds.b    1
songnumber  ds.b  1
my_constant: section
array:  dc.b     $0A,$12,$14,$0C,$FF
array2:  dc.b     $0C,$14,$12,$0A,$FF
port_t:   equ      $240 ;motor: ON(set bit3) OFF(clear bit3)
port_TDDR   equ   $242
Port_S:     equ   $248              ;LEDs to display SECOND
port_sddr   equ         $24A
port_p:  equ      $258
port_pddr    equ $25A  ;motorddr
port_u      equ         $268  ;port U
port_uDDR   equ   $26A  ;port direction register
port_uPSR   equ   $26D  ;portport U polarity select register
port_uCNR   equ   $26C  ;port control register
RTIFLAG:    equ   $0037;RTI flag
RTIENA:     equ   $0038   ;RTI enable
RTI_CTL:    equ   $003B  ;RTI time control
table: dc.b $EB, $77, $7B, $7D, $B7, $BB, $BD, $D7
       dc.b $DB, $DD, $E7, $ED, $7E, $BE, $DE, $EE, $00
row: dc.b $70, $B0, $D0, $E0, $CC
sound1: dc.b $11,$22,$33,$44,$55
sound2: dc.b $AA,$BB,$CC,$DD,$EE 
padScan     dc.b        $70,$b0,$d0,$e0
noPress   dc.b    $7f,$bf,$df,$ef
LEDS:                 equ $248

song1:        dc.b 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5
song2:        dc.b 5,4,3,2,1,5,4,3,2,1,5,4,3,2,1
song3:        dc.b 1,3,1,3,1,3,1,3,1,3,1,3,1,3,1
; code section
MyCode:     SECTION
Entry:
_Startup:

      lds   #__SEG_END_SSTACK
      jsr init_LCD


;INITIALIZATION
   movb #0, speedvar
   movb #0, currentspeed
   movb #0, distancetraveled
   movb #77, gear
   movb #0,second2
   movb #1, songnumber
    ldx   #0
    stx  xv
    ldaa  #4
    staa  xv2

  movb  $0,LED_Blink   ;LED light all off

      ;Time variable 
          LDAA    #$0
          STAA    count
          STAA    second
          STAA  min
          STAA  hour
                
      ;keypad
      ldaa  #$F0
      staa  port_uDDR
      staa  port_uPSR
      ;Enable     pull up resister of port_u
      ldaa  #$0F
      staa $26B  
      staa  port_uCNR  
      ;DCmotor
  movb #$7f,$24a
  bset  port_pddr,#%11110
  ;;;;;;;;;;Stepmotor;;;;;;;;;;;;;;;
  ldaa    #%11110                ;set 1 bit(11) to port_p  enable step motor
  staa    port_pddr

      ;;;;;;;;;;PWM;;;;;;;;;;;
      bset  port_TDDR,#101000
      ;;;;;;;;;;RTI;;;;;;;;

      bset  RTIENA,#%10000000 ;enable RTI
      bset  RTIFLAG,#%10000000      ;RTI Flag
      ;;;;;;;;in value
      movb #$0,count
      movb #$0,Counter
      movb #10,fuel
      movb #$0,menucount
      movb #0,Count1
      movb #0,Count2
      movb #0,speed
      movb #0,IRQcounter
      movb #0,LEDFlag

      movb #0,day
 
  jsr LCDwelcome
  ldd #disp   
      jsr display_string
      jsr debounceswitch
      movb #0,IRD_LED
  movw #0,pointer
      movw #0, change
  jsr debounceswitch

      movw #1,password
     movw #2,password+2
     jsr debounceswitch
     jsr debounceswitch
     movw #3,password+4
     movw #4,password+6
     jsr debounceswitch
     jsr debounceswitch
     movw #0,target_depth
     movw #0,newpassword
     movw #0,newpassword+2
     movw #0,newpassword+4
     movw #0,newpassword+6
     jsr debounceswitch
     jsr debounceswitch    

      movb  #0,position
      movw #0,depth
      movw #0,change
      jsr debounceswitch
      jsr debounceswitch
      movb #0,divedecide
      movw #0,target_depth
      movb #0,step_point
      movb #0,DC_dirc
      jsr debounceswitch
      jsr debounceswitch
      movb #0,keyInput
            movw #55, HornFreq
            movb #0, HornPB
            movb #0, OnOffSignal
            ldx  #0
            movb #0, Engine
            movb #0, LEDS
           
 ;INITIALIZATION END

      ldaa  #1
  staa  tonevalue  

 jsr LCD_start
      ldd #disp   
      jsr display_string
;check the password before showing the meanu
      jsr  enter_password;check the passcode
      bset LEDS, %01111000
      jsr  change_password
      bset LEDS, 000000
      jsr settime
      jsr string1
  ldd #disp
      jsr display_string
  jsr checkPAD
  ldaa keyInput+1
      cmpa #1
      beq choosesong1
      cmpa #2
      beq choosesong2
      cmpa #3
      beq choosesong3

choosesong1:
  movb      #1, songnumber
  bra goafterchoosesong
choosesong2:
  movb      #2, songnumber
  bra goafterchoosesong
choosesong3:
  movb      #3, songnumber
  bra goafterchoosesong

goafterchoosesong:
     
     
      jsr  LCD_normal
      ldd #disp
      movb        #$29, RTI_CTL    
  movb      #$80, RTIENA       
      cli
  ldy   #0



display:
   


  
    ldaa tonevalue
    psha
    ldd #5
    jsr SendsChr  
    pula


    jsr timeinc

                            ;   !these are
    ldaa  port_t            ;   !the
    anda  #001000         ;   !code
    bne   nogear             ;   !to
                             ;   !read
                             ;   !value
                             ;   !from
    ldaa  port_t             ;   !port
    anda  #000100         ;   !and
    bne   gear1              ;   !check
                             ;   !which
    ldaa  port_t             ;   !switch
    anda  #000010         ;   !is
    bne   fuelup              ;   !on
                             ;   !
    ldaa  port_t             ;   !
    anda  #010000         ;   !
    bne   gear3              ;   !
                             ;   !           
                            
                             ;   !
nogear:                      ;   !then
    movb  #77,gear           ;   !we
    bra gothere              ;   !will
gear1:                       ;   !set
    movb  #1,gear            ;   !variable "gear"
    bra gothere              ;   !according
fuelup:                       ;   !to
    movb  #50,fuel            ;   !the
   
    jsr  LCD_normal
        ldd #disp
   
    bra gothere              ;   !switch
gear3:                       ;   !
    movb  #3,gear            ;   !
    bra gothere              ;   !

gothere:
  
    ldaa  port_t            ;   !the
    anda  #000001         ;   !code
    bne   rightsignal             ;   !to
                             ;   !read
                             ;   !value
                             ;   !from
    ldaa  port_t             ;   !port
    anda  #%10000000         ;   !and
    bne   leftsignal             ;   !check

    ldaa  port_t             ;   !
    anda  #%01000000         ;   !
    bne   hazardsig

    bra exitsignalcheck

rightsignal:
     bset LEDS, 000001
     bra  exitsignalcheck
leftsignal:
     bset LEDS, 000100
     bra  exitsignalcheck
hazardsig
     bset LEDS, 000101
     bra  exitsignalcheck
    
exitsignalcheck:
 
    jsr read_pot     
    ldd #disp
            jsr display_string

            jsr decide_speed
            movb LED_Blink, Port_S
           
           
           
            jsr loadspeed
            jsr   displaytime
 
    ldab  second2
    cmpb  #1
    beq   changenote
    bra   skipchangenote
changenote:

    ldab  songnumber
    cmpb  #1
    beq   playsong1
   
   
    ldab  songnumber
    cmpb  #2
    beq   playsong2
   
   
    ldab  songnumber
    cmpb  #3
    beq   playsong3
   
   

playsong1:   
    ldaa  song1,y
   
    bra goafterplaysong
   
playsong2:   
    ldaa  song2,y
    bra goafterplaysong

playsong3:   
    ldaa  song3,y
    bra goafterplaysong
   
goafterplaysong:
   
    staa  tonevalue
    iny
    cpy #10
    bne skipytozero
    ldy #0
skipytozero:    
    movb  #0,second2
     
skipchangenote:



           
            jmp   display
           
           
timeinc:
    ldab  second
    cmpb  #60
    beq   incminute
    bra   skipincminute
incminute:
    inc   min
    movb  #0,second 


skipincminute:



    ldab  min
    cmpb  #60
    beq   incrementhour
    bra   skipinchour
incrementhour:
    inc   hour
    movb  #0,min 


skipinchour:

    ldab  hour
    cmpb  #24
    beq   incrementday
    bra   skipincday
incrementday:
    inc   day
    movb  #0,hour 


skipincday:
    rts



   XDEF WALL_CLOCK,xv,xv2
   XREF   second,  min ,hour,  RTIFLAG ,Count1,Count2,day ,speed,change,updateTime,play,divedecide,step_point,target_depth,decide_speed
   xref potvalue ,depth,LED_Blink,port_TDDR ,count,fuel,nofuel,timer_count ,IRD_LED ,port_p ,array,array2,pointer,port_t,loadspeed
   xref pot_value, gear,speedvar, currentspeed, distancetraveled , distancetraveledvar, PlayTone, SendsChr, tonevalue, LCD_nofuel
   xref disp, LEDS, second2

My_constant section
cwise:  dc.b  $0A,$12,$14,$0C
ccwise: dc.b  $0C,$14,$12,$0A

My_variable section
xv: ds.w 1
xv2:  ds.b 1

My_code:    section

WALL_CLOCK:
    bset LEDS, 000010
    jsr  PlayTone
   
    ldaa  fuel
    cmpa  #0
    beq exit1   ;nofuel skip to end
    bra skipexit1
   
exit1:

  bclr LEDS, 000010
  jsr LCD_nofuel
      ldd #disp
     
      ldaa  #000000        
      staa  $240
     
                             
    inc count                ;   CODE
    ldaa count               ;   TO
    cmpa  #100               ;   !
                             ;   !
    bne here4                ;   inc clock
    inc second               ;  
    ldaa #0                  ;  
    staa count               ;  
here4:      
    
      movb  #$80, RTIFLAG
      rti   
skipexit1:   
   
    ldx xv           

    ldab  gear        ; check if no gear
    cmpb  #77        ;   !
    beq nogear       ;   !
    ldab  gear        ;
    cmpb  #2          ;   !
    beq next          ;   !
       
    ldab  gear           ;check if gear is forward
    cmpb  #1             ;if it is forward then steppermotor go clockwise
    beq   clockwise      ;
   
    ldab  gear                   ;check if gear is backward
    cmpb  #3                     ;if it is then stppermotor go counter clockwise
    beq   counterclock           ;
   
counterclock:
    ldaa          ccwise, x
    bra next

clockwise:
    ldaa          cwise, x
    bra next

next:
    staa  $258
    inx
    stx xv
    dec xv2
    bne exit2
    movw #0, xv
    ldaa #4
    staa xv2
nogear:   
    ldaa speed               ;this is the value read from the pot meter
    cmpa  #222
    beq speediszero
    cmpa currentspeed        ;check if the value from pot is same as speed value that the dc motor is running right now
    beq keepcurrentspeed     ;if it the same make no change to current speed
    staa currentspeed        ; if it different then store new value from pot to the current dc motor speed
    bra here3
speediszero:
    ldaa  #000000        
    staa  $240
    bra here2
   
here3:

keepcurrentspeed:            ; FROM
                             ; HERE
    ldaa  speedvar           ;   !
    cmpa  #0                 ;   !
    bne   notdoneyet         ;   !
    ldaa  #001000         ;   !
    staa  $240               ;   !
    ldab  currentspeed       ;   !
    stab  speedvar
    inc   distancetraveledvar;   !
   
    ldaa distancetraveledvar
            cmpa  #50
            beq incdistraveled
            bra skiptothere
incdistraveled:
            inc distancetraveled
            dec fuel
skiptothere:             
    bra   skipnotdoneyet     ;  TO
notdoneyet:                  ;  HERE
    ldaa  #000000         ;   !
    staa  $240               ;   !
    ldaa  speedvar           ;   !
    deca                     ;   IS  CODE TO CONTROL DC SPEED
    staa  speedvar           ;   !
skipnotdoneyet:              ;   !
    inc count                ;
    ldaa count             
    cmpa  #226              

    bne here2                
    inc second
    inc second2            
    ldaa #0                
    staa count            
here2:   
exit2:

      movb  #$80, RTIFLAG
      rti
   
   IRQ.asm

  XDEF Emergency_stop
  XREF LEDS, display_string,checkPAD
  XREF keyInput, string2, disp, LCD_normal
Emergency_stop:
      
  ldaa  #000000        
  staa  $240    
      jsr string2
  ldd #disp
      jsr display_string
  bclr LEDS, 000010
wrongbuttonpress:

  jsr checkPAD
  ldaa keyInput+1
      cmpa #5
      beq repaircar
      bra wrongbuttonpress
repaircar: 
      ldaa  #001000        
      staa  $240
    bset LEDS, 000010   
  jsr  LCD_normal
      ldd #disp
  jsr display_string
       rti
      

decidespeed.asm      

xref speed,potvalue
 xdef decide_speed


decide_speed:
      ldaa potvalue
      cmpa #0
      beq load_speed0
      cmpa #2
      blo load_speed1
      cmpa #4
      blo load_speed2
      cmpa #7
      blo  load_speed3
      cmpa #10
      blo  load_speed4
      cmpa #13
      blo  load_speed5
      cmpa #17
      blo  load_speed6
      cmpa #20
      beq  load_speed7
      cmpa #24
      blo  load_speed8
      cmpa #28
      blo  load_speed9
      cmpa #33
      blo  load_speed10
      cmpa #45
      blo  load_speed11
      cmpa #60
      blo   load_speed12
      cmpa #65
      blo  load_speed13
      cmpa #70
      blo   load_speed14
      cmpa #75
      blo  load_speed15
      cmpa #80
      blo  load_speed16
      cmpa #85
      blo  load_speed17
      cmpa #90
      blo  load_speed18
      cmpa #95
      blo  load_speed19
      cmpa #101
      blo  load_speed20

load_speed0:
      movb #222,speed

      rts

load_speed1:
      movb #100,speed

      rts

load_speed2:
      movb #90,speed

      rts
load_speed3:
      movb #75,speed

      rts
load_speed4:
      movb #50,speed

      rts
load_speed5:
      movb #35,speed

      rts
load_speed6:
      movb #24,speed

      rts
load_speed7:
      movb #15,speed

      rts
load_speed8:
      movb #8,speed

      rts
load_speed9:
      movb #1,speed

      rts
load_speed10:
      movb #11,speed

      rts
load_speed11:
      movb #10,speed

      rts
load_speed12:
      movb #9,speed

      rts
load_speed13:
      movb #8,speed

      rts
load_speed14:
      movb #7,speed

      rts
load_speed15:
      movb #5,speed

      rts
load_speed16:
      movb #4,speed

      rts
load_speed17:
      movb #3,speed

      rts
load_speed18:
      movb #2,speed

      rts
load_speed19:
      movb #1,speed

      rts
load_speed20:
      movb #1,speed

      rts
           
           
           



          XDEF ControlWiper
         
          XREF LEDS, LeftTurnSwitch, RightTurnSwitch, HIBeamSwitch, LowBeamSwitch, OnOffSignal,port_t
myCode:          Section  
ControlWiper:
    ldaa  port_t            ;   !the
    anda  #000001         ;   !code
    bne   rightsignal             ;   !to
                             ;   !read
                             ;   !value
                             ;   !from
    ldaa  port_t             ;   !port
    anda  #%10000000         ;   !and
    bne   leftsignal             ;   !check  for which signal should be on

    ldaa  port_t             ;   !
    anda  #%01000000         ;   !
    bne   hazardsig

    bra exitsub

rightsignal:
     bset LEDS, 000001
     bra  exitsub
leftsignal:
     bset LEDS, %10000000
     bra  exitsub
hazardsig
     bset LEDS, %10000001
     bra  exitsub
exitsub:
          rts

        

 keypad.asm      
        

      XDEF  checkPAD,checkPAD2 ,delayG, debounceswitch
      XREF  port_u, table,padScan ,keyInput,noPress
checkPAD:
        pshx
      check_restart:
                    ldx #0
      checkNEXT:
        cpx #4
      beq         check_restart  ;keep checking until user press
            ldaa  padScan,x   ;fed pad
            staa  port_u           
            jsr         delayG
            ldaa  port_u    ;get result
            cmpa  noPress,x   ;if pad is press
            bne         keyPRESS    ;is pressed
            inx
            bra   checkNEXT;otherwise go next row or row back
            keyPRESS:
                        pulx
                        jsr keyValue
                        rts
checkPAD2:
        pshx
      checkNEXT2:
            ldaa  padScan,x   ;fed pad
            staa  port_u           
            jsr         delayG
            ldaa  port_u    ;get result
            cmpa  noPress,x   ;if pad is press
            bne         keyPRESS2   ;is pressed
            inx
            bra   checkNEXT2;otherwise go next row or row back
            keyPRESS2:
                        pulx
                        jsr keyValue
                        rts
keyValue:
         pshx
         ldx  #0
 nxt:
         cpx  #16
         beq  notFound
         cmpa table,x
         beq  valueFound
         inx
         bra  nxt
valueFound:
    
          pshx
     check_press_reset:
          ldx #-1
     check_press:
          inx
          cpx #4
          beq  check_press_reset
                  ldaa  port_u    ;get result
                  cmpa  noPress,x   ;if pad is press
                  bne         check_press ;is pressed
                 
                  pulx
          stx  keyInput
         pulx
          rts
        
notFound:
         pulx
         rts
delayG: 
        pshx
        ldx #400
delay:
        dex
        bne delay
        pulx
        rts
debounceswitch:

      ldy  #$FFFF
here1253:  
  dey
  bne   here1253
  rts
             

menu.asm       
       
       xdef setmenu,callmenu
        xref count1,menucount,disp ,settime, change_password ,display_string,port_t,enter_password
        xref string1,string2,string3,string4,readkeypad,enter_menu,stepMotor,read_value,LCD_start ,checkPAD,keyInput
callmenu:
     brclr port_t,#000100,endmenu
     jsr  LCD_start
     ldd #disp
            jsr display_string
     jsr  enter_password
     jsr setmenu
endmenu:
          rts
setmenu:
  jsr enter_menu
      ldd   #disp   
      jsr display_string
      reentermenu:
        jsr checkPAD
        ldaa keyInput+1
      cmpa #1
      beq menunumber
setenter: 
      cmpa #2
      beq menuenter
      cmpa #3
      beq menureturn
        bra reentermenu

menuenter:
      ldab menucount
      cmpb #1
      bne menuenter2
      jsr settime
      movb #0,menucount
      bra setmenu
menuenter2:
      cmpb #2
      bne menuenter3
      jsr change_password
menuenter3:
      cmpb #3
      bne menuenter4 
      jsr read_value
menuenter4:
    
   bra setmenu
     

menureturn:
      rts

meuntime:
      psha 
      jsr string1
      ldd   #disp   
      jsr display_string
      pula
      bra reentermenu  
menupass:
      psha
      jsr string2
      ldd   #disp   
      jsr display_string
      pula
      bra reentermenu
menudepth:
      psha
      jsr string3
      ldd   #disp   
      jsr display_string
      pula
      bra reentermenu
menuhorn:
      psha
      jsr string4
      ldd   #disp   
      jsr display_string
      movb #0,menucount
      pula
       bra reentermenu
     
 menunumber:
      inc menucount
      ldab menucount
      cmpb #1
      beq  meuntime
      cmpb #2
      beq  menupass
      cmpb #3
      beq  menudepth
      cmpb #4
      beq  menuhorn
  

No comments:

Post a Comment