Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. #include "stm32f10x.h"
  2. #include "stm32f10x_gpio.h" ​ //implementacja bibliotek
  3. #include "stm32f10x_rcc.h"
  4. GPIO_InitTypeDef GPIO_InitStructure​ ;
  5. GPIO_InitTypeDef GPIO_InitStructure1​ ;
  6. GPIO_InitTypeDef GPIO_InitStructure12out​ ;
  7. GPIO_InitTypeDef GPIO_InitStructure12in​ ;
  8. GPIO_InitTypeDef GPIO_InitStructure10out​ ;
  9.  
  10. unsigned​ ​ char​ tab​ [​ 16​ ]​ ​ =​ ​ {​ ​ 0xC0​ ,​ ​ 0xF9​ ,​ ​ 0xA4​ ,​ ​ 0xB0​ ,​ ​ 0x99​ ,​ ​ 0x92​ ,​ ​ 0x82​ ,​ ​ 0xF8​ , 0x80​ ,
  11. ​ 0x90​ ,​ ​ 0x88​ ,​ ​ 0x83​ ,​ ​ 0xC6​ ,​ ​ 0xA1​ ,​ ​ 0x86​ ,​ ​ 0x8E​ ​ }; ​ // utworzenie tablicy
  12. unsigned​ ​ char​ cztery ​ =​ ​ 0x99​ ;
  13. unsigned​ ​ char​ dwa ​ =​ ​ 0xA4
  14. int​ main​ (​ void​ )​ ​ {
  15.  
  16. RCC_APB2PeriphClockCmd​ (​ RCC_APB2Periph_GPIOC​ ,​ ENABLE​ );
  17. GPIO_InitStructure​ .​ GPIO_Speed ​ =​ GPIO_Speed_50MHz​ ;
  18. GPIO_InitStructure​ .​ GPIO_Mode ​ =​ GPIO_Mode_Out_PP​ ;
  19. 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​ ;
  20. GPIO_Init​ (​ GPIOC​ ,​ ​ &​ GPIO_InitStructure​ );
  21.  
  22. while​ ​ (​ 1​ )​ ​ {
  23. ​ unsigned​ ​ int​ i ​ =​ ​ 0​ ; ​
  24. unsigned​ ​ int​ j ​ =​ ​ 0​ ;
  25. //wyś 1 wyjście
  26. RCC_APB2PeriphClockCmd​ (​ RCC_APB2Periph_GPIOC​ ,​ ENABLE​ );
  27. GPIO_InitStructure1​ .​ GPIO_Speed ​ =​ GPIO_Speed_50MHz​ ;
  28. GPIO_InitStructure1​ .​ GPIO_Mode ​ =​ GPIO_Mode_Out_PP​ ;
  29. GPIO_InitStructure1​ .​ GPIO_Pin ​ =​ GPIO_Pin_10​ ;
  30. GPIO_Init​ (​ GPIOC​ ,​ ​ &​ GPIO_InitStructure1​ );
  31. ​//wyś 1 = 1
  32. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_10​ ,​ Bit_SET​ ); ​ // włączenie wyś 1 ​
  33. //wyś 2 wejście
  34. RCC_APB2PeriphClockCmd​ (​ RCC_APB2Periph_GPIOC​ ,​ ENABLE​ );
  35. GPIO_InitStructure12in​ .​ GPIO_Speed ​ =​ GPIO_Speed_50MHz​ ;
  36. GPIO_InitStructure12in​ .​ GPIO_Mode ​ =​ GPIO_Mode_IN_FLOATING​ ;
  37. GPIO_InitStructure12in​ .​ GPIO_Pin ​ =​ GPIO_Pin_12​ ;
  38. GPIO_Init​ (​ GPIOC​ ,​ ​ &​ GPIO_InitStructure12in​ );
  39. ​ //wyś 2 = 1
  40. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_12​ ,​ Bit_SET​ ); ​ // właczenie wyś 2
  41.  
  42. GPIOC​ ->​ ODR ​ =​ dwa​ ;​ // wyswietlenie cyfry 2
  43. ​ for​ ​ (​ i ​ =​ ​ 0​ ;​ i ​ <​ ​ 40000​ ;​ i​ ++);​ ​ //delay
  44. ​ //wyś 1 = 0
  45. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_10​ ,​ Bit_RESET​ ); ​
  46. //wyś 2 = 0
  47. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_12​ ,​ Bit_RESET​ );
  48. ​ //wyś 2 wyjście
  49. RCC_APB2PeriphClockCmd​ (​ RCC_APB2Periph_GPIOC​ ,​ ENABLE​ );
  50. GPIO_InitStructure12out​ .​ GPIO_Speed ​ =​ GPIO_Speed_50MHz​ ;
  51. GPIO_InitStructure12out​ .​ GPIO_Mode ​ =​ GPIO_Mode_Out_OD​ ;
  52. GPIO_InitStructure12out​ .​ GPIO_Pin ​ =​ GPIO_Pin_12​ ;
  53. GPIO_Init​ (​ GPIOC​ ,​ ​ &​ GPIO_InitStructure12out​ );
  54. //wyś 2 = 1
  55. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_12​ ,​ Bit_SET​ ); ​ // właczenie wyś 2 ​
  56. //wyś 1 wejście
  57. RCC_APB2PeriphClockCmd​ (​ RCC_APB2Periph_GPIOC​ ,​ ENABLE​ );
  58. GPIO_InitStructure10out​ .​ GPIO_Speed ​ =​ GPIO_Speed_50MHz​ ;
  59. GPIO_InitStructure10out​ .​ GPIO_Mode ​ =​ GPIO_Mode_IN_FLOATING​ ;
  60. GPIO_InitStructure10out​ .​ GPIO_Pin ​ =​ GPIO_Pin_10​ ;
  61. GPIO_Init​ (​ GPIOC​ ,​ ​ &​ GPIO_InitStructure10out​ ); ​
  62. //wyś 1 = 1
  63. GPIO_WriteBit​ (​ GPIOC​ ,​ GPIO_Pin_10​ ,​ Bit_SET​ ); ​ // włączenie wyś 1
  64. GPIOC​ ->​ ODR ​ =​ cztery​ ;​ ​ // wyswietlenie cyfry 4 ​
  65. for​ ​ (​ i ​ =​ ​ 0​ ;​ i ​ <​ ​ 40000​ ;​ i​ ++);​ ​ //delay
  66. ​ }
  67. }
  68.  
  69. GPIOC​ ->​ ODR ​ =​ jeden​ ;​ // wyswietlenie cyfry 1
  70. GPIOC​ ->​ ODR ​ =​ dwa​ ;​ ​ // wyswietlenie cyfry 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement