GNU ARM汇编--(九)s3c2440的PWM
时间:11-26
来源:互联网
点击:
- sublr,lr,#4
- stmfdsp!,{r0-r12,lr}
- blirq_isr
- ldmfdsp!,{r0-r12,pc}^
- irq_isr:
- ldrr2,=GPBDAT
- ldrr1,=0x0e0
- strr1,[r2]
- ldrr0,=EINTPEND
- ldrr1,=0xf0
- strr1,[r0]
- ldrr0,=SRCPND
- ldrr1,=0x3ff@0b11111
- strr1,[r0]
- ldrr0,=SUBSRCPND
- ldrr1,=0x3ff@0x1<13
- strr1,[r0]
- ldrr0,=INTPND
- ldrr1,=0x3ff@0b11111
- strr1,[r0]
- movpc,lr
- delay:
- ldrr3,=0xffffff
- delay1:
- subr3,r3,#1
- cmpr3,#0x0
- bnedelay1
- movpc,lr
- clock_setup:
- ldrr0,=LOCKTIME
- ldrr1,=0xffffffff
- strr1,[r0]
- ldrr0,=CLKdivN
- ldrr1,=(divN_UPLL<3)|(HdivN<1)|(PdivN<0)
- strr1,[r0]
- ldrr0,=UPLLCON
- ldrr1,=(U_Mdiv<12)|(U_Pdiv<4)|(U_Sdiv<0)@Fin=12MUPLL=48M
- strr1,[r0]
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- ldrr0,=MPLLCON
- ldrr1,=(M_Mdiv<12)|(M_Pdiv<4)|(M_Sdiv<0)@Fin=12MFCLK=400M
- strr1,[r0]
- movpc,lr
- uart_init:
- ldrr0,=GPHCON
- ldrr1,=0x2aaaa@配置GPIO复用规则为串口
- strr1,[r0]
- ldrr0,=ULCON0
- ldrr1,=(IR_MODE<6)|(Parity_Mode<3)|(Num_of_stop_bit<2)|(Word_length<0)@
- strr1,[r0]
- ldrr0,=UCON0
- 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)
- strr1,[r0]
- ldrr0,=UFCON0
- ldrr1,=(Tx_FIFO_Trig_Level<6)|(Rx_FIFO_Trig_Level<4)|(Tx_FIFO_Reset<2)|(Rx_FIFO_Reset<1)|(FIFO_Enable<0)@
- strr1,[r0]
- ldrr0,=UBRdiv0
- ldrr1,=(UBRdiv<0)
- strr1,[r0]
- movpc,lr
- Buzzer_Freq_Set:
- //ldrr0,=GPBCON
- //ldrr1,=0x15400@这个时候暂不配置GPB0为TOUT0,这时候只是配置GPB0为TOUT0
- //strr1,[r0]
- ldrr2,=GPBDAT
- ldrr1,=0x1c1
- strr1,[r2]
- ldrr2,=GPBCON
- ldrr1,[r2]
- ldrr1,[r1]
- //ldrr1,=0x15400
- bicr1,r1,#0x3
- orrr1,r1,#0x2
- strr1,[r2]
- ldrr2,=GPBDAT
- ldrr1,=0x1a0
- strr1,[r2]
- ldrr1,=TCFG0
- ldrr2,=(Prescaler0<0)
- strr2,[r1]
- ldrr1,=TCFG1
- ldrr2,=(DMA_MODE<20)|(MUX0<0)
- strr2,[r1]
- //ldrr3,[r0]
- //strr3,[r2]
- //movr2,r0
- ldrr1,=TCNTB0
- //ldrr2,=200
- strr0,[r1]
- movr0,r0,LSR#2
- ldrr1,=TCMPB0
- //ldrr2,=50
- strr0,[r1]
- ldrr1,=TCON
- ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(man_update<1)|(start<0)
- strr2,[r1]
- ldrr1,=TCON
- ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(clear_man_update<1)|(start<0)
- strr2,[r1]
- ldrr2,=GPBDAT
- ldrr1,=0x1a0
- strr1,[r2]
- movpc,lr
- main:
- ldrr1,=TCON
- ldrr2,=(DZ_eable<4)|(auto_reload<3)|(inverter<2)|(man_update<1)|(stop<0)
- strr2,[r1]
- ldrlr,=loop
- ldrpc,_pwm_uart_test
- _pwm_uart_test:.wordpwm_uart_test
- loop:
- bloop@死循环
- undefined_instruction:
- nop
- software_interrupt:
- nop
- prefetch_abort:
- nop
- data_abort:
- nop
- not_used:
- nop
- fiq:
- nop
pwm_uart_test.c内容如下:
[cpp]view plaincopy
- #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
如果有示波器,倒可以验证一下这个结果.如果有对朋友觉得这个方波估计的不对,欢迎指出,谢谢!
ARM汇编s3c2440PW 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)