标题:
按键实现跑马灯STM32F103C8T6
[打印本页]
作者:
qq5191
时间:
2019-12-21 11:01
标题:
按键实现跑马灯STM32F103C8T6
按键实现跑马灯
单片机源程序如下:
#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 输出
//关闭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);
}
复制代码
所有资料51hei提供下载:
Proj2_1-Seg-PB15_PB8-Bit-PB7-PB0 - bak20191101.7z
(162.65 KB, 下载次数: 27)
2019-12-21 14:37 上传
点击文件名下载附件
程序文件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1