0% found this document useful (0 votes)
5 views10 pages

Practica 2

The document contains multiple exercises written in C++ that demonstrate the initialization and use of various hardware components such as GPIO, PWM, and RTI in embedded systems. Each exercise includes a main function that sets up the necessary configurations and implements specific functionalities based on input states. The code snippets illustrate how to manage interrupts and control hardware signals in a loop.

Uploaded by

abrasoto50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Practica 2

The document contains multiple exercises written in C++ that demonstrate the initialization and use of various hardware components such as GPIO, PWM, and RTI in embedded systems. Each exercise includes a main function that sets up the necessary configurations and implements specific functionalities based on input states. The code snippets illustrate how to manage interrupts and control hardware signals in a loop.

Uploaded by

abrasoto50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Practica 2

Abraham Soto Olvera


May 2025

1 Ejercicio 1
1

3 /* USER CODE BEGIN (0) */


4 /* USER CODE END */
5

6 /* Include Files */
7

8 # include " sys_common . h "


9

10 /* USER CODE BEGIN (1) */


11 # include " gio . h "
12 # include " rti . h "
13 # include " mibspi . h "
14 /* USER CODE END */
15

16 /* * @fn void main ( void )


17 * @brief Application main function
18 * @note This function is empty by default .
19 *
20 * This function is called after startup .
21 * The user can use this function to implement the
application .
22 */
23

24 /* USER CODE BEGIN (2) */


25 int estado2 ;
26 int est ;
27 /* USER CODE END */
28

29 int main ( void )


30 {
31 /* USER CODE BEGIN (3) */
32 gioInit () ;
33 mibspiInit () ;
34 rtiInit () ;

1
35 _enable_IRQ () ; // habilitar todas las interrupciones
36 gio Enab leNot ific ation ( gioPORTA , 6) ; // habilitar
interrupciones en gioA6
37 rtiStartCounter ( rtiCOUNTER_BLOCK0 ) ;
38 rti Enab leNot ific ation ( r t i N OT I F I CA T I O N_ C O M PA R E 0 ) ;
39

40

41

42 while (1)
43 {
44 estado2 = gioGetBit ( mibspiPORT1 , 4) ;
45

46

47 if ( estado2 ==0 && est == 1)


48 {
49 gioToggleBit ( gioPORTB , 1) ;
50 }
51

52 est = estado2 ;
53

54 }
55 /* USER CODE END */
56

57 return 0;
58 }
59

60

61 /* USER CODE BEGIN (4) */


62 /*
63 void gioNotification ( gioPORT_t * port , uint32 bit )
64 {
65 gioToggleBit ( gioPORTB , 2) ;
66 }
67 */
68

69 void rtiNotification ( uint32 notification )


70 {
71 gioToggleBit ( gioPORTB , 1) ;
72 }
73

74 /* USER CODE END */


Listing 1: Ejemplo de código C++

2 Ejercicio 2
1

2 /* USER CODE BEGIN (0) */

2
3 /* USER CODE END */
4

5 /* Include Files */
6

7 # include " sys_common . h "


8

9 /* USER CODE BEGIN (1) */


10 # include " gio . h "
11 # include " mibspi . h "
12 # include " het . h "
13 # include " rti . h "
14 /* USER CODE END */
15

16 /* * @fn void main ( void )


17 * @brief Application main function
18 * @note This function is empty by default .
19 *
20 * This function is called after startup .
21 * The user can use this function to implement the
application .
22 */
23

24 /* USER CODE BEGIN (2) */


25 int P =500000;
26 int anterior =1;
27 int i =0;
28 int boton =0;
29 int D =50;
30 int delay =0;
31 int estado = 0;
32 int contador_ms = 0;
33 hetSIGNAL_t signal ;
34 /* USER CODE END */
35

36 int main ( void )


