GNU ARM汇编--(九)s3c2440的PWM
作者:
时间:2016-11-26
来源:网络
收藏
//movr2,r0ldrr1,=TCNTB0//ldrr2,=200strr0,[r1]movr0,r0,LSR#2ldrr1,=TCMPB0//ldrr2,=50strr0,[r1]ldrr1,=TCONldrr2,=(DZ_eable<<4)|(auto_reload<<3)|(inverter<<2)|(man_update<<1)|(start<<0)strr2,[r1]ldrr1,=TCONldrr2,=(DZ_eable<<4)|(auto_reload<<3)|(inverter<<2)|(clear_man_update<<1)|(start<<0)strr2,[r1]ldrr2,=GPBDATldrr1,=0x1a0strr1,[r2]movpc,lrmain:ldrr1,=TCONldrr2,=(DZ_eable<<4)|(auto_reload<<3)|(inverter<<2)|(man_update<<1)|(stop<<0)strr2,[r1]ldrlr,=loopldrpc,_pwm_uart_test_pwm_uart_test:.wordpwm_uart_testloop:bloop@死循环undefined_instruction:nopsoftware_interrupt:nopprefetch_abort:nopdata_abort:nopnot_used:nopfiq:nop
pwm_uart_test.c内容如下:
- #include"pwm_uart_test.h"
- externvoidBuzzer_Freq_Set(intfreq);
- //externvoidBuzzer_Freq_Set(void);
- charuart_GetByte(void)
- {
- while(!(rUTRSTAT0&0x1));//WaituntilTHRisempty.
- returnRdURXH0();
- }
- voiduart_GetString(char*pt)
- {
- while(*pt)
- uart_GetByte();
- }
- voiduart_SendByte(intdata)
- {
- if(data==)
- {
- while(!(rUTRSTAT0&0x2));
- WrUTXH0();
- }
- while(!(rUTRSTAT0&0x2));//WaituntilTHRisempty.
- WrUTXH0(data);
- }
- //====================================================================
- voiduart_SendString(char*pt)
- {
- while(*pt)
- uart_SendByte(*pt++);
- }
- voiduart_test(void)
- {
- charstr[20]="helloworld";
- inta=97;
- //while(1)
- //uart_SendByte(a);
- uart_SendString(str);
- chars=uart_GetByte();
- //if(s==a)
- if(s==97)
- rGPBDAT=0x1c0;
- //uart_SendByte(a);
- //uart_SendByte(97);
- //uart_SendByte(a);
- uart_SendByte((int)s);
- uart_SendByte((int)s);
- }
- voidpwm_uart_test(void)
- {
- intfreq=10;
- Buzzer_Freq_Set(freq);
- //Buzzer_Freq_Set();
- uart_SendString("start");
- /*
- inti;
- for(i=0;i<1000;i++)
- uart_SendString("wait");
- while(1)
- {
- charkey=uart_GetByte();
- uart_SendByte(key);
- if(key==a||key==A)
- {
- if(freq<2000)//lci20000
- freq+=10;
- uart_SendByte(a);
- Buzzer_Freq_Set(freq);
- }
- if(key==b||key==B)
- {
- if(freq>11)
- freq-=10;
- uart_SendByte(b);
- Buzzer_Freq_Set(freq);
- }
- //uart_SendString(" Freq=%d",freq);
- //if(key==ESC_KEY)
- //{
- //Buzzer_Stop();
- //return;
- //}
- }
- */
- }
在这个例子中,既有汇编调用c,也有c调用汇编.可供以后参考.目前,串口输入还有些问题,还得继续调一下.串口遇到一个想不明白的问题,单单串口是正常的,但在打开PWM定时器后,串口就出问题了,打印只能出前面几个字符,这是个神马情况,有人知道的请帮我下,thks!
从代码中有这样的设定:
定时器的输入时钟为@定时器输入时钟周期 = PCLK/(prescaler + 1)/(divider value)
@clk = 100M/(249+1)/8=25k
TCNTB0设为200,而TCMPB0为50,则TOUT0输出占空比为25%的方波,方波的周期为200/clk=8ms
如果有示波器,倒可以验证一下这个结果.如果有对朋友觉得这个方波估计的不对,欢迎指出,谢谢!
技术专区
评论