GNU ARM匯編--(九)s3c2440的PWM
作者:
時(shí)間:2016-11-26
來源:網(wǎng)絡(luò)
收藏
//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內(nèi)容如下:
- #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;
- //}
- }
- */
- }
在這個(gè)例子中,既有匯編調(diào)用c,也有c調(diào)用匯編.可供以后參考.目前,串口輸入還有些問題,還得繼續(xù)調(diào)一下.串口遇到一個(gè)想不明白的問題,單單串口是正常的,但在打開PWM定時(shí)器后,串口就出問題了,打印只能出前面幾個(gè)字符,這是個(gè)神馬情況,有人知道的請(qǐng)幫我下,thks!
從代碼中有這樣的設(shè)定:
定時(shí)器的輸入時(shí)鐘為@定時(shí)器輸入時(shí)鐘周期 = PCLK/(prescaler + 1)/(divider value)
@clk = 100M/(249+1)/8=25k
TCNTB0設(shè)為200,而TCMPB0為50,則TOUT0輸出占空比為25%的方波,方波的周期為200/clk=8ms
如果有示波器,倒可以驗(yàn)證一下這個(gè)結(jié)果.如果有對(duì)朋友覺得這個(gè)方波估計(jì)的不對(duì),歡迎指出,謝謝!
技術(shù)專區(qū)
評(píng)論