Advertisement
Bobita

marfa

May 24th, 2024
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.50 KB | None | 0 0
  1. /*
  2.  * USART2 is connected to the ST-Link virtual COM port.
  3.  * Use Tera Term to interract with STM board
  4.  *
  5.  * By default, the clock is running at 16 MHz.
  6.  * The UART2 is configured for 115200 Baud.
  7.  * PA2 - USART2 TX (AF7)
  8.  * PA3 - USART2 RX (AF7)
  9.  */
  10. #include "stm32f4xx.h"
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include "Types.h"
  15. #include "Drivers.h"
  16.  
  17. void delayMs(int);
  18. UART_MSG_T msg = {.data = {0}, .id = 0, .len = 0};
  19. U8 CyclicMessage_U8 = 0;
  20. U8 TimerCountDown_U16 = SECONDS_TO_COUNT_U8;
  21. U8 PrintInCycleMode_U8 = 0;
  22.  
  23. /* Lucrarea 2 de completat */
  24.  
  25. void PeriphInit(void)
  26. {
  27.  
  28.     __disable_irq();
  29.  
  30.     // Configure PC[11..8] as input
  31.     RCC->AHB1ENR |= 4;           /* Enable GPIOC clock */
  32.     GPIOC->MODER &= ~0x0CFF0000; /* Reset GPIOC PC[13..9]  for input mode */
  33.    
  34.     RCC->AHB1ENR |= 1; /* porneste semnalul de tact al portului A */
  35.     GPIOA->MODER &= ~0x00000C00; /* sterge registrul de mod al portului A */
  36.     GPIOA->MODER |= 0x00000400; /* seteaza modul de iesire al pinului PA5 */
  37.  
  38.     RCC->AHB1ENR |=  2;             /* enable GPIOB clock */
  39.   GPIOB->MODER &= ~0x0000ff00;    /* clear pin mode */
  40.   GPIOB->MODER |=  0x00005500;    /* set pins to output mode */
  41.  
  42.     USART2_init();
  43.  
  44.     __enable_irq();
  45. }
  46.  
  47. /* TODO: change the 0's to the correct value */
  48. const U8 Hex7Segment[16] = {0};
  49.  
  50. /* end lucrarea 2*/
  51.  
  52. /* Lucrarea 3 De completat*/
  53. static const U32 STRVR = 0;
  54. static const U16 STCTRL = 0;
  55.  
  56. static const U16 TIM3_PSC = 0;
  57. static const U16 TIM3_ARR = 0;
  58.  
  59. static const U16 TIM3_CH1_PSC = 0;
  60. static const U16 TIM3_CH1_ARR = 0;
  61. static const U16 TIM3_CH1_CCMR1 = 0;
  62. static const U16 TIM3_CH1_CCR1 = 0;
  63.  
  64. static const U16 TIM8_CH3_PSC = 0;
  65. static const U16 TIM8_CH3_CCMR2 = 0;
  66.  
  67. U32 timestamp = 0;
  68. U32 capture_time = 0;
  69. U8 nr_of_pushes = 0;
  70. U8 factor = 1;
  71. /* end lucrarea  3 */
  72.  
  73. /* Lucrarea 4 */
  74.  
  75. U16 dac_factor = 600;
  76. U16 dac_hold_value = 0;
  77.  
  78.  
  79. #define ADC_8_BIT 1 //dezactivati pentru adc 12 biti
  80.  
  81. #if ADC_8_BIT
  82. static const U32 ADC_CR1 = 0; /* 8-bit resolution */
  83. static const U32 ADC_CR2 = 0; /* SW Start, Align right justified, start adc */
  84. #else
  85. static const U32 ADC_CR1 = 0; /* 12-bit resolution */
  86. static const U32 ADC_CR2 = 0; /* SW Start, Align left justified,  start ADC */
  87. #endif
  88.  
  89. static const U32 MODER = 0; /* PA0-PA4 ca intrari analogice*/
  90.  
  91. /*End of Lucrarea 4*/
  92.  
  93. /* lucrarea 5 */
  94. static const U32 MODER_IRQ_B = 0; /* PB15-PB12 ca intrari*/
  95. static const U32 MODER_IRQ_C = 0; /* PC11-PC8 ca intrari */
  96. static const U32 PUPDR_IRQ_B = 0; /* PB15-PB12 pull-up*/
  97. static const U16 EXTI_FTSR = 0; /* ISR on PB15-PB12 falling edge*/
  98. static const U16 EXTI_RTSR = 0; /* ISR on PC11-PC8 rising edge*/
  99.  
  100. void IRQInit()
  101. {
  102.     SetupIOInterrupt(MODER_IRQ_B, MODER_IRQ_C, PUPDR_IRQ_B, EXTI_FTSR, EXTI_RTSR);
  103. }
  104. /* end of lucrarea 5 */
  105.  
  106. /* Lucrarea 6 */
  107. static const U16 SPI_CR1 = 0x33F; /* viteza transfer si 8 biti date, master mode */
  108.  
  109. static const U32 GPIOB_OTYPER = 0; /* set as open drain */
  110. static const U32 GPIOB_PUPDR = 0;   /* setup SCL, SDA ca pull-up pentru I2C*/
  111. static const U16 I2C_CR1 = 0;           /* SW resetm ie;ire reset, enable I2C1*/
  112. static const U16 I2CC_CCR = 0;              /* setup as standard mode*/
  113. /* end Lucrarea 6 */
  114.  
  115. U8 ReceiveMessage(void)
  116. {
  117.     char msg_str[MAX_PACKET_STR_SIZE];
  118.     const char *pos = msg_str;
  119.  
  120.     memset(&msg, 0, sizeof(UART_MSG_T));
  121.  
  122.     fgets(msg_str, MAX_PACKET_STR_SIZE, stdin);
  123.  
  124.     if (strlen(msg_str) < 3)
  125.     {
  126.         msg.id = 0xFF;
  127.         return 0;
  128.     }
  129.  
  130.     if (sscanf(pos, "%2hhx", &msg.id) == 0)
  131.     {
  132.         msg.id = 0xFF;
  133.         return 0;
  134.     }
  135.  
  136.     if (strlen(msg_str) > 5)
  137.     {
  138.         pos += 3;
  139.  
  140.         for (int i = 1; i < strlen(msg_str) / 3; i++)
  141.         {
  142.             sscanf(pos, "%2hhx", &msg.data[i - 1]);
  143.             pos += 3;
  144.             msg.len++;
  145.         }
  146.     }
  147.     return 1;
  148. }
  149.  
  150. void PrintReceivedMessage(const UART_MSG_T msg)
  151. {
  152.     printf("the received packet is: \n");
  153.     printf("ID: %02x \n", msg.id);
  154.     printf("Size in Bytes: %d\n", msg.len);
  155.     printf("Data:");
  156.     for (int i = 0; i < msg.len; i++)
  157.         printf("%02X ", msg.data[i]);
  158.     printf("\r\n");
  159. }
  160.  
  161. void ProcessMessage(const UART_MSG_T msg)
  162. {
  163.     U32 p;
  164.     switch (msg.id)
  165.     {
  166.     case SW_VERSION:
  167.         printf("SW Version: 01.03.24-SI\n");
  168.         break;
  169.  
  170.     case PORT_INPUT:
  171.         if (msg.len < 2)
  172.         {
  173.             printf("bad-len\n");
  174.         }
  175.         else if (msg.data[0] != 0x42 && msg.data[0] != 0x43)
  176.         {
  177.             printf("bad-port\n");
  178.         }
  179.         else if (((msg.data[0] == 0x42) && (msg.data[1] > 15 || msg.data[1] < 12)) ||
  180.                  ((msg.data[0] == 0x43) && (msg.data[1] > 11 || msg.data[1] < 8)))
  181.         {
  182.             printf("bad-pin\n");
  183.         }
  184.         else
  185.         {
  186.             U32 i = 1;
  187.             p = msg.data[0] != 0x42 ? GPIOC->IDR : GPIOB->IDR;
  188.             i <<= msg.data[1];
  189.             if (CyclicMessage_U8 == 0 || PrintInCycleMode_U8 == 1)
  190.             {
  191.                 printf("%ld \n", (p & i) >> msg.data[1]);
  192.                 PrintInCycleMode_U8 = 0;
  193.             }
  194.  
  195.             if (CyclicMessage_U8 == 0 && msg.len >= 3)
  196.             {
  197.                 if (msg.data[2] > 0)
  198.                 {
  199.                     CyclicMessage_U8 = 1;
  200.                     InitPeriodicTimer(PERIODIC_TIMER_VALUE_500US_U16);
  201.                 }
  202.             }
  203.         }
  204.  
  205.         break;
  206.     case PORT_OUTPUT:
  207.         if (msg.len < 3)
  208.         {
  209.             printf("bad-len\n");
  210.         }
  211.         else if (msg.data[0] != 0x42)
  212.         {
  213.             printf("bad-port\n");
  214.         }
  215.         else if ((msg.data[1] > 7) || (msg.data[1] < 4))
  216.         {
  217.             printf("bad-pin\n");
  218.         }
  219.         else
  220.         {
  221.             U32 i = 1;
  222.             i <<= msg.data[1];
  223.             GPIOB->BSRR = msg.data[2] ? (GPIOB->BSRR | i) : (GPIOB->BSRR | (i << 16));
  224.             printf("%02lX\n", (GPIOB->ODR & 0x000000F0) >> 4);
  225.         }
  226.         break;
  227.     case PORT_HEX:
  228.         if (msg.len < 2)
  229.         {
  230.             printf("bad-len\n");
  231.         }
  232.         else if (msg.data[0] > 3)
  233.         {
  234.             printf("bad-display\n");
  235.         }
  236.         else if (msg.data[1] > 15)
  237.         {
  238.             printf("bad-number\n");
  239.         }
  240.         else
  241.         {
  242.  
  243.             SPI1_init();
  244.             SPI1_write(Hex7Segment[msg.data[1]]); /* write pattern to the seven segments */
  245.             SPI1_write(1 << msg.data[0]);         /* select digit */
  246.         }
  247.         break;
  248.     case TIMERS:
  249.         if (msg.len < 1)
  250.         {
  251.             printf("bad-len\n");
  252.         }
  253.         else
  254.         {
  255.             SystemTickTimerStop();
  256.             switch (msg.data[0])
  257.             {
  258.             /*general timer */
  259.             case GENERAL_TIM3:
  260.                 if (CyclicMessage_U8 == 0)
  261.                 {
  262.                     TIM3_Cfg(TIM3_PSC, TIM3_ARR);
  263.                     timestamp = 0;
  264.  
  265.                     if (msg.len > 1)
  266.                     {
  267.                         TIM3->ARR = ((TIM3->ARR + 1) * msg.data[1]) - 1;
  268.                         factor = msg.data[1];
  269.                     }
  270.                 }
  271.                 if (CyclicMessage_U8 == 0 || PrintInCycleMode_U8 == 1)
  272.                 {
  273.                     printf("%ld \n", timestamp);
  274.                     PrintInCycleMode_U8 = 0;
  275.                 }
  276.  
  277.                 if (CyclicMessage_U8 == 0 && msg.len >= 3)
  278.                 {
  279.                     if (msg.data[2] > 0)
  280.                     {
  281.                         CyclicMessage_U8 = 1;
  282.                         InitPeriodicTimer(PERIODIC_TIMER_VALUE_500US_U16);
  283.                     }
  284.                     else
  285.                     {
  286.                         TIM3_Stop();
  287.                     }
  288.                 }
  289.                 break;
  290.             /* out compare */
  291.             case TIM3_CH1_COMPARE:
  292.                 TIM3_CH1_Compare_Cfg(TIM3_CH1_PSC, TIM3_CH1_ARR, TIM3_CH1_CCMR1, TIM3_CH1_CCR1);
  293.                 if (msg.len > 1)
  294.                 {
  295.                     TIM3->ARR = TIM3->ARR * msg.data[1];
  296.                 }
  297.                 break;
  298.             /* in capture */
  299.             case TIM8_CH3_CAPTURE:
  300.                 if (CyclicMessage_U8 == 0)
  301.                 {
  302.                     TIM8_CH3_Capture_Cfg(TIM8_CH3_PSC, TIM8_CH3_CCMR2);
  303.                     capture_time = 0;
  304.                 }
  305.  
  306.                 if (CyclicMessage_U8 == 0 || PrintInCycleMode_U8 == 1)
  307.                 {
  308.                     printf("%d %ld \n", nr_of_pushes, capture_time);
  309.                     PrintInCycleMode_U8 = 0;
  310.                 }
  311.  
  312.                 if (CyclicMessage_U8 == 0 && msg.len >= 2)
  313.                 {
  314.                     if (msg.data[1] > 0)
  315.                     {
  316.                         CyclicMessage_U8 = 1;
  317.                         InitPeriodicTimer(PERIODIC_TIMER_VALUE_500US_U16);
  318.                     }
  319.                     else
  320.                     {
  321.                         TIM8_Stop();
  322.                     }
  323.                 }
  324.                 break;
  325.             /* PWM */
  326.             case TIM8_CH1_PWM:
  327.                 StopTIM8_CH1_PWM();
  328.                 InitTIM8_CH1_PWM();
  329.                 if (msg.len >= 2)
  330.                 {
  331.                     if (msg.data[1] <= 0x64)
  332.                     {
  333.                         SetTIM8_CH1_PWM_DutyCycle(msg.data[1]);
  334.                     }
  335.                     else
  336.                     {
  337.                         printf("bad-duty-cycle\n");
  338.                         StopTIM8_CH1_PWM();
  339.                     }
  340.                 }
  341.                 break;
  342.             case SYS_TICK_TIMER:
  343.                 SystemTickTimerInit(STRVR, STCTRL);
  344.                 break;
  345.             default:
  346.                 printf("Invalid CMD received \n");
  347.                 break;
  348.             }
  349.         }
  350.         break;
  351.     case ADC_DAC:
  352.         if (msg.len < 2)
  353.         {
  354.             printf("bad-len\n");
  355.         }
  356.         else if (msg.data[0] == 0x00) /*ADC*/
  357.         {
  358.             if (msg.data[1] > MAX_NR_OF_CHANNELS)
  359.             {
  360.                 printf("bad-channel\n");
  361.             }
  362.             else if (msg.data[1] < 2 || (msg.data[1] > 3 && msg.data[1] <5) || msg.data[1] > 16)
  363.             {
  364.                 U16 adc_value = 0xFFFF;
  365.                 ADC_Configure(MODER, ADC_CR1, ADC_CR2);
  366.  
  367.                 adc_value = ADC_SampleChannel(msg.data[1]);
  368. #if ADC_8_BIT
  369.                 adc_value &= 0x00FF;
  370. #else
  371.                 adc_value &= 0xFFF0;
  372. #endif
  373.                 printf("Channel %d value %d\n", msg.data[1], adc_value);
  374.                 ADC_Stop();
  375.             }
  376.             else
  377.             {
  378.                 printf("Channel %d value %d\n", msg.data[1], 0xFFFF);
  379.             }
  380.         }
  381.         else if (msg.data[0] == 0x01) /*DAC*/
  382.         {
  383.             if (CyclicMessage_U8 == 0)
  384.             {
  385.                 dac_factor = dac_factor * msg.data[1];
  386.                 DAC_Configure(dac_hold_value + dac_factor);
  387.             }
  388.  
  389.             if (CyclicMessage_U8 == 0 || PrintInCycleMode_U8 == 1)
  390.             {
  391.  
  392.                 dac_hold_value = dac_hold_value + dac_factor;
  393.                 DAC->DHR12R1 = dac_hold_value & 0x0FFF;
  394.  
  395.                 printf("Hold Value: %ld \n", DAC->DHR12R1);
  396.                 PrintInCycleMode_U8 = 0;
  397.             }
  398.  
  399.             if (CyclicMessage_U8 == 0)
  400.             {
  401.                 CyclicMessage_U8 = 1;
  402.                 InitPeriodicTimer(PERIODIC_TIMER_VALUE_500US_U16);
  403.             }
  404.         }
  405.         else
  406.         {
  407.             printf("Invalid module\n");
  408.         }
  409.         break;
  410.     case IRQ:
  411.         if (msg.len < 2)
  412.         {
  413.             printf("bad-len\n");
  414.         }
  415.         else if (msg.data[0] != 0x42 && msg.data[0] != 0x43)
  416.         {
  417.             printf("bad-port\n");
  418.         }
  419.         else if (((msg.data[0] == 0x42) && (msg.data[1] > 15 || msg.data[1] < 12)) ||
  420.                  ((msg.data[0] == 0x43) && (msg.data[1] > 11 || msg.data[1] < 8)))
  421.         {
  422.             printf("bad-pin\n");
  423.         }
  424.         else
  425.         {
  426.  
  427.             EnableIRQForIO(msg.data[1]);
  428.             printf("Press the button for port %c, pin %d\n", msg.data[0], msg.data[1]);
  429.             delayMs(5000);
  430.             DisableIRQForIO(msg.data[1]);
  431.         }
  432.         break;
  433.     case SPI:
  434.         if (msg.len < 1)
  435.         {
  436.             printf("bad-len\n");
  437.         }
  438.         else
  439.         {
  440.             LCD_data(msg.data[0]);
  441.         }
  442.         break;
  443.     case I2C:
  444.         if (msg.len < 1)
  445.         {
  446.             printf("bad-len\n");
  447.         }
  448.         else
  449.         {
  450.             I16 acc_g[6];
  451.             I2C1_Init(GPIOB_OTYPER, GPIOB_PUPDR, I2C_CR1, I2CC_CCR);
  452.             MPU6050_initialize();
  453.             MPU6050_getMotion6(&acc_g[0], &acc_g[1], &acc_g[2], &acc_g[3], &acc_g[4], &acc_g[5]);
  454.             if(msg.data[0] > 6)
  455.                 printf("sensor return values: %d, %d, %d, %d, %d, %d\n", acc_g[0], acc_g[1], acc_g[2], acc_g[3], acc_g[4], acc_g[5]);
  456.             else
  457.                 printf("sensor return value: %d\n", acc_g[msg.data[0]]);
  458.         }
  459.         break;
  460.     default:
  461.         printf("Invalid ID received \n");
  462.         break;
  463.     }
  464. }
  465.  
  466. void writeStringLCD(char *line) {
  467.     for(unsigned int i=0; i < strlen(line); i++)
  468.     {
  469.         LCD_data(line[i]);
  470.     }
  471. }
  472.  
  473. void newLine(unsigned int size){
  474.     for(unsigned int i=0; i < 40-size; i++)
  475.     {
  476.         LCD_data(' ');
  477.     }
  478. }
  479.  
  480. void stopProgram(){
  481.     while(1){}
  482. }
  483.  
  484. int main(void)
  485. {
  486.     U8 status = 0;
  487.  
  488.     PeriphInit();
  489.     if(SPI_CR1 != 0) {
  490.        LCD_init(SPI_CR1);
  491.     }
  492.  
  493.     printf("Lucrarea 6 interfete seriale \n");
  494.     printf("please enter the packet in the following format ID Byte0 Byte1 ... Byte7 \n");
  495.    
  496.     //RCC->AHB1ENR |= 4; /* porneste semnalul de tact al portului C */
  497. //RCC->AHB1ENR |= 1; /* porneste semnalul de tact al portului A */
  498. //GPIOA->MODER &= ~0x00000C00; /* sterge registrul de mod al portului A */
  499. //GPIOA->MODER |= 0x00000400; /* seteaza modul de iesire al pinului PA5 */
  500. //GPIOC->MODER &= ~0x00030000; /* Seteaza modul de intrare al pinului PC13 */
  501.    
  502.     char startMessageLine1[100] = {'I', 'n', 't', 'r', 'o', 'd', 'u', 'c', 'e', 't', 'i', '\0'};
  503.     char startMessageLine2[100] = {'p', 'a', 'r', 'o', 'l', 'a', ':', '\0'};
  504.     char buttonMessageLine1[100] = {'1', '\0'};
  505.     char buttonMessageLine2[100] = {'2', '\0'};
  506.     char buttonMessageLine3[100] = {'3', '\0'};
  507.     char buttonMessageLine4[100] = {'4', '\0'};
  508.     char password[100] = {'1', '2', '3', '4'};
  509.     char passwordTry[100];
  510.     char successMessageLine2[100] = {'D', 'E', 'B', 'L', 'O', 'C', 'A', 'T','\0'};
  511.     char wrongPasswordMessageLine1[100] = {'I', 'n', 'c', 'e', 'r', 'c', 'a', 'r', 'i', '\0'};
  512.     char wrongPasswordMessageLine2[100] = {'r', 'a', 'm', 'a', 's', 'e', ':', '\0'};
  513.     char noMoreTriesMessageLine1[100] = {'A', 'i', ' ', 'r', 'a', 'm', 'a', 's', ' ', 'f', 'a', 'r', 'a', '\0'};
  514.     char noMoreTriesMessageLine2[100] = {'i', 'n', 'c', 'e', 'r', 'c', 'a', 'r', 'i', '!', '\0'};
  515.     char unlockStateMessageLine[100] = {'M', 'e', 'r', 'g', 'e', '!', '\0'};
  516.     int k=0;
  517.     int tries=3;
  518.     int unlocked = 0;
  519.     while (1)
  520.     {
  521.         //writeStringLCD(startMessageLine1);
  522.         //newLine(strlen(startMessageLine1));
  523.         //writeStringLCD(startMessageLine2);
  524.         if(strcmp(password, passwordTry) == 0 && !unlocked) {
  525.             LCD_command(1);
  526.             delayMs(10);
  527.             GPIOB->ODR &=  ~0x000000F0;
  528.             writeStringLCD(successMessageLine2);
  529.             unlocked = 1;
  530.             delayMs(500);
  531.             //LCD_command(1);
  532.         } else if(k >= 4 && !unlocked){
  533.             LCD_command(1);
  534.             GPIOB->ODR |=  0x000000F0;
  535.             tries--;
  536.             writeStringLCD(wrongPasswordMessageLine1);
  537.             newLine(strlen(wrongPasswordMessageLine1));
  538.             writeStringLCD(wrongPasswordMessageLine2);
  539.             LCD_data('0' + tries);
  540.             delayMs(500);
  541.             if(tries == 0) {
  542.                 LCD_command(1);
  543.                 writeStringLCD(noMoreTriesMessageLine1);
  544.                 newLine(strlen(noMoreTriesMessageLine1));
  545.                 writeStringLCD(noMoreTriesMessageLine2);
  546.                 stopProgram();
  547.             } else {
  548.                 //GPIOB->ODR &=  ~0x000000F0;
  549.                 k=0;
  550.                 LCD_command(1);
  551.             }
  552.         }
  553.        
  554.         //if (GPIOC->IDR & 0x2000 && unlocked)
  555.         //{
  556.             //writeStringLCD(unlockStateMessageLine);
  557.             //delayMs(500);
  558.             //LCD_command(1);
  559.         //}
  560.        
  561.         if (GPIOC->IDR & 0x100 && !unlocked)
  562.         {
  563.             passwordTry[k] = '1';
  564.             LCD_data('*');
  565.             delayMs(125);
  566.             k++;
  567.         }
  568.  
  569.             //GPIOA->BSRR = 0x00000020; /* aprinde LED-ul verde */
  570.         if (GPIOC->IDR & 0x200 && !unlocked){
  571.                 passwordTry[k] = '2';
  572.                 LCD_data('*');
  573.                 delayMs(125);
  574.                 k++;
  575.             }
  576.        
  577.         if (GPIOC->IDR & 0x400 && !unlocked){
  578.                 passwordTry[k] = '3';
  579.                 LCD_data('*');
  580.                 delayMs(125);
  581.                 k++;
  582.             }
  583.        
  584.         if (GPIOC->IDR & 0x800 && !unlocked){
  585.                 passwordTry[k] = '4';
  586.                 LCD_data('*');
  587.                 delayMs(125);
  588.                 k++;
  589.             }
  590.  
  591.     }
  592.    
  593. }
  594.  
  595. /* ISRs */
  596. void TIM2_IRQHandler(void)
  597. {
  598.     TIM2->SR = 0; /* clear UIF */
  599.     TimerCountDown_U16--;
  600.     PrintInCycleMode_U8 = 1; /* time to print */
  601. }
  602.  
  603. /* Lucrarea 3*/
  604. void TIM3_IRQHandler(void)
  605. {
  606.     if (TIM3->SR & 1)
  607.     {
  608.         TIM3->SR &= ~1;
  609.         timestamp += 40 * factor;
  610.     }
  611. }
  612.  
  613. void TIM8_CC_IRQHandler(void)
  614. {
  615.     if (TIM8->SR & 8)
  616.     {
  617.         TIM8->SR &= ~8;
  618.         nr_of_pushes += 1;
  619.         capture_time += TIM8->CCR3;
  620.     }
  621. }
  622.  
  623. void SysTick_Handler(void)
  624. {
  625.     GPIOB->ODR ^= 0x00000020;
  626. }
  627.  
  628. /* Lucrarea 5 */
  629. void EXTI15_10_IRQHandler(void)
  630. {
  631.     if (EXTI->PR & 0x00000400)
  632.     {                          /* isr on pin 10 */
  633.         EXTI->PR = 0x00000400; /* clear interrupt pending flag */
  634.         GPIOB->ODR ^= 0x00000040;
  635.     }
  636.     else if (EXTI->PR & 0x00000800)
  637.     {                          /* isr on pin 11 */
  638.         EXTI->PR = 0x00000800; /* clear interrupt pending flag */
  639.         GPIOB->ODR ^= 0x00000080;
  640.     }
  641.     else if (EXTI->PR & 0x00001000)
  642.     {                          /* isr on pin 12 */
  643.         EXTI->PR = 0x00001000; /* clear interrupt pending flag */
  644.         GPIOB->ODR ^= 0x00000010;
  645.     }
  646.     else if (EXTI->PR & 0x00002000)
  647.     {                          /* isr on pin 13 */
  648.         EXTI->PR = 0x00002000; /* clear interrupt pending flag */
  649.         GPIOB->ODR ^= 0x00000020;
  650.     }
  651.     else if (EXTI->PR & 0x00004000)
  652.     {                          /* isr on pin 14 */
  653.         EXTI->PR = 0x00004000; /* clear interrupt pending flag */
  654.         GPIOB->ODR ^= 0x00000040;
  655.     }
  656.     else if (EXTI->PR & 0x00008000)
  657.     {                          /* isr on pin 15 */
  658.         EXTI->PR = 0x00008000; /* clear interrupt pending flag */
  659.         GPIOB->ODR ^= 0x00000080;
  660.     }
  661. }
  662.  
  663. void EXTI9_5_IRQHandler(void)
  664. {
  665.     if (EXTI->PR & 0x000000100)
  666.     {                          /* isr on pin 8 */
  667.         EXTI->PR = 0x00000100; /* clear interrupt pending flag */
  668.         GPIOB->ODR ^= 0x00000010;
  669.     }
  670.     else if (EXTI->PR & 0x00000200)
  671.     {                          /* isr on pin 9 */
  672.         EXTI->PR = 0x00000200; /* clear interrupt pending flag */
  673.         GPIOB->ODR ^= 0x00000020;
  674.     }
  675. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement