数据手册上说应该先写低字节,再写高字节
因为在写低字节的同时,监时寄存器的内容会写入高字节.但是我看AVR-GCC编译后的汇编语言是这样的: void timer1_init(void) { 1c2: cf 93 push r28 1c4: df 93 push r29 1c6: cd b7 in r28, 0x3d ; 61 1c8: de b7 in r29, 0x3e ; 62 DDRD |= _BV(PD5); 1ca: 80 91 31 00 lds r24, 0x0031 1ce: 80 62 ori r24, 0x20 ; 32 1d0: 80 93 31 00 sts 0x0031, r24 TCCR1A = 0x00; 1d4: 10 92 4f 00 sts 0x004F, r1 TCCR1B = 0x00; //start 1d8: 10 92 4e 00 sts 0x004E, r1 TCNT1L = 0x00; 1dc: 10 92 4c 00 sts 0x004C, r1 TCNT1H = 0x00; //REG = 65536 - (Fosc/分频)/Fobj) 1e0: 10 92 4d 00 sts 0x004D, r1 //OCR1AL = 0X00; //OCR1AH = 0X00; //OCR1AL = 0XFF; //OCR1AH = 0XEF; OCR1A = 0XEFff; 1e4: 8f ef ldi r24, 0xFF ; 255 1e6: 9f ee ldi r25, 0xEF ; 239 1e8: 90 93 4b 00 sts 0x004B, r25 1ec: 80 93 4a 00 sts 0x004A, r24 ICR1L = 0XFF; 1f0: 8f ef ldi r24, 0xFF ; 255 1f2: 80 93 46 00 sts 0x0046, r24 ICR1H = 0XFF; 1f6: 8f ef ldi r24, 0xFF ; 255 1f8: 80 93 47 00 sts 0x0047, r24
TCCR1A = 0x82; 1fc: 82 e8 ldi r24, 0x82 ; 130 1fe: 80 93 4f 00 sts 0x004F, r24 TCCR1B = 0x19; //start 202: 89 e1 ldi r24, 0x19 ; 25 204: 80 93 4e 00 sts 0x004E, r24 TIMSK = TIMSK | 0X10; 208: 80 91 59 00 lds r24, 0x0059 20c: 80 61 ori r24, 0x10 ; 16 20e: 80 93 59 00 sts 0x0059, r24 212: df 91 pop r29 214: cf 91 pop r28 216: 08 95 ret
00000218 <disable_timer1>: }
很明显编译后汇编是先写高字节再写低字节. 以上这一段代码是快速PWM模式14,比较匹配时OC1A清零,在TOP时置位.
程序将OCR1A赋值:0XEFFF,但是软件仿真是,执行OCR1A = 0XEFFF后, OCR1A寄存器的值为0x01ff,真不明白错在哪里?
OC1A引脚也没有输入想象中的波形,匹配中断可以正常产生,不知哪里出错,请大家帮忙! |
|