Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. ;################################################################################
  2. ;# #
  3. ;# Exercise: #
  4. ;# Microcontroller Laboratory Exercise with ZILOG DEVELOPER STUDIO 3.68 and #
  5. ;# Z8 CCP Emulator (Z86CCP01ZEM) #
  6. ;# #
  7. ;# Task: #
  8. ;# Clock-Program #
  9. ;# The Program uses Timer1 as a simple clock and show the hundredths, seconds #
  10. ;# and hours on Port 0, Port 1 and Port 2 as binary number. #
  11. ;# The timer is set to continues mode (bit D0=1) and the clock source is the #
  12. ;# internal source clock. Each time when the Timer/Counter and the prescaler #
  13. ;# both reach the end end-of-count (of every 1/100 second- hundredth), #
  14. ;# an interrupt request IRQ5 is generated. #
  15. ;################################################################################
  16.  
  17. VECTOR IRQ0 = IRQ_DUMMY ;The Interrupt vectors
  18. VECTOR IRQ1 = IRQ_DUMMY
  19. VECTOR IRQ2 = IRQ_DUMMY
  20. VECTOR IRQ3 = IRQ_DUMMY
  21. VECTOR IRQ4 = T0_IRQ ;neuer IRQ
  22. VECTOR IRQ5 = T1_IRQ ;ISR for Timer-Interrupt begins by
  23.  
  24. init:
  25.  
  26. HOUR: .equ r12
  27. MINUTE: .equ r13
  28. SECOND: .equ r14
  29. HUNDREDTH: .equ r15
  30. STACK: .equ %EF ;Work. Register Group 1, Work. Register F
  31.  
  32. ld SPL,#STACK ;load the Stack Pointer Low Byte (SPL = control register at address FF)
  33. ld RP,#0Fh ;Select ERB Bank F, working register group 0 for access
  34. ld 0Bh,#00010011B ;CLOCK MODE SWITCHING, select
  35. ;D0 = 1 divide by 16, D1 = SCLK/TCLK = XTAL
  36.  
  37. nop ;When changing either clock mode selection bits D1 or D0 in the Stop Mode Recovery register(address 0Bh = SMR),
  38. nop ;it is recommended that two No Operation instructions (NOP’s) immediately follow that change
  39. ld RP,#00h ;Select the Standard Register File for access (ERB Bank 0, working register group 0)
  40.  
  41. clr p2m ;Defines port 2 pins to be outputs
  42. ld p3m,#00000001B ;Set Port2 as Push-Pull
  43. di ;Disable all Interrupts
  44. clr irq ;Clear all interrupts
  45. ld imr,#10100000b ;Enable Timer1_IRQ
  46. ld p01m,#00000100B ;Init Port 1 mode as outputs (that is P00-03 is output, internal stack-D2 set to 1,P10-17 is output, P04-07 is output, Normal Memory Timing-bit D5 set to 0)
  47. ei
  48.  
  49. ld pre1,#11001011b ;Prescaler=50, internal clock source (D1 set to 1), (Timer 1 set to continues Count Mode N (bit D0 set to 1))
  50. ld t1,#200 ;200 is equal to 1/100 second at 8 MHz clock
  51. or tmr,#11001100b ;load and start timer1 (bits D2 and D3 set to 1), Internal Clock Out (bits D7D6=11)
  52.  
  53. ld SECOND,#0 ;Reset the Clock
  54. ld MINUTE,#0
  55. ld HOUR,#0
  56. ld HUNDREDTH,#0
  57.  
  58. start:
  59. ld p0,HUNDREDTH ;Show the hundredths on Port 0 as binary number (Now the LEDs display the hundredths)
  60. ld p1,SECOND ;The LEDs show now the Seconds
  61. ld p2,MINUTE ;
  62. jp start ;as long as there are no Interrupts, this loop will repeat
  63.  
  64. T0_IRQ:
  65. iret ;Zählen von
  66.  
  67.  
  68. T1_IRQ: ;Start the Interrupt-Service-Routine
  69. ;disable T1
  70. inc HUNDREDTH ;1/100 Second increment
  71. cp HUNDREDTH,#100 ;a whole second?
  72. jp ne,T1_IRQ_EXIT ;no
  73. clr HUNDREDTH ;yes
  74. inc SECOND ;Seconds increment
  75. cp SECOND,#60 ;a whole Minute?
  76. jp ne,T1_IRQ_EXIT ;no
  77. clr SECOND ;yes
  78. inc MINUTE ;Minutes increment
  79. cp MINUTE,#60 ;a whole hour?
  80. jp ne,T1_IRQ_EXIT ;no
  81. clr MINUTE ;yes
  82. inc HOUR ;an hour increment
  83. T1_IRQ_EXIT:
  84. ;enable T0
  85. iret ;Return from the Interrupt-Service-Routine
  86.  
  87. IRQ_DUMMY:
  88. ;enable T1
  89. iret ;ISR-Dummy, in case any other interrupt is entered
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement