Advertisement
Guest User

DeviceATmega16

a guest
Apr 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "m16def.inc"
  2. .list
  3. .def temp = r16
  4. .def sys = r17
  5. .def trns = r18
  6. .def str = r19
  7. .def k = r20
  8. .def msumb1 = r21
  9. .def msumb2 = r22
  10. .equ bitrate =38400
  11. .equ BAUD=8000000/(16*bitrate)-1
  12. .cseg
  13. .org 0
  14. rjmp RESET
  15. //.org $009
  16. //rjmp USART_RXC
  17. //.org $00B
  18. //rjmp USART_TXC
  19. ;;Interrupt table definition
  20.  
  21. .org INT0addr
  22. rjmp INT0_IRQ
  23.  
  24. .org INT1addr
  25. rjmp INT1_IRQ
  26.  
  27. .org OC1Aaddr
  28. rjmp OC1A_IRQ
  29.  
  30. .org OC1Baddr
  31. rjmp OC1B_IRQ
  32.  
  33. .org OVF1addr
  34. rjmp OVF1_IRQ
  35.  
  36. INT0_IRQ:
  37. reti
  38.  
  39. ;INT1_IRQ:
  40. ;reti
  41.  
  42. OC2_IRQ:
  43. reti
  44.  
  45. OVF2_IRQ:
  46. reti
  47.  
  48. ICP1_IRQ:
  49. reti
  50.  
  51. ;OC1A_IRQ:
  52. ;reti
  53.  
  54. OC1B_IRQ:
  55. reti
  56.  
  57. OVF1_IRQ:
  58. reti
  59.  
  60.  
  61. RESET:
  62. clr msumb1
  63. clr msumb2
  64. ;Stack Init
  65. ldi temp,low(RAMEND)
  66. out SPL,temp
  67. ldi temp,high(RAMEND)
  68. out SPH,temp
  69. ;USART Init
  70. ;BAUD=19600 bit/sec
  71. ldi sys,high(BAUD)
  72. out UBRRH,sys
  73. ldi sys,low(BAUD)
  74. out UBRRL,sys
  75. ;
  76. ldi sys,(1<<TXEN)|(1<<RXEN) ; TXEN=1)
  77. out UCSRB,sys
  78. ;UCSZ0 UCSZ1 =1 => 8 bit + URSEL=1 (1 stop-bit)
  79. ldi   sys,(1<< URSEL)|(1<< UCSZ0)|(1<< UCSZ1)
  80. out UCSRC,sys
  81. ;Low Level Signal
  82. ldi temp,(0<<PORTD3)
  83. out PORTD,temp
  84. ;INT1 External Interrupt Init
  85. ldi sys, (1<<ISC11)|(1<<ISC10)
  86. out MCUCR,sys
  87. clr sys
  88. ldi sys,(1<<INTF1)
  89. out GIFR,sys
  90. ldi sys,(1<<INT1)
  91. out GICR,sys
  92. ;Button Init
  93. ldi sys,(0<<PIND7)
  94. out PIND,sys
  95. clr temp
  96. clr sys
  97. out DDRB,temp
  98. out DDRA, temp
  99. ldi temp,(1<<PORTD3)
  100. out PORTD,temp
  101. clr sys
  102. //TIMER1 (16 bit) Initialization; Output Compare A Match Interrupt Enable
  103. ldi temp,(1<<OCIE1A)
  104. out TIMSK,temp
  105. //Set Output Compare Register A; 1562 <=> 5 Hz
  106. ldi temp,high(500)
  107. out OCR1AH,temp
  108. ldi temp,low(500)
  109. out OCR1AL,temp
  110. clr temp
  111. //Timer/Counter Init
  112. out TCNT1H,temp
  113. out TCNT1L,temp
  114. //CS12-CS10 Clock Select in 1024 prescaller
  115. ldi temp,0b00001101
  116. out TCCR1B,temp
  117. clr temp
  118. sei
  119. loop:
  120. rjmp loop
  121. INT1_IRQ:
  122. cli
  123. sbic PIND,PIND7;skip if 0
  124. rjmp leave
  125. ;sbis PIND,PIND6;skip if 1
  126. ;rcall scorebutton
  127. SEND0:
  128. sbis UCSRA,UDRE
  129. rjmp SEND0
  130. in sys,PINA //
  131. ;mov msymb1,sys //msymb1=byte1
  132. out UDR,sys //
  133. //
  134. rcall check //
  135. //
  136. SEND1:
  137. sbis UCSRA,UDRE
  138. rjmp SEND1
  139. in trns,PINB
  140. out UDR,trns
  141. //
  142. rcall check
  143. //counting msum
  144. adc sys,trns //trns=byte2, sys=byte1
  145. in msumb1, SREG
  146. sbrc msumb1,0 //skip if 0//if C in SREG = 1 => msumb2=00000001
  147. ldi msumb2,0b00000001
  148. mov msumb1,sys // msumb1= the first 8 bit of msum
  149. chksum2:
  150. sbis UCSRA,UDRE
  151. rjmp chksum2
  152. out UDR,msumb2
  153. //
  154. rcall check
  155. //
  156. chksum1:
  157. sbis UCSRA,UDRE
  158. rjmp chksum1
  159. out UDR,msumb1
  160. //
  161. rcall check
  162. //
  163. SEND2:
  164. sbis UCSRA,UDRE
  165. rjmp SEND2
  166. ldi str,0x0A
  167. out UDR,str
  168. //
  169. rcall check
  170. //
  171. SEND3:
  172. sbis UCSRA,UDRE
  173. rjmp SEND3
  174. ldi str,0x0D
  175. out UDR,str
  176. //
  177. rcall check
  178. //
  179. leave:
  180. clr sys
  181. reti
  182. check:
  183. sei
  184. push r14
  185. ldi temp,0b00001101
  186. out TCCR1B,temp
  187. receive:
  188. sbis UCSRA,RXC
  189. rjmp receive
  190. clr temp
  191. out TCCR1B,temp
  192. sbic 20, 0
  193. rjmp loop
  194. clr temp //
  195. out TCCR1B,temp
  196. in temp,UDR
  197. clr temp
  198. pop r14
  199. ret
  200.  
  201. OC1A_IRQ:
  202. clr temp
  203. out TCCR1B,temp
  204. ldi r20,0b00000001
  205. EE:
  206. sbis UCSRA,UDRE
  207. rjmp EE
  208. ldi temp,0xEE
  209. out UDR,temp
  210. reti
  211. rjmp RESET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement