主函数:
#include "stm32f10x.h"
#include "smg.h"
uint16_t table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint16_t dis[2];
void delay(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<t;j++);
}
int main()
{
u8 i;
u16 temp;
SMG_Init();
while(1)
{
for(i=0;i<241;i++)
{
dis[1]=table[i/16];
dis[0]=table[i%16];
temp=(dis[1]<<8)|(dis[0]&0x0ff);
GPIO_Write(GPIOC, temp);
delay(500);
}
}
}
smg.h:
#ifndef __SMG_H
#define __SMG_H
void SMG_Init(void);
#endif
smg.c:
#include "smg.h"
#include "stm32f10x.h"
void SMG_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitTypeDef GPIO_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(GPIOC, &GPIO_InitStructure);
}