您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > STM32-8位数码管动态扫描实验
Óû§Ãû:ÃÜÂë:µÇ¼ע²áÓÐÃÎÏë˶¼Á˲»ÆðÖ÷Ò³²©¿ÍÏà²á|¸öÈ˵µ°¸|ºÃÓÑ|iÌù°É²é¿´ÎÄÕÂSTM328λÊýÂë¹Ü¶¯Ì¬É¨ÃèʵÑ飨²»Óÿ⺯Êý£©²»ÉÁ˸2011-05-2018:05/*****************************************************************8λ¹²Òõ¼«ÊýÂë¹ÜÏÔʾÇý¶¯³ÌÐòforSTM32*by×·ÃÎ2011-4-3*****************************************************************/#includestm32f10x.h#defineDPYOUTGPIOD-ODR//ÊýÂë¹ÜµÄ¶ÎÑ¡¶¨Òå74HC573ÊäÈëPD[0..7]#defineDPYCOMGPIOE-ODR//ÊýÂë¹Üλѡ74HC138ABC¶¨Òå#defineOPENOUTGPIOE-BSRR=GPIO_Pin_3//PE.374HC573ʹÄܶË#defineCLOSEOUTGPIOE-BRR=GPIO_Pin_3#defineLED7CCsign0x40//¹²¡°Òõ¡±¼«ÊýÂë¹ÜµÄÂë±íunsignedcharLED7CC[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};externvoiddelay_nus(unsignedlongn);externvoiddelay_nms(unsignedlongn);//8λÊýÂë¹Ü¶¯Ì¬ÏÔʾº¯ÊývoidDPY_num(int32_tnum){uint32_tsign=0,wei,i;if(num0){sign=1;num=-num;}if(num10)wei=1;elseif(num100)wei=2;elseif(num1000)wei=3;elseif(num10000)wei=4;elseif(num100000)wei=5;elseif(num1000000)wei=6;elseif(num10000000)wei=7;elsewei=8;for(i=1;i=wei;i++){DPYOUT=LED7CC[num%10];num/=10;DPYCOM=8-i;OPENOUT;delay_nms(2);CLOSEOUT;}if(sign){DPYOUT=LED7CCsign;DPYCOM=8-wei-1;OPENOUT;delay_nms(2);CLOSEOUT;}}//ÊýÂë¹ÜÏÔʾСÊýº¯ÊývoidDPY_deceimal(int32_tnum,intdot){uint32_tsign=0,wei,i;if(num0){sign=1;num=-num;}if(num10)wei=1;elseif(num100)wei=2;elseif(num1000)wei=3;elseif(num10000)wei=4;elsewei=5;for(i=1;i=wei;i++){DPYOUT=LED7CC[num%10];if(dot==(i-1)){DPYOUT|=0x80;//µãÁÁСÊýµã}num/=10;DPYCOM=8-i;OPENOUT;delay_nms(3);CLOSEOUT;}if(sign){DPYOUT=LED7CCsign;DPYCOM=8-wei-1;OPENOUT;delay_nms(3);CLOSEOUT;}}//ÊýÂë¹ÜÏÔʾָ¶¨Î»ÊýµÄ¸¡µãÊývoidDPY_float(floatf,intdot){inti=0;for(;idot;i++)f*=10;DPY_deceimal((int)f,dot);}/**************************************************************8λÊýÂë¹Ü¶¯Ì¬É¨ÃèÏÔʾʵÑé(ÏÔʾ²»Óÿ⺯Êý)*ÏÔʾÓÃÖ¸ÕëÖ±½Ó·ÃÎÊGPIO¶Ë¿ÚµÄÊä³ö¼Ä´æÆ÷£¬ÐÎʽGPIOD-ODR*ÑÓʱdelay_nms(5)ʱ£¬ÏÔʾ²»ÉÁ˸*74HC138A--P2.2--PE.0B--P2.3--PE.1C--P2.4--PE.2*74HC573D0~D7---PD[0..7]LE---PE.3*by×·ÃÎ2011-4-3*************************************************************/#includestm32f10x.h//¹²¡°Ñô¡±¼«ÊýÂë¹ÜµÄÂë±íunsignedcharLED7CA[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71};externDPY_num(int32_tnum);externDPY_deceimal(int32_tflo,intdot);//ʱÖÓÅäÖú¯Êý8MHz*9=72MHzvoidRCC_Configuration(){RCC_DeInit();RCC_HSEConfig(RCC_HSE_ON);//ʹÄÜHSEif(RCC_WaitForHSEStartUp()==SUCCESS){RCC_HCLKConfig(RCC_SYSCLK_Div1);//HCLK=SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1);RCC_PCLK1Config(RCC_HCLK_Div2);RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);RCC_PLLCmd(ENABLE);while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);while(RCC_GetSYSCLKSource()!=0x08);}RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|\RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);//RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);}//ÑÓʱnusvoiddelay_nus(unsignedlongn){unsignedlongj;while(n--){j=8;while(j--);}}//ÑÓʱnmsvoiddelay_nms(unsignedlongn){while(n--)delay_nus(1100);}//GPIOÅäÖú¯ÊývoidGPIO_Configuration(void){GPIO_InitTypeDefGPIO_InitStructure;GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_Init(GPIOD,&GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin=(GPIO_Pin_0+GPIO_Pin_1+GPIO_Pin_2+GPIO_Pin_3);GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_Init(GPIOE,&GPIO_InitStructure);}///////////////////////////////////////////intmain(){uint32_tdpynum;RCC_Configuration();GPIO_Configuration();dpynum=10000000;while(1){dpynum+=111;if(dpynum90000000)dpynum=0;DPY_num(dpynum);delay_nms(5);}}Àà±ð£ºStm32||Ìí¼Óµ½ËѲØ|·ÖÏíµ½iÌù°É|ä¯ÀÀ(298)|ÆÀÂÛ(3)ÉÏһƪ£ºSTM32LCD12864Çý¶¯³ÌÐò£¨Í·ÎÄ...ÏÂһƪ£ºUbuntu11.04¸üÐÂÔ´Ïà¹ØÎÄÕ£º?½âÎöSTM32µÄ¿âº¯Êý¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡?²»Óÿ⺯Êý×Ô¼º¶¯ÊÖÅäÖÃSTM32ÖÐ...?ARMѧϰ11²»Óÿ⺯Êý×Ô¼º¶¯ÊÖÅä...¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡×î½ü¶ÁÕߣºµÇ¼ºó£¬Äú¾Í³öÏÖÔÚÕâÀï¡£lixin4511snowasc531243354ÑîÇ¿333837078933é龫½ßÂÇÏëÃû×ÖÐý·çÓê·²ÂäÈË×ÚÍøÓÑÆÀÂÛ£º1bearmybed2011-08-0115:02|»Ø¸´ÄúÖªµÀÎÒÃǶ¼ÊdzõѧÕߣ¬ºÃ²»ÈÝÒ×´ÓÍøÉÏËѵ½ÄúµÄÎÄÕ£¬¼Ä´æÆ÷²Ù×÷µÄ£¬¿´ÁË°ëÌì²Å¿´¶®°¡£¬¡£ËùÒÔ½¨ÒéÒÔºó¶à¼Óµã×¢ÊÍ°É¡£2ÑÛÉñÓëÌì¿Õ2011-08-2313:55|»Ø¸´Õâ¸ö²»´íÒªÊÇÄܸ½Í¼»á¸üºÃ3gongkansb2011-08-2814:04|»Ø¸´²»ÖªµÀ¿É²»¿ÉÒÔ°¡¶¥Ò»ÏÂÂ¥Ö÷·¢±íÆÀÂÛ£ºÄÚ¡¡ÈÝ£º²åÈë±íÇ騋ÉÁ¹â×ÖÈ¡Ïû»Ø¸´°ïÖúÖÐÐÄ|¿Õ¼ä¿Í·þ|ͶËßÖÐÐÄ|¿Õ¼äÐÒé?2011BaiduÄúÖªµÀÎÒÃǶ¼ÊdzõѧÕߣ¬ºÃ²»ÈÝÒ×´ÓÍøÉÏËѵ½ÄúµÄÎÄÕ£¬¼Ä´æÆ÷²Ù×÷µÄ£¬¿´ÁË°ëÌì²Å¿´¶®°¡£¬¡£ËùÒÔ½¨ÒéÒÔºó¶à¼Óµã×¢ÊÍ°É¡£Õâ¸ö²»´íÒªÊÇÄܸ½Í¼»á¸üºÃ²»ÖªµÀ¿É²»¿ÉÒÔ°¡¶¥Ò»ÏÂÂ¥Ö÷
本文标题:STM32-8位数码管动态扫描实验
链接地址:https://www.777doc.com/doc-5284301 .html