37 {
38 /* USER CODE BEGIN (3) */
39 gioInit () ;
40 hetInit () ;
41 mibspiInit () ;
42

43 rtiInit () ;
44 pwmStart ( hetRAM1 , pwm0 ) ;
45 _enable_IRQ () ; // habilitar todas las
interrupciones
46 rtiStartCounter ( rtiCOUNTER_BLOCK0 ) ;
47 rti Enab leNot ific ation ( r t i N OT I F I CA T I O N_ C O M PA R E 0 ) ;
48

49

50 while (1)

3
51 {
52

53 estado = gioGetBit ( mibspiPORT1 , 4) ;


54 /*
55

56 if ( delay ==1)
57 {
58 for ( i =0; i <=1000000; i ++) {
59

60 }
61 delay =0;
62 } */
63

64 if ( estado == 0 && anterior ==1)


65 {
66 D =50;
67

68 P = P +500000;
69 boton = 1;
70 }
71 if ( estado == 1 && anterior == 0)
72 {
73 boton = 0;
74 contador_ms = 0;
75 }
76 anterior = estado ;
77 if (P >2000000)
78 {
79 P =500000;
80 }
81

82 signal . period = P ;
83 signal . duty = D ;
84 pwmSetSignal ( hetRAM1 , pwm0 , signal ) ;
85

86

87 i = gioGetBit ( hetPORT1 , 8) ;
88

89

90 gioSetBit ( gioPORTB ,1 , i ) ;
91

92 }
93 /* USER CODE END */
94

95 return 0;
96 }
97

98

99 /* USER CODE BEGIN (4) */


100

4
101

102 void rtiNotification ( uint32 notification )


103 {
104 if ( boton ==1)
105 {
106 contador_ms ++;
107

108

109 if ( contador_ms >= 3000)


110 {
111 D =0;
112 boton = 0;
113 P =500000;
114

115

116

117 }
118

119

120 }
121 }
122 /* USER CODE END */
Listing 2: Ejemplo de código C++

3 Ejercicio 3
1

2 /* USER CODE BEGIN (0) */


3 /* USER CODE END */
4

5 /* Include Files */
6

7 # include " sys_common . h "


8

9 /* USER CODE BEGIN (1) */


10 # include " gio . h "
11 # include " mibspi . h "
12 # include " rti . h "
13 /* USER CODE END */
14

15 /* * @fn void main ( void )


16 * @brief Application main function
17 * @note This function is empty by default .
18 *
19 * This function is called after startup .
20 * The user can use this function to implement the
application .

5
21 */
22

23 /* USER CODE BEGIN (2) */


24 int contador_ms =0;
25 int estado =1;
26

27

28 /* USER CODE END */


29

30 int main ( void )


31 {
32 /* USER CODE BEGIN (3) */
33 gioInit () ;
34 mibspiInit () ;
35

36 rtiInit () ;
37 _enable_IRQ () ; // habilitar todas las
interrupciones
38 rtiStartCounter ( rtiCOUNTER_BLOCK0 ) ;
39 rti Enab leNot ific ation ( r t i N OT I F I CA T I O N_ C O M PA R E 0 ) ;
40

41

42 while (1)
43 {
44 estado = gioGetBit ( mibspiPORT1 , 4) ;
45

46

47 if ( contador_ms >=1 && contador_ms <=500)


48 {
49 gioSetBit ( gioPORTB ,1 ,1) ;
50 }
51 if ( contador_ms >=500 && contador_ms <=1000)
52 {
53 gioSetBit ( gioPORTB ,1 ,0) ;
54 }
55

56 if ( contador_ms >=1000 && contador_ms <=1500)


57 {
58 gioSetBit ( gioPORTB ,2 ,0) ;
59 }
60

61

62 if ( estado ==0 && contador_ms >=2900)


63 {
64 gioSetBit ( gioPORTB ,2 ,1) ;
65 }
66 }
67

68

69 /* USER CODE END */

6
70

71 return 0;
72 }
73

74

75 /* USER CODE BEGIN (4) */


76 void rtiNotification ( uint32 notification )
77 {
78

79 contador_ms ++;
80

81

82 if ( contador_ms >= 3000)


83 {
84 contador_ms =0;
85

86

87

88 }
89

90

91

92 }
93 /* USER CODE END */
Listing 3: Ejemplo de código C++

4 Ejercico 4
1

3 /* USER CODE BEGIN (0) */


4 /* USER CODE END */
5

