main.asm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ;**************************************************************
  2. ;* This stationery serves as the framework for a *
  3. ;* user application. For a more comprehensive program that *
  4. ;* demonstrates the more advanced functionality of this *
  5. ;* processor, please see the demonstration applications *
  6. ;* located in the examples subdirectory of the *
  7. ;* Freescale CodeWarrior for the HC12 Program directory *
  8. ;**************************************************************
  9. ; Include derivative-specific definitions
  10. INCLUDE 'derivative.inc'
  11. ; export symbols
  12. XDEF Entry,KVS,PRESSED,PRESSED_VAL,PORT_U,SEQUENCE,TON,TOFF,PORT_T,COUNTER
  13. XREF __SEG_END_SSTACK,Keypad,PulseWidthMod
  14. Variables: Section
  15. PRESSED ds.b 1 ;the keypad value in the LUT
  16. PRESSED_VAL ds.b 1 ;the numeral of the pressed key or the index of PRESSED in the LUT
  17. TON ds.b 1
  18. TOFF ds.b 1
  19. COUNTER ds.b 1 ;"define a byte variable to use as a counter" ^1
  20. Constants: Section
  21. DDR_T equ $242 ;DC motor DDR
  22. PORT_T equ $240 ;DC motor
  23. DDR_U equ $26A
  24. PSR_U equ $26D
  25. PDR_U equ $26C
  26. PORT_U equ $268 ;keypad
  27. ;key value pairs from 4.3
  28. KVS dc.b $EB,$77,$7B,$7D,$B7,$BB,$BD,$D7,$DB,$DD,$E7,$ED,$7E,$BE,$DE,$EE
  29. ;given sequence from lab instructions (with trailing zero)
  30. SEQUENCE dc.b $70,$B0,$D0,$E0,$00
  31. ;=================================================================================
  32. Code: Section
  33. Entry:
  34. LDS #__SEG_END_SSTACK
  35. BCLR COUNTER,#$FF;initialize the counter to zero
  36. BSET DDR_U,#$F0 ;bits 1-3 in bits 4-7 out
  37. BSET PSR_U,#$F0 ;pins 1-3 pull up
  38. BSET PDR_U,#$0F ;pull up pins 1-3
  39. MOVB #$80,CRGINT ;enable real-time interrupts
  40. MOVB #$3C,RTICTL ;set RTI interval to 1 ms
  41. CLI ;enable interrupts
  42. Main:
  43. JSR Keypad ;"The *unaltered* keypad routine from Lab 5.2 should be called in the main program."