Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. // problema 3, laborator 1
  2.  
  3.  
  4. unsigned int i;
  5.  
  6.  
  7. int var;
  8. //variabila folosit pentru a trece de la un led la altul
  9. // ledul 6
  10. int led1=6;
  11. // ledul 11 shiftat cu 2 la dreapta
  12. int led2=13;
  13.  
  14. //direction register
  15. *pPORTFIO_DIR=0x0FFC;
  16.  
  17. *pPORTFIO_DIR&= ~((1<<3)|(1<<4));
  18.  
  19. //input enable register
  20. *pPORTFIO_INEN=0x00018;
  21.  
  22. while(1) {
  23.  
  24. //folosim butonul 4.
  25.  
  26. //reset
  27. if((*pPORTFIO&(1<<4))!=0)) {
  28.  
  29. *pPORTFIO=0x0000;
  30.  
  31. for(i=0;i<1000;i++);
  32.  
  33. if((*pPORTFIO&(1<<4))!=0)){
  34. //cat timp butonul este apasat
  35.  
  36. while((*pPORTFIO&(1<<4))!=0));
  37.  
  38. //aprindem ledul urmator
  39. *pPORTFIO|= (1<<var);
  40.  
  41. //in acelasi timp se stinge cel anterior
  42.  
  43. *pPORTFIO&=~(1<<var-1);
  44.  
  45. //se trece la urmatorul
  46.  
  47. var++;
  48.  
  49. //
  50. if(led1==13) {
  51.  
  52. *pPORTFIO&=~(1<<12);
  53.  
  54. led1=6;
  55.  
  56. *pPORTFIO|=(1<<6);}}}}
  57.  
  58. // laborator 2
  59.  
  60. #include <sys/platform.h>
  61. #include <adi_initialize.h>
  62. #include <test.h>
  63. #include <cdefbf537.h>
  64. #include <sys/exception.h>
  65.  
  66. volatile unsigned int i;
  67. EX_INTERRUPT_HANDLER(ISR_TIMER7){
  68. //for(i=0;i<9999;i++)
  69. i++;
  70. if(i%2==0)
  71. *pPORTFIO &= ~ (1<<9);
  72. else
  73. *pPORTFIO |= (1<<9);
  74. *pTIMER_STATUS=0x00000000;
  75. }
  76.  
  77. void initInterrupts(void) {
  78. *pSIC_IAR3 = 0xFFFFF5FF;
  79. *pSIC_MASK = 0x04000000;
  80. register_handler(ik_ivg12, ISR_Timer7);
  81. }
  82. int main(int argc, char *argv[]){
  83. int i;
  84. //alegem led-urile ca iesiri
  85.  
  86. *pPORTFIO_DIR=0xFFCF;
  87.  
  88. //configurare timer
  89.  
  90. *pTIMER7_CONFIG = 0x001D;
  91.  
  92. //perioada timer, perioada de numarare = 0.5
  93.  
  94. *pTIMER_PERIOD = 0x17D7840;
  95.  
  96. *pTIMER_ENABLE = 0x0080;
  97.  
  98. //oprim led-urile
  99.  
  100. *pPORTFIO = 0x0000;
  101.  
  102. initInterrupts();
  103. while(1){
  104. };
  105. //*pTIMER_STATUS &= ~(1<<19);
  106.  
  107. /* while(1) {
  108. if((*pTIMER_STATUS&=(1<<19))!=0) {
  109.  
  110. i++;
  111. if(i%2==0)
  112. *pPORTFIO &= ~(1<<9);
  113. else
  114. *pPORTFIO |= (1<<9);
  115. }
  116. }*/
  117. return 0;
  118. }
  119.  
  120.  
  121.  
  122.  
  123. #include <sys/platform.h>
  124. #include "adi_initialize.h"
  125. #include "hau.h"
  126. #include <cdefBF537.h>
  127.  
  128.  
  129. char __argv_string[] = "";
  130.  
  131. void config() {
  132. *pTIMER7_CONFIG |= 1;
  133. *pTIMER7_CONFIG &= ~(1 << 1);
  134. *pTIMER7_CONFIG |= (1 << 3);
  135. *pTIMER7_CONFIG |= (1 << 4);
  136. *pPORTFIO_DIR |= (1 << 6);
  137. *pTIMER7_PERIOD = 10000000;
  138. *pPORTFIO_DIR &= ~(1 << 4); //up
  139. *pPORTFIO_INEN |= 1 << 4;
  140. *pPORTFIO_DIR &= ~(1 << 5); //down
  141. *pPORTFIO_INEN |= 1 << 5;
  142. }
  143.  
  144.  
  145. int main(int argc, char *argv[])
  146. {
  147.  
  148. volatile unsigned int i;
  149. adi_initComponents();
  150.  
  151. config();
  152.  
  153. *pTIMER_ENABLE |= (1 << 7);
  154. *pTIMER_DISABLE &= ~(1 << 7);
  155.  
  156. volatile unsigned sw = 0;
  157. while(1) {
  158. if ((*pPORTFIO & (1 << 4))) {
  159. for (i=0; i<800; i++);
  160. if ((*pPORTFIO & (1 << 4)) && *pTIMER7_PERIOD != 100000000) {
  161. while((*pPORTFIO & (1 << 4)));
  162. *pTIMER_ENABLE &= ~(1 << 7);
  163. *pTIMER_DISABLE |= (1 << 7);
  164. *pTIMER7_PERIOD +=
  165. 0;
  166. *pTIMER_DISABLE &= ~(1 << 7);
  167. *pTIMER_ENABLE |= (1 << 7);
  168. }
  169. }
  170.  
  171. if ((*pPORTFIO & (1 << 5))) {
  172. for (i=0; i<800; i++);
  173. if ((*pPORTFIO & (1 << 5)) && *pTIMER7_PERIOD != 2000000) {
  174. while((*pPORTFIO & (1 << 5)));
  175. *pTIMER_ENABLE &= ~(1 << 7);
  176. *pTIMER_DISABLE |= (1 << 7);
  177. *pTIMER7_PERIOD -= 2000000;
  178. *pTIMER_DISABLE &= ~(1 << 7);
  179. *pTIMER_ENABLE |= (1 << 7);
  180. }
  181. }
  182.  
  183. if ((*pTIMER_STATUS & (1 << 19))) {
  184. if (sw) {
  185. *pPORTFIO &= ~(1 << 6);
  186. sw = 0;
  187. }
  188. else {
  189. *pPORTFIO |= (1 << 6);
  190. sw = 1;
  191. }
  192. *pTIMER_STATUS |= (1 << 19);
  193. }
  194.  
  195. }
  196.  
  197. return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement