完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
先上代码
volatile unsigned long g_timer0_delay_conut = 0; void main(void) { DISI(); //Disable all unmasked interrupts Ny8b072a_Gpio_Init(); //Ny8b072a_Timer1_Init(); //Ny8b072a_Timer2_Init(); Ny8b072a_Timer3_Init(); ENI(); // Enable all unmasked interrupts while(1) { //CLRWDT(); // Clear WatchDog /* LED1 = ~LED1; LED2 = ~LED2; LED3 = ~LED3; LED4 = ~LED4; */ App_Delay_Ms(1000); } } //10bit count down , max 0x3FF void Ny8b072a_Timer1_Init(void) { //1MS TMRH = 0x30; // TIMER1 higt 2bit in TMRH bit4~5 m*** TMR1 = 0xE8; // Load 0xFF to TMR1 (Initial Timer1 register) low 8bit T1CR1 = C_TMR1_Reload | C_TMR1_En; // Enable Timer1, Initial value reloaded from TMR1, Non-stop mode T1CR2 = C_TMR1_ClkSrc_Inst | C_PS1_Div2; // Enable Prescaler1, Prescaler1 dividing rate = 1:2 // Timer1 clock source is instruction clock INTE |= C_INT_TMR1; // Enable Timer1 overflow interrupt } //10bit count down , max 0x3FF void Ny8b072a_Timer2_Init(void) { //500us TMRH = 0x40; //TIMER2 higt 2bit in TMRH bit6~7 m*** TMR2 = 0xF4; // Load 0xFF to TMR2 (Initial Timer2 register) low 8bit T2CR1 = C_TMR2_Reload | C_TMR2_En; // Enable Timer2, Initial value reloaded from TMR2, Non-stop mode T2CR2 = C_TMR2_ClkSrc_Inst | C_PS2_Div2; // Enable Prescaler2, Prescaler2 dividing rate = 1:2 // Timer2 clock source is instruction clock INTE |= C_INT_TMR2; // Enable Timer2 overflow interrupt } //10bit count down , max 0x3FF void Ny8b072a_Timer3_Init(void) { //50us TM3RH = 0; //TIMER3 higt 2bit in TM3RH bit4~5 m*** TMR3 = 50; // Load 0xFF to TMR3 (Initial Timer3 register) low 8bit T3CR1 = C_TMR3_Reload | C_TMR3_En; // Enable Timer3, Initial value reloaded from TMR3, Non-stop mode T3CR2 = C_TMR3_ClkSrc_Inst | C_PS3_Div2; // Enable Prescaler3, Prescaler3 dividing rate = 1:2 // Timer3 clock source is instruction clock //这里用 |= 会报错:如果其他中断讯号刚好在此时产生的话,使用 'BSR' 指令清除中断旗标有机会误清其他的中断旗标。 (201) INTE2 = C_INE_TMR3; // Enable Timer3 overflow interrupt } //! interrupt service routine void isr(void) __interrupt(0) { if(INTFbits.T1IF) { g_timer0_delay_conut ++; if(500 == g_timer0_delay_conut ) //1MS * 500 = 500ms { LED1 ^= 1; g_timer0_delay_conut= 0; } INTF= (unsigned char)~(C_INT_TMR1); // Clear T1IF flag bit } if(INTFbits.T2IF) { g_timer0_delay_conut ++; if(1000 == g_timer0_delay_conut ) //500us * 1000 = 500ms { LED1 ^= 1; g_timer0_delay_conut = 0; } INTF= (unsigned char)~(C_INT_TMR2); // Clear T2IF flag bit } if(INTE2bits.T3IF) { g_timer0_delay_conut ++; if(10000 == g_timer0_delay_conut )//50us * 10000 = 500ms { LED1 ^= 1; g_timer0_delay_conut = 0; } INTE2= (unsigned char)~(C_INF_TMR3); // Clear T3IF flag bit } }
800 000 / 4 / 2 = 50us 1 / 0001 / 4 / 2 = 50us 1 / 0000 = 1us 1 这计算000005 55 需要00000000000每一次的中断时间; 中断中1000 ==频率时间0_delay_需要的时间50 * 10 000000000000000000000000000000000000000000000000000000000000000000 美元个人不建议使用简单的时间 来说明自己的价值设置(我们),非常真实的 G 很容易显示出BU的真实价值。 |
||||||
|
||||||
只有小组成员才能发言,加入小组>>
3314 浏览 9 评论
2995 浏览 16 评论
3494 浏览 1 评论
9059 浏览 16 评论
4088 浏览 18 评论
1179浏览 3评论
605浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
599浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2335浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1896浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 14:48 , Processed in 1.146300 second(s), Total 77, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号