微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > GNU ARM汇编--(九)s3c2440的PWM

GNU ARM汇编--(九)s3c2440的PWM

时间:11-26 来源:互联网 点击:

  1. sublr,lr,#4
  2. stmfdsp!,{r0-r12,lr}
  3. blirq_isr
  4. ldmfdsp!,{r0-r12,pc}^
  5. irq_isr:
  6. ldrr2,=GPBDAT
  7. ldrr1,=0x0e0
  8. strr1,[r2]
  9. ldrr0,=EINTPEND
  10. ldrr1,=0xf0
  11. strr1,[r0]
  12. ldrr0,=SRCPND
  13. ldrr1,=0x3ff@0b11111
  14. strr1,[r0]
  15. ldrr0,=SUBSRCPND
  16. ldrr1,=0x3ff@0x1<13
  17. strr1,[r0]
  18. ldrr0,=INTPND
  19. ldrr1,=0x3ff@0b11111
  20. strr1,[r0]
  21. movpc,lr
  22. delay:
  23. ldrr3,=0xffffff
  24. delay1:
  25. subr3,r3,#1
  26. cmpr3,#0x0
  27. bnedelay1
  28. movpc,lr
  29. clock_setup:
  30. ldrr0,=LOCKTIME
  31. ldrr1,=0xffffffff
  32. strr1,[r0]
  33. ldrr0,=CLKdivN
  34. ldrr1,=(divN_UPLL<3)|(HdivN<1)|(PdivN<0)
  35. strr1,[r0]
  36. ldrr0,=UPLLCON
  37. ldrr1,=(U_Mdiv<12)|(U_Pdiv<4)|(U_Sdiv<0)@Fin=12MUPLL=48M
  38. strr1,[r0]
  39. nop
  40. nop
  41. nop
  42. nop
  43. nop
  44. nop
  45. nop
  46. ldrr0,=MPLLCON
  47. ldrr1,=(M_Mdiv<12)|(M_Pdiv<4)|(M_Sdiv<0)@Fin=12MFCLK=400M
  48. strr1,[r0]
  49. movpc,lr
  50. uart_init:
  51. ldrr0,=GPHCON
  52. ldrr1,=0x2aaaa@配置GPIO复用规则为串口
  53. strr1,[r0]
  54. ldrr0,=ULCON0
  55. ldrr1,=(IR_MODE<6)|(Parity_Mode<3)|(Num_of_stop_bit<2)|(Word_length<0)@
  56. strr1,[r0]
  57. ldrr0,=UCON0
  58. 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)
  59. strr1,[r0]
  60. ldrr0,=UFCON0
  61. ldrr1,=(Tx_FIFO_Trig_Level<6)|(Rx_FIFO_Trig_Level<4)|(Tx_FIFO_Reset<2)|(Rx_FIFO_Reset<1)|(FIFO_Enable<0)@
  62. strr1,[r0]
  63. ldrr0,=UBRdiv0
  64. ldrr1,=(UBRdiv<0)
  65. strr1,[r0]
  66. movpc,lr
  67. Buzzer_Freq_Set:
  68. //ldrr0,=GPBCON
  69. //ldrr1,=0x15400@这个时候暂不配置GPB0为TOUT0,这时候只是配置GPB0为TOUT0
  70. //strr1,[r0]
  71. ldrr2,=GPBDAT
  72. ldrr1,=0x1c1
  73. strr1,[r2]
  74. ldrr2,=GPBCON
  75. ldrr1,[r2]
  76. ldrr1,[r1]
  77. //ldrr1,=0x15400
  78. bicr1,r1,#0x3
  79. orrr1,r1,#0x2
  80. strr1,[r2]
  81. ldrr2,=GPBDAT
  82. ldrr1,=0x1a0
  83. strr1,[r2]
  84. ldrr1,=TCFG0
  85. ldrr2,=(Prescaler0<0)
  86. strr2,[r1]
  87. ldrr1,=TCFG1
  88. ldrr2,=(DMA_MODE<20)|(MUX0<0)
  89. strr2,[r1]
  90. //ldrr3,[r0]
  91. //strr3,[r2]
  92. //movr2,r0
  93. ldrr1,=TCNTB0
  94. //ldrr2,=200
  95. strr0,[r1]
  96. movr0,r0,LSR#2
  97. ldrr1,=TCMPB0
  98. //ldrr2,=50
  99. strr0,[r1]
  100. ldrr1,=TCON
  101. ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(man_update<1)|(start<0)
  102. strr2,[r1]
  103. ldrr1,=TCON
  104. ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(clear_man_update<1)|(start<0)
  105. strr2,[r1]
  106. ldrr2,=GPBDAT
  107. ldrr1,=0x1a0
  108. strr1,[r2]
  109. movpc,lr
  110. main:
  111. ldrr1,=TCON
  112. ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(man_update<1)|(stop<0)
  113. strr2,[r1]
  114. ldrlr,=loop
  115. ldrpc,_pwm_uart_test
  116. _pwm_uart_test:.wordpwm_uart_test
  117. loop:
  118. bloop@死循环
  119. undefined_instruction:
  120. nop
  121. software_interrupt:
  122. nop
  123. prefetch_abort:
  124. nop
  125. data_abort:
  126. nop
  127. not_used:
  128. nop
  129. fiq:
  130. nop

