GNU ARM匯編--(九)s3c2440的PWM
作者:
時間:2016-11-26
來源:網(wǎng)絡
收藏
//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@死循環(huán)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調用匯編.可供以后參考.目前,串口輸入還有些問題,還得繼續(xù)調一下.串口遇到一個想不明白的問題,單單串口是正常的,但在打開PWM定時器后,串口就出問題了,打印只能出前面幾個字符,這是個神馬情況,有人知道的請幫我下,thks!
從代碼中有這樣的設定:
定時器的輸入時鐘為@定時器輸入時鐘周期 = PCLK/(prescaler + 1)/(divider value)
@clk = 100M/(249+1)/8=25k
TCNTB0設為200,而TCMPB0為50,則TOUT0輸出占空比為25%的方波,方波的周期為200/clk=8ms
如果有示波器,倒可以驗證一下這個結果.如果有對朋友覺得這個方波估計的不對,歡迎指出,謝謝!
技術專區(qū)
看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
評論