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 43 44 45 46 47 48 49 50 51 52 53 54 55
| #define GPIOB_CRL (*(volatile unsigned int*)(0x40010C00+0x00)) #define GPIOB_IDR (*(volatile unsigned int*)(0x40010C00+0x08)) #define GPIOC_CRL (*(volatile unsigned int*)(0x40011000+0x00)) #define GPIOC_CRH (*(volatile unsigned int*)(0x40011000+0x04)) #define GPIOC_ODR (*(volatile unsigned int*)(0x40011000+0x0C)) #define RCC_APB2ENR (*(volatile unsigned int*)(0x40021000+0x18))
unsigned int num[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; void delay(int iterations) { for (int i=0; i<iterations; i++) { asm("nop"); } }
int main(void){
int value = 0;
RCC_APB2ENR|=1<<3; RCC_APB2ENR|=1<<4;
GPIOB_CRL &= ~0x0000000F; GPIOB_CRL |= 0x00000008;
GPIOC_CRL &= ~(0xFFFF); GPIOC_CRH &= ~((0xF<<20)|(0xF<<16)); GPIOC_CRL |= 0x33333333;
while(1){ if(!(GPIOB_IDR & 0x01)){ delay(20); if(!(GPIOB_IDR & 0x01)){ value++; while(!(GPIOB_IDR & 0x01)); } } if(!(GPIOB_IDR & 0x02)){ delay(20); if(!(GPIOB_IDR & 0x02)){ value--; while(!(GPIOB_IDR & 0x02)); } } if(value>9){ value = 0; } if(value<0){ value = 9; } GPIOC_ODR = (~num[value]) & 0x7F; } }
|