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 56 57 58 59 60 61 62 63 64 65 66 67 68
|
void HC595_GPIO_Configuration(void); void HC595_Send_Data(unsigned char num, unsigned char show_bit); void HC595_Send_Byte(unsigned char byte); void display(unsigned int n);
unsigned int num[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xff, 0x00};
void HC595_Send_Byte(unsigned char byte) { unsigned int i; for(i = 0; i < 8; i++) { if(byte & 0x80) GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_SET); else GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_RESET); GPIO_WriteBit(GPIOB, GPIO_Pin_13, Bit_RESET); Delay_us(10); GPIO_WriteBit(GPIOB, GPIO_Pin_13, Bit_SET); Delay_us(10); byte <<= 1; } }
void HC595_Send_Data(unsigned char num, unsigned char show_bit) { HC595_Send_Byte(num); HC595_Send_Byte(1 << show_bit); GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET); Delay_us(10); GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET); Delay_us(10); }
void display(unsigned int n) { static unsigned int thousand_bit, hundred_bit, ten_bit, single_bit; thousand_bit = n / 1000; hundred_bit = (n % 1000) / 100; ten_bit = n % 1000 % 100 / 10; single_bit = n % 10; HC595_Send_Data(num[thousand_bit], 3); HC595_Send_Data(num[hundred_bit], 2); HC595_Send_Data(num[ten_bit], 1); HC595_Send_Data(num[single_bit], 0); }
|