pwm_uart_test.c内容如下:

[cpp]view plaincopy

  1. #include"pwm_uart_test.h"
  2. externvoidBuzzer_Freq_Set(intfreq);
  3. //externvoidBuzzer_Freq_Set(void);
  4. charuart_GetByte(void)
  5. {
  6. while(!(rUTRSTAT0&0x1));//WaituntilTHRisempty.
  7. returnRdURXH0();
  8. }
  9. voiduart_GetString(char*pt)
  10. {
  11. while(*pt)
  12. uart_GetByte();
  13. }
  14. voiduart_SendByte(intdata)
  15. {
  16. if(data==)
  17. {
  18. while(!(rUTRSTAT0&0x2));
  19. WrUTXH0();
  20. }
  21. while(!(rUTRSTAT0&0x2));//WaituntilTHRisempty.
  22. WrUTXH0(data);
  23. }
  24. //====================================================================
  25. voiduart_SendString(char*pt)
  26. {
  27. while(*pt)
  28. uart_SendByte(*pt++);
  29. }
  30. voiduart_test(void)
  31. {
  32. charstr[20]="helloworld";
  33. inta=97;
  34. //while(1)
  35. //uart_SendByte(a);
  36. uart_SendString(str);
  37. chars=uart_GetByte();
  38. //if(s==a)
  39. if(s==97)
  40. rGPBDAT=0x1c0;
  41. //uart_SendByte(a);
  42. //uart_SendByte(97);
  43. //uart_SendByte(a);
  44. uart_SendByte((int)s);
  45. uart_SendByte((int)s);
  46. }
  47. voidpwm_uart_test(void)
  48. {
  49. intfreq=10;
  50. Buzzer_Freq_Set(freq);
  51. //Buzzer_Freq_Set();
  52. uart_SendString("start");
  53. /*
  54. inti;
  55. for(i=0;i<1000;i++)
  56. uart_SendString("wait");
  57. while(1)
  58. {
  59. charkey=uart_GetByte();
  60. uart_SendByte(key);
  61. if(key==a||key==A)
  62. {
  63. if(freq<2000)//lci20000
  64. freq+=10;
  65. uart_SendByte(a);
  66. Buzzer_Freq_Set(freq);
  67. }
  68. if(key==b||key==B)
  69. {
  70. if(freq>11)
  71. freq-=10;
  72. uart_SendByte(b);
  73. Buzzer_Freq_Set(freq);
  74. }
  75. //uart_SendString(" Freq=%d",freq);
  76. //if(key==ESC_KEY)
  77. //{
  78. //Buzzer_Stop();
  79. //return;
  80. //}
  81. }
  82. */
  83. }


在这个例子中,既有汇编调用c,也有c调用汇编.可供以后参考.目前,串口输入还有些问题,还得继续调一下.串口遇到一个想不明白的问题,单单串口是正常的,但在打开PWM定时器后,串口就出问题了,打印只能出前面几个字符,这是个神马情况,有人知道的请帮我下,thks!

从代码中有这样的设定:

定时器的输入时钟为@定时器输入时钟周期 = PCLK/(prescaler + 1)/(divider value)
@clk = 100M/(249+1)/8=25k

TCNTB0设为200,而TCMPB0为50,则TOUT0输出占空比为25%的方波,方波的周期为200/clk=8ms

如果有示波器,倒可以验证一下这个结果.如果有对朋友觉得这个方波估计的不对,欢迎指出,谢谢!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top