|
按鍵實(shí)現(xiàn)跑馬燈
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "Bitband.h"
- #define DELAY_5MS 5000
- //#define RCC_APB2ENR *((volatile unsigned long int *)(0x40021000+0x18))
- //#define GPIOB_CRL *((volatile unsigned long int *)(0x40010C00+0x00))
- //#define GPIOB_ODR *((volatile unsigned long int *)(0x40010C00+0x0c))
- //0x4200 0000+(A-0x4000 0000)*32+n*4 b[0]
- //#define BPA0IN *((volatile unsigned long int *)(0x42000000+(0x10808<<5)+(0<<2))) //GPIOA->IDR.14
- #define S0 PAin(0)
- #define S1 PAin(1)
- //RCC_APB2ENR=;
- //=RCC_APB2ENR;
- void Delay(unsigned long int n)
- {
- unsigned long int i;
- for(i=0;i<n;i++)
- ;
- }
- int main(void)
- {
- unsigned char D[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
- signed char i;//int i;
- unsigned char Led_bit[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
- //unsigned char led_seg[8]={0x5b,0x3f,0x06,0x6f,0x06,0x3f,0x06,0x7f};
- unsigned char led_seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char Led_buf[8]={2,0,1,9,1,1,0,1};
- unsigned char dir; //1:左移 2:右移
- RCC->APB2ENR=RCC->APB2ENR|(1<<0);//AFIO EN
- // RCC->APB2ENR=RCC->APB2ENR|(1<<2);//PA
- RCC->APB2ENR=RCC->APB2ENR|(1<<3);//PB
- GPIOB->CRL=0x33333333;//PB7~PB0 輸出
- GPIOB->CRH=0x33333333;//PB15~PB8 輸出
-
- //關(guān)閉JTAG SWD功能
- AFIO->MAPR=AFIO->MAPR&(~(7<<24)); //清[26:24]
- AFIO->MAPR=AFIO->MAPR|2<<24; // [26:24]=010
- i=0;
- while(1)
- {
-
-
- GPIOB->ODR=(GPIOB->ODR&0xffffff00)|Led_bit[i];//送位碼PB7~PB0=1000 0000
- GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(led_seg[Led_buf[i]]<<8);//PBH送段碼2
- Delay(DELAY_5MS);
- i++;
- if(i>=8)
- i=0;
-
-
- // //2
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x80;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x5b<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //0
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x40;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x3f<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //1
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x20;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //9
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x10;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x6f<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //1
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x08;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //0
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x04;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x3f<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //1
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x02;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x06<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
- // //8
- // GPIOB->ODR=(GPIOB->ODR&0xffffff00)|0x01;//送位碼PB7~PB0=1000 0000
- // GPIOB->ODR=(GPIOB->ODR&0xffff00ff)|(0x7f<<8);//PBH送段碼2
- // Delay(DELAY_5MS);
-
- }
- return(0);
- }
復(fù)制代碼
所有資料51hei提供下載:
Proj2_1-Seg-PB15_PB8-Bit-PB7-PB0 - bak20191101.7z
(162.65 KB, 下載次數(shù): 27)
2019-12-21 14:37 上傳
點(diǎn)擊文件名下載附件
程序文件 下載積分: 黑幣 -5
|
|