多语言展示
当前在线:1555今日阅读:155今日分享:35

普中科技的单片机开发实验仪—LED点阵 代码

LED点阵的代码分享,已成功调试。
工具/原料

电脑

方法/步骤
1

主函数 #include 'stm32f10x.h'#include 'delay.h'#include 'gpio.h'#include 'Globel_Var.h'unsigned int taba[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned int tabb[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};int main (){    int m,i,j;    delay_init();    GPIO_Configuration();while(1)   {  m++ ;  if(m> 4) m=1;switch (m){  case 1:  for(j=0;j<3;j++)//  //从左到右3次  {  for(i=0;i<8;i++)  {  //P2=taba[i];   GPIOB->BSRR = taba[i] & 0x00ff;  //将数据送到P2口 并屏蔽高位,不干扰高8位IO的使用   GPIOB->BRR = (~taba[i]) & 0x00ff;   // P1=0xff;   GPIOA->BSRR = 0xff & 0x00ff;  //将数据送到P1口  并屏蔽高位,不干扰高8位IO的使用   GPIOA->BRR = (0xff) & 0x00ff;  delay_ms(100);  }    }  break;   case 2:  delay_ms(100);  for(j=0;j<3;j++)//  //从右到左3次  {  for(i=0;i<8;i++)  {  //P2=taba[7-i];     GPIOB->BSRR = taba[7-i] & 0x00ff;  //将数据送到P2口 并屏蔽高位,不干扰高8位IO的使用      GPIOB->BRR = (~taba[7-i]) & 0x00ff;  //P1=0xff;   GPIOA->BSRR = 0xff & 0x00ff;  //将数据送到P1口  并屏蔽高位,不干扰高8位IO的使用   GPIOA->BRR = (0xff) & 0x00ff;   delay_ms(100);  }  }  break;   case 3:  delay_ms(100);  for(j=0;j<3;j++)//  //从上至下3次{   for(i=0;i<8;i++){//P2=0x00;     GPIOB->BSRR = 0x00 & 0x00ff;  //将数据送到P2口    并屏蔽高位,不干扰高8位IO的使用     GPIOB->BRR = (~0x00) & 0x00ff;  //P1=tabb[7-i];     GPIOA->BSRR = tabb[7-i] & 0x00ff;  //将数据送到P1口  并屏蔽高位,不干扰高8位IO的使用     GPIOA->BRR = (~tabb[7-i]) & 0x00ff;     delay_ms(100);   } } break;  case 4:  delay_ms(100);   for(j=0;j<3;j++)//  //从下至上 3 次 { for(i=0;i<8;i++) { //P2=0x00; GPIOB->BSRR = 0x00 & 0x00ff;  //将数据送到P2口 并屏蔽高位,不干扰高8位IO的使用       GPIOB->BRR = (~0x00) & 0x00ff; //P1=tabb[i]; GPIOA->BSRR = tabb[i] & 0x00ff;  //将数据送到P1口 并屏蔽高位,不干扰高8位IO的使用      GPIOA->BRR = (~tabb[i]) & 0x00ff;   delay_ms(100);   }   }    break;           }   }     }

2

gpio.c #include 'gpio.h'void GPIO_Configuration(void){    GPIO_InitTypeDef GPIO_InitStructure;  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_ GPIOB | RCC_APB2Periph_AFIO, ENABLE);  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |    GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; //所有GPIO为同一类型端口  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出的最大频率为50HZ  GPIO_Init(GPIOB, &GPIO_InitStructure);   //初始化GPIOB端口  GPIO_Init(GPIOA, &GPIO_InitStructure);   //初始化GPIOB端口}

3

gpio.h #ifndef __GPIO_H#define __GPIO_H#include 'stm32f10x.h'extern void GPIO_Configuration(void);#endif

4

delay.h和delay.c正点原子编写的,直接拿来用。

推荐信息