main.asm
上传用户:yinyuzhe
上传日期:2015-02-23
资源大小:542k
文件大小:7k
开发平台:

Asm

  1. ;==================================================================================
  2. ; The information contained herein is the exclusive property of
  3. ; Sunplus Technology Co. And shall not be distributed, reproduced,
  4. ; or disclosed in whole in part without prior written permission.
  5. ;       (C) COPYRIGHT 2004   SUNPLUS TECHNOLOGY CO.                                  
  6. ;                   ALL RIGHTS RESERVED
  7. ; The entire notice above must be reproduced on all authorized copies.
  8. ;==================================================================================
  9. ;==================================================================================
  10. ; Project Name :
  11. ; Applied Body : SPMC65P2404A
  12. ; Firmware version:
  13. ; Programer :
  14. ; Date : 2004-11-10
  15. ; Description : slave Communicates with master 
  16. ;
  17. ; Hardware Connect:
  18. ; Link File :
  19. ; IDE Version :  V1.6.5
  20. ; BODY Version : V1.0.0A
  21. ;==================================================================================
  22. .SYNTAX  6502 ;Process standard 6502 addressing syntax
  23. .LINKLIST ;Generate linklist information
  24. .SYMBOLS ;Generate symbolic debug information
  25. ;************************************************************************************
  26. ;* *
  27. ;*      System Register Define *
  28. ;* *
  29. ;************************************************************************************
  30. ;************************************************************************************
  31. .INCLUDE SPMC65P2404A.inc ;Define all hardware,Registers and ports.                       
  32. ;************************************************************************************
  33. ;************************************************************************************
  34. ;* *
  35. ;*      Data memory Define                                                         *
  36. ;* *
  37. ;************************************************************************************
  38. .PAGE0 ;Define values in the range from 00h to FFh
  39. ;************************************************************************************
  40. .DATA ;Define data storage section           
  41. ;************************************************************************************
  42. ;* *
  43. ;*        Program Area *
  44. ;* *
  45. ;************************************************************************************
  46. .CODE 
  47. .INCLUDE   Subprogram.asm                  
  48. ;************************************************************************************
  49. ;* *
  50. ;*      Power on Reset Process                                                     *
  51. ;* *
  52. ;************************************************************************************
  53. .PUBLIC V_Reset
  54. V_Reset:
  55. sei ;Disable interrupt
  56. ldx #C_STACK_BOTTOM ;Initial stack pointer at $00FF
  57. txs
  58. lda #C_T0FCS_Div_4
  59. sta GP_IIC_BitRate ;select the Prescaler of Timer1
  60. jsr F_Sys_Init ;initialize the I/O,Timer and clock for communication 
  61. lda #%11110011 ;require master receive data
  62. sta GB_SCommand
  63. lda #2
  64. sta GB_SCapacity ;the size of the data
  65. lda #2
  66. sta GB_SData_Addr ;store the Slaver number
  67. lda #$10
  68. sta GB_SData_Addr+1
  69. cli    
  70. L_MainLoop:
  71. jsr F_WrData ;dispose when send the data
  72. jsr F_CheckACK ;ACK check
  73. lda P_IOC_Data
  74. and #%00000001 ;if PC0=0 then clear the counter and display
  75. bne ?L_Display
  76. lda #0
  77. sta GB_TimeCnt1
  78. sta GB_DisCnt
  79. ?L_Display:
  80. lda GB_DisCnt ;display the value of the counter
  81. sta GB_SData_Addr+1
  82. ?L_Wait:
  83. lda P_INT_Flag1
  84. and #C_INT_T2OIF ;time 704us ?
  85. beq ?L_Wait ;no
  86. lda #C_INT_T2OIF
  87. sta P_INT_Flag1
  88. inc GB_CSCnt
  89. lda GB_CSCnt
  90. cmp #2
  91. bcc ?L_Count
  92. lda #0
  93. sta GB_CSCnt
  94. sta GB_INT_Cnt
  95. ?L_Count:
  96. inc GB_TimeCnt1
  97. lda GB_TimeCnt1
  98. cmp #250 ;time 0.5s
  99. bcc L_MainLoop ;no
  100. lda #0
  101. sta GB_TimeCnt1
  102. inc GB_TimeCnt2
  103. lda GB_TimeCnt2
  104. cmp #2
  105. bcc L_MainLoop
  106. lda #0
  107. sta GB_TimeCnt2
  108. inc GB_DisCnt
  109. lda GB_DisCnt
  110. cmp #$10
  111. bcc L_MainLoop
  112. lda #0
  113. sta GB_DisCnt
  114. jmp L_MainLoop
  115. ;************************************************************************************
  116. ;* *
  117. ;*      Interrupt Service Process                                                  *
  118. ;* *
  119. ;************************************************************************************
  120. V_IRQ:
  121. pha 
  122. txa
  123. pha
  124. ;===============================================================================
  125. ; Timer0 INT
  126. ;===============================================================================
  127. lda P_INT_Flag1
  128. and #C_INT_T0OIF
  129. beq ?L_IRQ_INT
  130. M_ClrSCL; ;clear SCL
  131. lda GB_INT_Cnt
  132. cmp #8
  133. bcc ?L_SendData
  134. M_SDA_Input; ;set free the SDA
  135. M_DisableT1; ;disable the Timer1
  136. inc GB_TxCnt
  137. M_BitSet GB_Flag,0; ;set the flag for check ACK
  138. jmp ?L_INT_rti
  139. ?L_SendData:
  140. asl GP_IIC_TxBuf
  141. bcs ?L_OutputH
  142. M_ClrSDA; ;SDA export '0'
  143. jmp ?L_Rising
  144. ?L_OutputH:
  145. M_SetSDA; ;SDA export '1'
  146. ?L_Rising:
  147. inc GB_INT_Cnt
  148. M_SetSCL; ;set SCL
  149. jmp ?L_INT_rti
  150. ;===============================================================================
  151. ; IRQ INT
  152. ;===============================================================================
  153. ?L_IRQ_INT:
  154. lda P_INT_Flag0
  155. and #(C_INT_IRQ0IF+C_INT_IRQ1IF)
  156. beq ?L_INT_rti
  157. lda GB_Flag
  158. and  #%10000000
  159. beq ?L_NoSart
  160. lda P_IOB_Data
  161. and #%00100000 ;check the SCL is high ?
  162. beq ?L_INT_rti ;No
  163. M_BitClr GB_Flag,7; ;start flag
  164. lda #C_IRQOpt1_IRQ1ES ;select rising edge trigger
  165. sta P_IRQ_Opt1
  166. sta P_IRQ_Opt1
  167. lda P_INT_Ctrl0
  168. ora #C_INT_IRQ1IE ;enable IRQ1
  169. sta P_INT_Ctrl0
  170. jmp ?L_INT_rti
  171. ?L_NoSart:
  172. lda #0
  173. sta GB_CSCnt
  174. lda P_IOB_Data ;
  175. and #%00010000 ; 
  176. rol a ;  + = catch one bit
  177. rol a ; /
  178. rol a ;/
  179. rol a
  180. rol GP_IIC_RxBuf
  181. inc GB_INT_Cnt
  182. lda GB_INT_Cnt
  183. cmp #8 ;catch 8 bit ?
  184. bcc ?L_INT_rti ;no
  185. M_RxData;
  186. inc GB_RxCnt
  187. M_BitClr GB_Flag,5; ;clear if receive the command
  188. lda #0
  189. sta GB_INT_Cnt
  190. lda #00 ;select rising edge trigger
  191. sta P_IRQ_Opt1
  192. sta P_IRQ_Opt1
  193. lda P_INT_Ctrl0
  194. ora #C_INT_IRQ1IE ;enable IRQ1
  195. sta P_INT_Ctrl0
  196. ?L_INT_rti:
  197. lda #(C_INT_IRQ0IF+C_INT_IRQ1IF)
  198. sta P_INT_Flag0
  199. lda #C_INT_T0OIF
  200. sta P_INT_Flag1
  201. pla 
  202. tax
  203. pla   
  204. rti           
  205. V_NMI:
  206. rti
  207. ;************************************************************************************
  208. ;* *
  209. ;*      Interrupt Vector Table *
  210. ;* *
  211. ;************************************************************************************
  212. VECTOR .SECTION
  213. DW V_NMI ;Non-mask interrupt vector(no use)
  214. DW V_Reset ;Reset vector
  215. DW V_IRQ ;IRQ interrupt vector
  216. ;************************************************************************************
  217. ;* *
  218. ;*      End of Interrupt Vector Table *
  219. ;* *
  220. ;************************************************************************************
  221. .END