标题: 按键实现跑马灯STM32F103C8T6 [打印本页]

作者: qq5191    时间: 2019-12-21 11:01
标题: 按键实现跑马灯STM32F103C8T6
按键实现跑马灯

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "Bitband.h"
  3. #define DELAY_5MS 5000
  4. //#define RCC_APB2ENR *((volatile unsigned long int *)(0x40021000+0x18))
  5. //#define GPIOB_CRL *((volatile unsigned long int *)(0x40010C00+0x00))
  6. //#define GPIOB_ODR *((volatile unsigned long int *)(0x40010C00+0x0c))
  7. //0x4200 0000+(A-0x4000 0000)*32+n*4    b[0]
  8. //#define BPA0IN *((volatile unsigned long int *)(0x42000000+(0x10808<<5)+(0<<2)))  //GPIOA->IDR.14
  9. #define S0 PAin(0)
  10. #define S1 PAin(1)       
  11. //RCC_APB2ENR=;
  12. //=RCC_APB2ENR;
  13. void Delay(unsigned long int n)
  14. {
  15.         unsigned long int i;
  16.         for(i=0;i<n;i++)
  17.                 ;       
  18. }
  19. int main(void)
  20. {
  21.         unsigned char D[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
  22.         signed char i;//int i;
  23.         unsigned char Led_bit[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
  24.         //unsigned char led_seg[8]={0x5b,0x3f,0x06,0x6f,0x06,0x3f,0x06,0x7f};
  25.         unsigned char led_seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  26.         unsigned char Led_buf[8]={2,0,1,9,1,1,0,1};
  27.         unsigned char dir;                          //1:左移  2:右移
  28.         RCC->APB2ENR=RCC->APB2ENR|(1<<0);//AFIO EN
  29. //        RCC->APB2ENR=RCC->APB2ENR|(1<<2);//PA
  30.         RCC->APB2ENR=RCC->APB2ENR|(1<<3);//PB
  31.         GPIOB->CRL=0x33333333;//PB7~PB0 输出
  32.         GPIOB->CRH=0x33333333;//PB15~PB8 输出
  33.        
  34.         //关闭JTAG SWD功能
  35.         AFIO->MAPR=AFIO->MAPR&(~(7<<24));        //清[26:24]
  36.         AFIO->MAPR=AFIO->MAPR|2<<24;                // [26:24]=010
  37.         i=0;

  38.         while(1)
  39.         {
  40.                                
  41.                        
  42.                 GPIOB->ODR=(GPIOB->ODR&0xffffff00)|Led_bit[i];//送位码PB7~PB0=1000 0000
  43.                 GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(led_seg[Led_buf[i]]<<8);//PBH送段码2
  44.                 Delay(DELAY_5MS);
  45.                 i++;
  46.                 if(i>=8)
  47.                         i=0;
  48.                
  49.                
  50. //                //2
  51. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x80;//送位码PB7~PB0=1000 0000
  52. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x5b<<8);//PBH送段码2
  53. //                Delay(DELAY_5MS);
  54. //                //0
  55. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x40;//送位码PB7~PB0=1000 0000
  56. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x3f<<8);//PBH送段码2
  57. //                Delay(DELAY_5MS);
  58. //                //1
  59. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x20;//送位码PB7~PB0=1000 0000
  60. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段码2
  61. //                Delay(DELAY_5MS);
  62. //                //9
  63. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x10;//送位码PB7~PB0=1000 0000
  64. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x6f<<8);//PBH送段码2
  65. //                Delay(DELAY_5MS);       


  66. //                //1
  67. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x08;//送位码PB7~PB0=1000 0000
  68. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段码2
  69. //                Delay(DELAY_5MS);
  70. //                //0
  71. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x04;//送位码PB7~PB0=1000 0000
  72. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x3f<<8);//PBH送段码2
  73. //                Delay(DELAY_5MS);
  74. //                //1
  75. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x02;//送位码PB7~PB0=1000 0000
  76. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段码2
  77. //                Delay(DELAY_5MS);
  78. //                //8
  79. //                GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x01;//送位码PB7~PB0=1000 0000
  80. //                GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x7f<<8);//PBH送段码2
  81. //                Delay(DELAY_5MS);                       
  82.                
  83.         }
  84.         return(0);
  85. }
复制代码

所有资料51hei提供下载:
Proj2_1-Seg-PB15_PB8-Bit-PB7-PB0 - bak20191101.7z (162.65 KB, 下载次数: 27)







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1