1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include "stm32f10x.h" uint16_t table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uint16_t disp[4]; uint16_t temp,i,temp2,a,b,c; void Delay(unsigned int count) { unsigned int i; for(;count!=0;count--) { i=5000; while(i--); } } int main(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = 0xffff; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); while(1) { for(i=0;i<=9999;i++) { a=i/1000; b=i/100-a*10; c=i/10-a*100-b*10; disp[3]=table[a]; disp[2]=table[b] ; disp[1]=table[c]; disp[0]=table[i%10]; temp=(disp[1]<<8)|(disp[0]&0x0ff); GPIO_Write(GPIOC,temp); temp2=(disp[3]<<8)|(disp[2]&0x0ff); GPIO_Write(GPIOB,temp2); Delay(100); } } }
|