6 /* Include Files */
7

8 # include " sys_common . h "


9

10 /* USER CODE BEGIN (1) */


11 # include " het . h "
12 # include " gio . h "
13 /* USER CODE END */
14

15 /* * @fn void main ( void )


16 * @brief Application main function
17 * @note This function is empty by default .
18 *
19 * This function is called after startup .

7
20 * The user can use this function to implement the
application .
21 */
22

23 /* USER CODE BEGIN (2) */


24 int cont =0;
25 int i =0;
26 int b =0;
27 hetSIGNAL_t signal ;
28 hetSIGNAL_t signal2 ;
29 /* USER CODE END */
30

31 int main ( void )


32 {
33 /* USER CODE BEGIN (3) */
34 hetInit () ;
35 gioInit () ;
36 _enable_IRQ () ; // habilitar todas las interrupciones
37 pwmStart ( hetRAM1 , pwm0 ) ;
38 pwmStart ( hetRAM1 , pwm1 ) ;
39

40 pwm Enab leNot ific atio n ( hetREG1 , pwm0 , pwmEND_OF_PERIOD ) ;


41

42 signal . duty = 50;


43 signal . period = 300000;
44 pwmSetSignal ( hetRAM1 , pwm0 , signal ) ;
45 pwmSetSignal ( hetRAM1 , pwm1 , signal ) ;
46

47 while (1)
48 {
49

50

51 /*
52

53 i = gioGetBit ( hetPORT1 , 10) ;


54

55

56 gioSetBit ( gioPORTB ,1 , i ) ;
57

58

59

60 i = gioGetBit ( hetPORT1 , 10) ;


61 gioSetBit ( gioPORTB ,1 , i ) ;
62 if ( i == 1 && b ==0)
63 {
64 cont = cont + 1;
65 }
66

67 b = i ; */
68 i = gioGetBit ( hetPORT1 , 10) ;

8
69

70

71 gioSetBit ( gioPORTB ,1 , i ) ;
72

73 }
74

75

76

77 /* USER CODE END */


78

79 return 0;
80 }
81

82

83 /* USER CODE BEGIN (4) */


84 void pwmNotification ( hetBASE_t * hetREG , uint32 pwm , uint32
notification )
85 {
86

87

88 cont ++;
89 // gioToggleBit ( gioPORTB , 1) ;
90

91 if ( cont >= 0 && cont <= 10)


92 {
93 signal . duty = 50;
94 signal . period = 300000;
95 signal2 . duty = 50;
96 signal2 . period = 300000;
97 }
98 else if ( cont > 10 && cont <= 20)
99 {
100 signal . duty = 50;
101 signal . period = 800000;
102 signal2 . duty = 50;
103 signal2 . period = 800000;
104 }
105 else if ( cont > 20 && cont <= 30)
106 {
107 signal . duty = 50;
108 signal . period = 800000;
109 signal2 . duty = 0;
110 signal2 . period =800000;
111 }
112 else if ( cont > 30)
113 {
114 cont = 0;
115 }
116

117 pwmSetSignal ( hetRAM1 , pwm0 , signal ) ;

9
118 pwmSetSignal ( hetRAM1 , pwm1 , signal2 ) ;
119

120

121 // cont ++;


122 // gioToggleBit ( gioPORTB , 1) ;
123

124

125 /*
126 if ( cont >=0 && cont <=10)
127 {
128

129 signal . duty =50;


130 signal . period =300000;
131 pwmSetSignal ( hetRAM1 , pwm1 , signal ) ;
132 }
133 else if ( cont >=11 && cont <=20)
134 {
135 signal . duty =50;
136 signal . period =800000;
137 pwmSetSignal ( hetRAM1 , pwm1 , signal ) ;
138 }
139 else if ( cont >=21 && cont <=30)
140 {
141 signal . duty =0;
142 signal . period =1000000;
143 pwmSetSignal ( hetRAM1 , pwm1 , signal ) ;
144 }
145

146 else if ( cont >30)


147 {
148 cont =0;
149 }
150 */
151 }
152 /* USER CODE END */
Listing 4: Ejemplo de código C++

10

You might also like