完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位大侠!请指点。
以下时我的main.c /**************************************************************************//** * main.c * V2.10 * $Date: 13/10/07 3:56p $ * MINI51 Series General Purpose I/O Driver Sample Code * * @note * Copyright (C) 2012 Nuvoton Technology Corp. All rights reserved. * ******************************************************************************/ #include "stdio.h" #include "Mini51Series.h" #include "GPIO.h" #include "custom.h" void WDT_IRQHandler(void) { // Clear WDT interrupt flag WDT_CLEAR_tiMEOUT_INT_FLAG(); // Check WDT wake up flag if(WDT_GET_RESET_FLAG()) { WDT_CLEAR_RESET_FLAG(); } } void UART_IRQHandler(void) { vu32 uart_isr_back; vu32 uart_fsr_back; uart_isr_back=UART->ISR; uart_fsr_back=UART->FSR; if(UART->ISR&UART_ISR_RDA_INT_Msk) { while(UART->ISR&UART_ISR_RDA_IF_Msk) while(!(UART->FSR&UART_FSR_RX_EMPTY_Msk)) { if(++uart_rxcnt>uart_buffer_size) { uart_rxcnt=uart_buffer_size; return; } uart_data_buffer[uart_rxin]=UART->RBR; if(++uart_rxin>=uart_buffer_size) uart_rxin=0; } } } void TMR0_IRQHandler(void) { vu8 i; ///20ms TIMER_ClearIntFlag(TIMER0); flag_check_key=1; M62429_SDA=~M62429_SDA; } void TMR1_IRQHandler(void) { ///190us TIMER_ClearIntFlag(TIMER1); M62429_SCL=~M62429_SCL; } /** * @brief Port0/Port1 IRQ * * @param None * * @return None * * @details The Port0/Port1 default IRQ, declared in startup_Mini51.s. */ void GPIO01_IRQHandler(void) { } /** * @brief Port2/Port3/Port4 IRQ * * @param None * * @return None * * @details The Port2/Port3/Port4 default IRQ, declared in startup_Mini51.s. */ void GPIO234_IRQHandler(void) { P3->ISRC = 0x10; } /** * @brief External INT0 IRQ * * @param None * * @return None * * @details The External INT0(P3.2) default IRQ, declared in startup_Mini51.s. */ void EINT0_IRQHandler(void) { } /** * @brief External INT1 IRQ * * @param None * * @return None * * @details The External INT1(P5.2) default IRQ, declared in startup_Mini51.s. */ void EINT1_IRQHandler(void) { } void SYS_Init(void) { /* Unlock protected registers */ SYS_UnlockReg(); #if 1 /* Set P5 multi-function pins for XTAL1 and XTAL2 */ SYS->P5_MFP &= ~(SYS_MFP_P50_Msk | SYS_MFP_P51_Msk); SYS->P5_MFP |= (SYS_MFP_P50_XTAL1 | SYS_MFP_P51_XTAL2); /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable external 12MHz XTAL, internal 22.1184MHz */ CLK->PWRCON |= CLK_PWRCON_XTL12M |CLK_PWRCON_IRC22M_EN_Msk|CLK_PWRCON_IRC10K_EN_Msk; /* Waiting for clock ready */ // CLK_WaitClockReady(CLK_CLKSTATUS_XTL_STB_Msk | CLK_CLKSTATUS_IRC22M_STB_Msk|CLK_CLKSTATUS_IRC10K_STB_Msk); CLK_WaitClockReady(CLK_CLKSTATUS_IRC22M_STB_Msk|CLK_CLKSTATUS_IRC10K_STB_Msk); /* Switch HCLK clock source to XTL */ CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_IRC22M,CLK_CLKDIV_HCLK(1)); /* STCLK to XTL STCLK to XTL */ CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLK_S_HCLK_DIV2); #endif /* Enable IP clock */ CLK_EnableModuleClock(UART_MODULE); CLK_EnableModuleClock(PWM01_MODULE); // CLK_EnableModuleClock(WDT_MODULE); /* Select IP clock source */ CLK_SetModuleClock(UART_MODULE,CLK_CLKSEL1_UART_S_IRC22M,CLK_CLKDIV_UART(1)); // CLK_SetModuleClock(WDT_MODULE,CLK_CLKSEL1_WDT_S_IRC10K,CLK_CLKDIV_UART(1)); CLK_SetModuleClock(TMR0_MODULE,CLK_CLKSEL1_TMR0_S_HCLK,0); CLK_SetModuleClock(TMR1_MODULE,CLK_CLKSEL1_TMR1_S_HCLK,0); // CLK_SetModuleClock(TMR0_MODULE,CLK_CLKSEL1_TMR0_S_HCLK,0); #if 1 /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set P0 multi-function pins for UART RXD and TXD */ SYS->P1_MFP &= ~(SYS_MFP_P12_Msk | SYS_MFP_P13_Msk); SYS->P1_MFP |= (SYS_MFP_P12_RXD | SYS_MFP_P13_TXD); /* Set P2 multi-function pins for PWM Channel 0~4 */ SYS->P2_MFP = (SYS_MFP_P23_PWM1 ); SYS->P4_MFP &= ~(SYS_MFP_P46_Msk | SYS_MFP_P47_Msk); SYS->P4_MFP |= (SYS_MFP_P46_GPIO | SYS_MFP_P47_GPIO); #endif /* To update the variable SystemCoreClock */ SystemCoreClockUpdate(); /* Lock protected registers */ SYS_LockReg(); } void UART_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ /* Reset IP */ SYS_ResetModule(SYS_IPRSTC2_UART_RST_Msk); /* Configure UART and set UART Baudrate */ UART_Open(UART, 9600); } /*---------------------------------------------------------------------------------------------------------*/ /* MAIN function */ /*---------------------------------------------------------------------------------------------------------*/ int main (void) { // int32_t i32Err; /* Init System, IP clock and multi-function I/O */ SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. /* Init UART for printf */ UART_Init(); CONTROL4=0; CONTROL3=0; UNLOCK=0; V5_CTRL=0; V9_CTRL=0; GPIO_SetMode(P0, BIT0, GPIO_PMD_OUTPUT); GPIO_SetMode(P0, BIT1, GPIO_PMD_OUTPUT); GPIO_SetMode(P0, BIT5, GPIO_PMD_OUTPUT); GPIO_SetMode(P0, BIT6, GPIO_PMD_OUTPUT); GPIO_SetMode(P0, BIT7, GPIO_PMD_OUTPUT); MASTER_DETECT=0; GPIO_SetMode(P0, BIT4, GPIO_PMD_INPUT); CONTROL2=0; DOOR2_SEL=0; DOOR1_SEL=0; GPIO_SetMode(P1, BIT0, GPIO_PMD_OUTPUT); GPIO_SetMode(P1, BIT4, GPIO_PMD_OUTPUT); GPIO_SetMode(P1, BIT5, GPIO_PMD_OUTPUT); RING_ON=0; MIC_CTRL=0; GPIO_SetMode(P2, BIT2, GPIO_PMD_OUTPUT); GPIO_SetMode(P2, BIT6, GPIO_PMD_OUTPUT); DOOR1_CALL=0; DOOR2_CALL=0; GPIO_SetMode(P2, BIT4, GPIO_PMD_INPUT); GPIO_SetMode(P2, BIT5, GPIO_PMD_INPUT); PORT1=0; PORT2=0; PORT3=0; GPIO_SetMode(P3, BIT0, GPIO_PMD_OUTPUT); GPIO_SetMode(P3, BIT1, GPIO_PMD_OUTPUT); GPIO_SetMode(P3, BIT2, GPIO_PMD_OUTPUT); AUDIO12_CTRL=0; AUDIO_CRTL=0; GPIO_SetMode(P3, BIT5, GPIO_PMD_INPUT); GPIO_SetMode(P3, BIT6, GPIO_PMD_INPUT); M62429_SCL=0; M62429_SDA=0; GPIO_SetMode(P4, BIT6, GPIO_PMD_OUTPUT); GPIO_SetMode(P4, BIT7, GPIO_PMD_OUTPUT); MUSIC_DATA=0; MUSIC_RST=0; CONTROL1=0; LED_CTRL=0; GPIO_SetMode(P5, BIT0, GPIO_PMD_OUTPUT); GPIO_SetMode(P5, BIT1, GPIO_PMD_OUTPUT); GPIO_SetMode(P5, BIT3, GPIO_PMD_OUTPUT); GPIO_SetMode(P5, BIT4, GPIO_PMD_OUTPUT); MUSIC_BUSY=0; GPIO_SetMode(P5, BIT4, GPIO_PMD_INPUT); MCU_DATA=0; GPIO_SetMode(P3, BIT4, GPIO_PMD_INPUT); ////data-in GPIO_EnableInt(P3, 4, GPIO_INT_RISING); /* Enable interrupt de-bounce function and select de-bounce sampling cycle time */ GPIO_SET_DEBOUNCE_TIME(GPIO_DBNCECON_DBCLKSRC_HCLK, GPIO_DBNCECON_DBCLKSEL_1); GPIO_ENABLE_DEBOUNCE(P3, BIT4); #if 1 CLK_EnableModuleClock(TMR0_MODULE); TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 30); // Update prescale and compare value to what we need in event counter mode. TIMER_SET_PRESCALE_VALUE(TIMER0, 40); TIMER_SET_CMP_VALUE(TIMER0, 10000); ////1000-50us 2000-100us // Counter increase on falling edge // TIMER_EnableEventCounter(TIMER0, TIMER_COUNTER_FALLING_EDGE); // Start Timer 0 TIMER_Start(TIMER0); // Enable timer interrupt TIMER_EnableInt(TIMER0); NVIC_EnableIRQ(TMR0_IRQn); SYS_ResetModule(SYS_IPRSTC2_TMR1_RST_Msk); CLK_EnableModuleClock(TMR1_MODULE); #if 1 TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, 100); // TIMER_SET_PRESCALE_VALUE(TIMER1, 40); // Update prescale and compare value to what we need in event counter mode. TIMER_SET_CMP_VALUE(TIMER1, 1900); // Counter increase on falling edge // TIMER_EnableEventCounter(TIMER0, TIMER_COUNTER_FALLING_EDGE); #endif // Start Timer 0 TIMER_Start(TIMER1); // Enable timer interrupt TIMER_EnableInt(TIMER1); NVIC_EnableIRQ(TMR1_IRQn); UART_ENABLE_INT(UART, (UART_IER_RDA_IEN_Msk)); NVIC_EnableIRQ(UART_IRQn); // PWM2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWM, 1, 2360, 50); // Enable output of all PWM channels PWM_EnableOutput(PWM, 0x02); // PWM_Start(PWM, 0x02); #endif init_custom(); /* Waiting for interrupts */ while (1) { ; } } 只要我的外部晶振不启动, /* Enable external 12MHz XTAL, internal 22.1184MHz */ CLK->PWRCON |=CLK_PWRCON_IRC22M_EN_Msk|CLK_PWRCON_IRC10K_EN_Msk; 我的timer0和timer1就只能启动一个, 然后我只要后定义的是timer1,那就只能timer1启动。 CLK_SetModuleClock(TMR0_MODULE,CLK_CLKSEL1_TMR0_S_HCLK,0); CLK_SetModuleClock(TMR1_MODULE,CLK_CLKSEL1_TMR1_S_HCLK,0); 找了很久找不到问题!!!求助!! |
|
相关推荐
1个回答
|
|
fndef __MAIN_H__#define __MAIN_H__#include "Mini51Series.h"extern void Timer0_ISR(void);extern void Timer1_ISR(void);#endif //__MAIN_H__/********************************************************************** * Timer0_ISR * $Date: 13/10/07 3:56p $ * Description: The interrupt services routine of Timer 0. *-----------------------------------------------------------------------------*/void Timer0_ISR(void){}// clear timer interrupt flagTMR0_IS_FLAG();}/********************************************************************** * Timer1_ISR * $Date: 13/10/07 3:56p $ * Description: The interrupt services routine of Timer 1. *-----------------------------------------------------------------------------*/void Timer1_ISR(void){}// clear timer interrupt flagTMR1_IS_FLAG();}// Mainvoid main (void){CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);CLK_SysTickDelay(2000);CLK_EnableCKO(CLK_CLKSEL1_CLKOSEL_HCLK, 1, 0);/* Set P3 multi-function pins for UART1 RXD and TXD */SYS->P3_MFP = SYS_MFP_P30_RXD1 | SYS_MFP_P31_TXD1;SYS->P5_MFP &= ~(SYS_MFP_P54_Msk | SYS_MFP_P55_Msk);/* Set P5.4 and P5.5 for LED toggle */GPIO_SetMode(P5, (BIT4 | BIT5), GPIO_PMD_OUTPUT);/* Set P2 multi-function pin for STADC */SYS->P2_MFP |= SYS_MFP_P23_AD3;ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END);ADC_POWER_ON(ADC);/* Enable ADC ADC_IF interrupt */ADC_EnableInt(ADC, ADC_ADF_INT);/* Set Timer0 time-out frequency to 1Hz */TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1);TIMER_EnableInt(TIMER0);/* Enable Timer0 NVIC */NVIC_EnableIRQ(TMR0_IRQn);/* Set Timer1 time-out frequency to 2Hz */TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, 2);TIMER_EnableInt(TIMER1);/* Enable Timer1 NVIC */NVIC_EnableIRQ(TMR1_IRQn);/* Start Timer0 and Timer1 counting */TIMER_Start(TIMER0);TIMER_Start(TIMER1);/* Waiting for Timer0 and Timer1 count */while(1){GPIO_TOGGLE(P5, BIT4);GPIO_TOGGLE(P5, BIT5);CLK_SysTickDelay(100000);}}
|
|
|
|
只有小组成员才能发言,加入小组>>
890 浏览 1 评论
2287 浏览 5 评论
2596 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2405 浏览 6 评论
2308 浏览 7 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
453浏览 9评论
465浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
569浏览 6评论
446浏览 5评论
478浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-19 15:09 , Processed in 0.540292 second(s), Total 45, Slave 36 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号