新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應用 > GNU ARM匯編--(九)s3c2440的PWM

GNU ARM匯編--(九)s3c2440的PWM

作者: 時間:2016-11-26 來源:網(wǎng)絡 收藏
  1. /*
  2. copyleft@dndxhej@gmail.com
  3. */
  4. .equNOINT,0xc0
  5. .equGPBCON,0x56000010@led
  6. .equGPBDAT,0x56000014@led
  7. .equGPBUP,0x56000018@led
  8. .equGPFCON,0x56000050@interruptconfig
  9. .equEINTMASK,0x560000a4
  10. .equEXTINT0,0x56000088
  11. .equEXTINT1,0x5600008c
  12. .equEXTINT2,0x56000090
  13. .equINTMSK,0x4A000008
  14. .equEINTPEND,0x560000a8
  15. .equSUBSRCPND,0x4a000018
  16. .equINTSUBMSK,0x4a00001c
  17. .equSRCPND,0X4A000000
  18. .equINTPND,0X4A000010
  19. .equGPHCON,0x56000070
  20. .equGPHDAT,0x56000074
  21. .equGPB5_out,(1<<(5*2))
  22. .equGPB6_out,(1<<(6*2))
  23. .equGPB7_out,(1<<(7*2))
  24. .equGPB8_out,(1<<(8*2))
  25. .equGPBVALUE,(GPB5_out|GPB6_out|GPB7_out|GPB8_out)
  26. .equLOCKTIME,0x4c000000
  27. .equMPLLCON,0x4c000004
  28. .equUPLLCON,0x4c000008
  29. .equM_MDIV,92
  30. .equM_PDIV,1
  31. .equM_SDIV,1
  32. .equU_MDIV,56
  33. .equU_PDIV,2
  34. .equU_SDIV,2
  35. .equCLKDIVN,0x4c000014
  36. .equDIVN_UPLL,0
  37. .equHDIVN,1
  38. .equPDIVN,1@FCLK:HCLK:PCLK=1:2:4
  39. .equWTCON,0x53000000
  40. .equPre_scaler,249
  41. .equwd_timer,1
  42. .equclock_select,00@316
  43. .equint_gen,1@開中斷
  44. .equreset_enable,0@關(guān)掉重啟信號
  45. .equWTDAT,0x53000004
  46. .equCount_reload,50000@定時器定為2SPCLK=100MPCLK/(Pre_scaler+1)/clock_select=100M/(249+1)/16=25k50000/25k=2s
  47. .equWTCNT,0x53000008
  48. .equCount,50000
  49. .equTCFG0,0x51000000
  50. .equPrescaler1,0x00@[15:8]Timer234
  51. .equPrescaler0,249@[7:0]Timer01
  52. .equTCFG1,0x51000004
  53. .equDMA_MODE,0x0@[23:20]nodmachannal
  54. .equMUX0,0x2@[3:0]1/8
  55. @定時器輸入時鐘周期=PCLK/(prescaler+1)/(dividervalue)
  56. @clk=100M/(249+1)/8=25k
  57. .equTCON,0x51000008
  58. .equDZ_eable,0@[4]關(guān)閉死區(qū)的操作
  59. .equauto_reload,1@[3]auto_reload
  60. .equinverter,1@[2]打開電平反轉(zhuǎn)
  61. .equman_update,1@[1]手動更新
  62. .equclear_man_update,0
  63. .equstart,1@[0]開始
  64. .equstop,0@[0]停止
  65. .equTCNTB0,0x5100000c
  66. .equTCMPB0,0x51000010
  67. .equTCNTO0,0x51000014
  68. .equULCON0,0x50000000
  69. .equIR_MODE,0x0@[6]正常模式
  70. .equParity_Mode,0x0@[5:3]無校驗位
  71. .equNum_of_stop_bit,0x0@[2]一個停止位
  72. .equWord_length,0b11@[1:0]8個數(shù)據(jù)位
  73. .equUCON0,0x50000004
  74. .equFCLK_Div,0@[15:12]時鐘源選擇用PCLK,所以這里用默認值
  75. .equClk_select,0b00@[11:10]時鐘源選擇使用PCLK
  76. .equTx_Int_Type,1@[9]中斷請求類型為Level
  77. .equRx_Int_Type,0@1@[8]中斷請求類型為Level
  78. .equRx_Timeout,0@[7]
  79. .equRx_Error_Stat_Int,1@[6]
  80. .equLoopback_Mode,0@[5]正常模式
  81. .equBreak_Sig,0@[4]不發(fā)送終止信號
  82. .equTx_Mode,0b01@[3:2]中斷請求或輪循模式
  83. .equRx_Mode,0b01@[1:0]中斷請求或輪循模式
  84. .equUFCON0,0x50000008
  85. .equTx_FIFO_Trig_Level,0b00@[7:6]
  86. .equRx_FIFO_Trig_Level,0b00@[5:4]
  87. .equTx_FIFO_Reset,0b0@[2]
  88. .equRx_FIFO_Reset,0b0@[1]
  89. .equFIFO_Enable,0b0@[0]非FIFO模式
  90. .equUMCON0,0x5000000C@這個寄存器可以不管的
  91. .equUTRSTAT0,0x50000010
  92. .equUERSTAT0,0x50000014
  93. .equUFSTAT0,0x50000018
  94. .equUMSTAT0,0x5000001C
  95. .equUTXH0,0x50000020@(L小端)
  96. .equURXH0,0x50000024@(L小端)
  97. .equUBRDIV0,0x50000028
  98. .equUBRDIV,0x35@PCLK=400M/4=100MUBRDIV=(int)(100M/115200/16)-1=53=0x35
  99. .globalBuzzer_Freq_Set
  100. .global_start
  101. _start:breset
  102. ldrpc,_undefined_instruction
  103. ldrpc,_software_interrupt
  104. ldrpc,_prefetch_abort
  105. ldrpc,_data_abort
  106. ldrpc,_not_used
  107. @birq
  108. ldrpc,_irq
  109. ldrpc,_fiq
  110. _undefined_instruction:.wordundefined_instruction
  111. _software_interrupt:.wordsoftware_interrupt
  112. _prefetch_abort:.wordprefetch_abort
  113. _data_abort:.worddata_abort
  114. _not_used:.wordnot_used
  115. _irq:.wordirq
  116. _fiq:.wordfiq
  117. .balignl16,0xdeadbeef
  118. reset:
  119. ldrr3,=WTCON
  120. movr4,#0x0
  121. strr4,[r3]@disablewatchdog
  122. ldrr0,=GPBCON
  123. ldrr1,=0x15400@這個時候暫不配置GPB0為TOUT0,這時候只是配置GPB0為TOUT0
  124. strr1,[r0]
  125. ldrr2,=GPBDAT
  126. ldrr1,=0x160
  127. strr1,[r2]
  128. blclock_setup
  129. bluart_init
  130. //bldelay
  131. msrcpsr_c,#0xd2@進入中斷模式
  132. ldrsp,=3072@中斷模式的棧指針定義
  133. msrcpsr_c,#0xd3@進入系統(tǒng)模式
  134. ldrsp,=4096@設(shè)置系統(tǒng)模式的棧指針
  135. @--------------------------------------------
  136. ldrr0,=GPBUP
  137. ldrr1,=0x03f0
  138. strr1,[r0]
  139. ldrr0,=GPFCON
  140. ldrr1,=0x2ea@0x2
  141. strr1,[r0]
  142. ldrr0,=EXTINT0
  143. @ldrr1,=0x8f888@0x0@0x8f888@~(7|(7<<4)|(7<<8)|(7<<16))//低電平觸發(fā)中斷
  144. ldrr1,=0xafaaa@0x0@0x8f888//下降沿觸發(fā)中斷
  145. strr1,[r0]
  146. ldrr0,=EINTPEND
  147. ldrr1,=0xf0@0b10000
  148. strr1,[r0]
  149. ldrr0,=EINTMASK
  150. ldrr1,=0x00@0b00000
  151. strr1,[r0]
  152. ldrr0,=SRCPND
  153. ldrr1,=0x3ff@0x1@0b11111
  154. strr1,[r0]
  155. ldrr0,=SUBSRCPND
  156. ldrr1,=0x1<<13
  157. strr1,[r0]
  158. ldrr0,=INTPND
  159. ldrr1,=0x3ff@0x1@0b11111
  160. strr1,[r0]
  161. ldrr0,=INTSUBMSK
  162. ldrr1,=0x0<<13
  163. strr1,[r0]
  164. ldrr0,=INTMSK
  165. ldrr1,=0xfffff000@0b00000
  166. strr1,[r0]
  167. MRSr1,cpsr
  168. BICr1,r1,#0x80
  169. MSRcpsr_c,r1
  170. blmain
  171. irq:
  172. sublr,lr,#4
  173. stmfdsp!,{r0-r12,lr}
  174. blirq_isr
  175. ldmfdsp!,{r0-r12,pc}^
  176. irq_isr:
  177. ldrr2,=GPBDAT
  178. ldrr1,=0x0e0
  179. strr1,[r2]
  180. ldrr0,=EINTPEND
  181. ldrr1,=0xf0
  182. strr1,[r0]
  183. ldrr0,=SRCPND
  184. ldrr1,=0x3ff@0b11111
  185. strr1,[r0]
  186. ldrr0,=SUBSRCPND
  187. ldrr1,=0x3ff@0x1<<13
  188. strr1,[r0]
  189. ldrr0,=INTPND
  190. ldrr1,=0x3ff@0b11111
  191. strr1,[r0]
  192. movpc,lr
  193. delay:
  194. ldrr3,=0xffffff
  195. delay1:
  196. subr3,r3,#1
  197. cmpr3,#0x0
  198. bnedelay1
  199. movpc,lr
  200. clock_setup:
  201. ldrr0,=LOCKTIME
  202. ldrr1,=0xffffffff
  203. strr1,[r0]
  204. ldrr0,=CLKDIVN
  205. ldrr1,=(DIVN_UPLL<<3)|(HDIVN<<1)|(PDIVN<<0)
  206. strr1,[r0]
  207. ldrr0,=UPLLCON
  208. ldrr1,=(U_MDIV<<12)|(U_PDIV<<4)|(U_SDIV<<0)@Fin=12MUPLL=48M
  209. strr1,[r0]
  210. nop
  211. nop
  212. nop
  213. nop
  214. nop
  215. nop
  216. nop
  217. ldrr0,=MPLLCON
  218. ldrr1,=(M_MDIV<<12)|(M_PDIV<<4)|(M_SDIV<<0)@Fin=12MFCLK=400M
  219. strr1,[r0]
  220. movpc,lr
  221. uart_init:
  222. ldrr0,=GPHCON
  223. ldrr1,=0x2aaaa@配置GPIO復用規(guī)則為串口
  224. strr1,[r0]
  225. ldrr0,=ULCON0
  226. ldrr1,=(IR_MODE<<6)|(Parity_Mode<<3)|(Num_of_stop_bit<<2)|(Word_length<<0)@
  227. strr1,[r0]
  228. ldrr0,=UCON0
  229. ldrr1,=(FCLK_Div<<12)|(Clk_select<<10)|(Tx_Int_Type<<9)|(Rx_Int_Type<<8)|(Rx_Timeout<<7)|(Rx_Error_Stat_Int<<6)|(Loopback_Mode<<5)|(Break_Sig<<4)|(Tx_Mode<<2)|(Rx_Mode<<0)
  230. strr1,[r0]
  231. ldrr0,=UFCON0
  232. ldrr1,=(Tx_FIFO_Trig_Level<<6)|(Rx_FIFO_Trig_Level<<4)|(Tx_FIFO_Reset<<2)|(Rx_FIFO_Reset<<1)|(FIFO_Enable<<0)@
  233. strr1,[r0]
  234. ldrr0,=UBRDIV0
  235. ldrr1,=(UBRDIV<<0)
  236. strr1,[r0]
  237. movpc,lr
  238. Buzzer_Freq_Set:
  239. //ldrr0,=GPBCON
  240. //ldrr1,=0x15400@這個時候暫不配置GPB0為TOUT0,這時候只是配置GPB0為TOUT0
  241. //strr1,[r0]
  242. ldrr2,=GPBDAT
  243. ldrr1,=0x1c1
  244. strr1,[r2]
  245. ldrr2,=GPBCON
  246. ldrr1,[r2]
  247. ldrr1,[r1]
  248. //ldrr1,=0x15400
  249. bicr1,r1,#0x3
  250. orrr1,r1,#0x2
  251. strr1,[r2]
  252. ldrr2,=GPBDAT
  253. ldrr1,=0x1a0
  254. strr1,[r2]
  255. ldrr1,=TCFG0
  256. ldrr2,=(Prescaler0<<0)
  257. strr2,[r1]
  258. ldrr1,=TCFG1
  259. ldrr2,=(DMA_MODE<<20)|(MUX0<<0)
  260. strr2,[r1]
  261. //ldrr3,[r0]
  262. //strr3,[r2]


關(guān)鍵詞: ARM匯編s3c2440PW

評論


技術(shù)專區(qū)

關(guān)閉