Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <hidef.h> /* for EnableInterrupts macro */
  2. #include "derivative.h" /* include peripheral declarations */
  3. #define LED_1 PTDD_PTDD4
  4. #define LED_2 PTDD_PTDD5
  5. #define LED_3 PTDD_PTDD6
  6. #define LED_4 PTDD_PTDD7
  7. #define button_1_isPressed !PTAD_PTAD2
  8. #define button_2_isPressed !PTAD_PTAD3
  9. #define button_3_isPressed !PTAD_PTAD4
  10. #define button_4_isPressed !PTAD_PTAD5
  11.  
  12. #define Clock_Source TPM1SC_CLKSA
  13. #define Timer_Register TPM1SC
  14. #define Timer_Channel_Register TPM1C0SC
  15.  
  16. #define ON 0
  17. #define OFF 1
  18.  
  19. #define FIXED 1;
  20. #define FLASHING 0;
  21.  
  22. int delay = 0;
  23.  
  24. interrupt VectorNumber_Vtpm1ch0 void step(void)
  25. {
  26. if(TPM1C0SC_CH0F)
  27. TPM1C0SC_CH0F = 0;//встановлення значення флагу в 0 - скидання
  28. LED_1 = !LED_1; //якщо горіла - не горить. якщо не горіла - горить. Реалізація блимання
  29. TPM1SC_TOF = 0;//встановлення значення флагу переповненння таймера в 0 - скидання
  30. }
  31.  
  32.  
  33. void main(void) {
  34. EnableInterrupts;
  35. /* include your code here */
  36. PTDDD = 0b11110000;
  37. PTDD = 0b11110000;
  38.  
  39. PTAPE_PTAPE2 = 1;
  40. PTAPE_PTAPE3 = 1;
  41. PTAPE_PTAPE4 = 1;
  42. PTAPE_PTAPE5 = 1;
  43.  
  44. KBIPE_KBIPE5 = 1;
  45. KBIPE_KBIPE4 = 1;
  46. KBIPE_KBIPE3 = 1;
  47. KBIPE_KBIPE2 = 1;
  48. KBISC_KBIE = 1;// enable Keyboard Interrupts
  49. KBISC_KBF = 1;
  50. Timer_Register = 0;
  51. TPM1C0V = 0;
  52. TPM1MOD = 50000;
  53. TPM1CNTH = 0;
  54. for(;;){
  55. __RESET_WATCHDOG(); /* feeds the dog */
  56. } /* loop forever */
  57. /* please make sure that you never leave main */
  58. }
  59. void Btn3Clicked() {
  60. int frequency = Timer_Register & 0b00000111;
  61.  
  62. if(frequency)
  63. frequency -= 1;
  64. TPM1SC_PS0 = frequency & 1;
  65. TPM1SC_PS1 = (frequency >> 1) & 1;
  66. TPM1SC_PS2 = (frequency >> 2) & 1;
  67. }
  68. void Btn1Clicked() {
  69. TPM1SC_PS2 = TPM1SC_PS1 = TPM1SC_PS0 = 1;
  70. Timer_Channel_Register = 0;
  71. TPM1C0SC_CH0IE = TPM1C0SC_MS0A = 1;
  72. Clock_Source = 1;
  73. TPM1SC_TOIE = 1;
  74.  
  75. }
  76. void Btn4Clicked(){
  77. int frequency = Timer_Register & 0b00000111;
  78. if(frequency != 0b00000111)
  79. frequency += 1;
  80. TPM1SC_PS0 = frequency & 1;
  81. TPM1SC_PS1 = (frequency >> 1) & 1;
  82. TPM1SC_PS2 = (frequency >> 2) & 1;
  83. }
  84.  
  85. //turn off the blaming
  86. void Btn2Clicked() {
  87. Clock_Source = 0;
  88. Timer_Channel_Register = 0;
  89. LED_1 = OFF;
  90. }
  91.  
  92. interrupt VectorNumber_Vkeyboard1 void click(void)
  93. {
  94. KBISC_KBACK = 1;
  95. if(button_1_isPressed)
  96. Btn1Clicked();
  97.  
  98. if(button_2_isPressed)
  99. {
  100. Btn2Clicked();
  101. }
  102. if (button_3_isPressed)
  103. {
  104. Btn3Clicked();
  105.  
  106. }
  107. if (button_4_isPressed)
  108. {
  109. Btn4Clicked();
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement