您当前的位置:五五电子网电子知识电子学习基础知识电脑-单片机-自动控制STM32 DS1302 正文
STM32 DS1302

STM32 DS1302

点击数:7358 次   录入时间:03-04 11:56:25   整理:http://www.55dianzi.com   电脑-单片机-自动控制

    u8 table1[3]="hjw";

    u8 table2[2]="00";

    void Delay(unsigned short time)//nms

    {

    unsigned short i, j;

    for(; time > 0; time--){

    for(j = 0; j < 10; j++){

    for(i = 0; i < 1000; i++);

    }

    }

    }

    int main(void)

    {

    //u8 i;

    /* System CLOCks Configuration */

    RCC_Configuration();

    /* NVIC configuration */

    NVIC_Configuration();

    /* Configure the GPIO ports */

    GPIO_Configuration();

    LCD1602_init();

    ds1302set_time();

    while (1)

    {

    ds1302read_time();

    ds1302d_convert();

    write1602_Achar(1,2,disp[8]);

    write1602_Achar(1,3,disp[9]); //显示 时

    write1602_Achar(1,4,0x0a);//':'

    write1602_Achar(1,5,disp[10]);

    write1602_Achar(1,6,disp[11]);

    write1602_Achar(1,7,0x0a);//显示分

    write1602_Achar(1,8,disp[12]);

    write1602_Achar(1,9,disp[13]);//显示秒

    }

    }

    void RCC_Configuration(void)

    {

    RCC_DeInit();

    /* Enable HSE */

    RCC_HSEConfig(RCC_HSE_ON);

    /* Wait till HSE is ready */

    HSEStartUpStatus = RCC_WaitForHSEStartUp();

    if(HSEStartUpStatus == SUCCESS)

    {

    /* Enable Prefetch Buffer */

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */

    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */

    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */

    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */

    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */

    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */

    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

    {

    }

    /* Select PLL as system clock source */

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */

    while(RCC_GetSYSCLKSource() != 0x08)

    {

    }

    }

    /* Enable Key Button GPIO Port, GPIO_LED and AFIO clock */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB

    | RCC_APB2Periph_AFIO, ENABLE);

    }

    /*******************************************************************************

    * Function Name : GPIO_Configuration

    * Description : Configures the different GPIO ports.

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    void GPIO_Configuration(void)

    {

    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;

    GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

    }

    void NVIC_Configuration(void)

    {

    //NVIC_InitTypeDef NVIC_InitStructure;

    #ifdef VECT_TAB_RAM

    /* Set the Vector Table base location at 0x20000000 */

    NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

    #else /* VECT_TAB_FLASH */

    /* Set the Vector Table base location at 0x08000000 */

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

    #endif

    }



上一页  [1] [2] 


本文关键字:暂无联系方式电脑-单片机-自动控制电子学习 - 基础知识 - 电脑-单片机-自动控制