Advertisement
Guest User

sw4update

a guest
Nov 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <stdbool.h>
  4. #include <system.h>
  5. #include "alt_types.h"
  6. #include <sys/alt_alarm.h>
  7.  
  8. #define SEGA 0x00001
  9. #define SEGB 0x00002
  10. #define SEGC 0x00004
  11. #define SEGD 0x00008
  12. #define SEGE 0x00010
  13. #define SEGF 0x00020
  14. #define SEGG 0x00040
  15.  
  16. #define ZERO SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
  17. #define ONE SEGB | SEGC
  18. #define TWO SEGA | SEGB | SEGG| SEGE | SEGD
  19. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  20. #define FOUR SEGB | SEGC | SEGF | SEGG
  21. #define FIVE SEGG | SEGC | SEGA | SEGD | SEGF
  22. #define CHE SEGA | SEGD | SEGE | SEGF | SEGG
  23. #define CHR SEGE | SEGG
  24.  
  25. void hexOff(){
  26. IOWR(HEX_BASE, 0, 0);
  27. IOWR(HEX_BASE, 1, 0);
  28. IOWR(HEX_BASE, 2, 0);
  29. IOWR(HEX_BASE, 3, 0);
  30. IOWR(HEX_BASE, 4, 0);
  31. IOWR(HEX_BASE, 5, 0);
  32. }
  33.  
  34. int main()
  35. {
  36.  
  37. int sw;
  38.  
  39. int s1on, s2on, s3on, s4on, s5on, seof;
  40. bool io1 = false, io2 = false, io3 = false, io4 = false, io5 = false, ioe = false;
  41. bool swOn = false;
  42. int switches;
  43. int x = alt_ticks_per_second();
  44.  
  45.  
  46. while(1){
  47. //printf("t1 %d t2 %d \n", alt_nticks(), alt_ticks_per_second());
  48.  
  49. switches = IORD(SW_SLIDERS_BASE,0) & 0b00111111;
  50.  
  51. switch(switches) {
  52. case 0:
  53. IOWR(HEX_7_BASE, 0, ZERO);
  54. if(io1){
  55. if(alt_nticks() - s1on >= x*1){
  56. io1 = false;
  57. IOWR(LEDS_RED_BASE, 0, 0);
  58. }
  59. }
  60. else if(io2){
  61. if(alt_nticks() - s2on >= x*2){
  62. io2 = false;
  63. IOWR(LEDS_RED_BASE, 0, 0);
  64. }
  65. }
  66. else if(io3){
  67. if(alt_nticks() - s3on >= x*3){
  68. io3 = false;
  69. IOWR(LEDS_RED_BASE, 0, 0);
  70. }
  71. }
  72. else if(io4){
  73. if(alt_nticks() - s4on >= x*4){
  74. io4 = false;
  75. IOWR(LEDS_RED_BASE, 0, 0);
  76. }
  77. }
  78. else if(io5){
  79. if(alt_nticks() - s5on >= x*5){
  80. io5 = false;
  81. IOWR(LEDS_RED_BASE, 0, 0);
  82. }
  83. }
  84.  
  85. break;
  86.  
  87. case 1 :
  88. IOWR(HEX_7_BASE, 0, ONE);
  89.  
  90.  
  91. if (!io1){
  92. s1on=alt_nticks();
  93. io1=true;
  94. }
  95. if(alt_nticks()-s1on >= x*1){
  96. IOWR(LEDS_RED_BASE, 0, 4);
  97. IOWR(LEDS_RED_BASE, 0, 8);
  98. IOWR(LEDS_RED_BASE, 0, 64);
  99. IOWR(LEDS_RED_BASE, 0, 2048);
  100. }
  101. }
  102.  
  103. break;
  104. case 2 :
  105.  
  106. IOWR(HEX_7_BASE, 0, TWO);
  107.  
  108. if (!io2){
  109. s2on=alt_nticks();
  110. io2=true;
  111. }
  112. if (alt_nticks()- s2on >= x*2){
  113. IOWR(LEDS_RED_BASE, 0, 2);
  114. IOWR(LEDS_RED_BASE, 0, 8);
  115. IOWR(LEDS_RED_BASE, 0, 16);
  116. IOWR(LEDS_RED_BASE, 0, 64);
  117. IOWR(LEDS_RED_BASE, 0, 128);
  118. IOWR(LEDS_RED_BASE, 0, 1024);
  119. }
  120. }
  121.  
  122. break;
  123.  
  124. case 4 :
  125. IOWR(HEX_7_BASE, 0, THREE);
  126.  
  127. if (!io3){
  128. s3on=alt_nticks();
  129. io3=true;
  130. }
  131.  
  132. if(alt_nticks()-s3on >= x*3){
  133. IOWR(LEDS_RED_BASE, 0, 1);
  134. IOWR(LEDS_RED_BASE, 0, 32);
  135. IOWR(LEDS_RED_BASE, 0, 256);
  136. IOWR(LEDS_RED_BASE, 0, 512);
  137. }
  138. }
  139.  
  140. break;
  141. case 8 :
  142.  
  143. IOWR(HEX_7_BASE,0 ,FOUR);
  144.  
  145. if (!io4){
  146. s4on=alt_nticks();
  147. io4=true;
  148. }
  149.  
  150. if(alt_nticks()-s4on >= x*4){
  151. IOWR(LEDS_RED_BASE, 0, 1);
  152. IOWR(LEDS_RED_BASE, 0, 2);
  153. IOWR(LEDS_RED_BASE, 0, 16);
  154. IOWR(LEDS_RED_BASE, 0, 128);
  155. IOWR(LEDS_RED_BASE, 0, 512);
  156. IOWR(LEDS_RED_BASE, 0, 1024);
  157. }
  158. }
  159.  
  160. break;
  161. case 16 :
  162. IOWR(HEX_7_BASE,0 ,FIVE);
  163.  
  164. if (!io5){
  165. s5on=alt_nticks();
  166. io5=true;
  167. }
  168. if(alt_nticks()-s4on >= x*5){
  169. IOWR(LEDS_RED_BASE, 0, 2);
  170. IOWR(LEDS_RED_BASE, 0, 16);
  171. IOWR(LEDS_RED_BASE, 0, 128);
  172. IOWR(LEDS_RED_BASE, 0, 1024);
  173. }
  174. }
  175.  
  176. break;
  177.  
  178. default:
  179.  
  180. IOWR(HEX_7_BASE,2, CHE);
  181. IOWR(HEX_7_BASE,1, CHR);
  182. IOWR(HEX_7_BASE,0, CHR);
  183. /*
  184. if(ssw==2){
  185. printf("%d", (alt_nticks()-sw1));
  186. if(alt_nticks()-sw1 >= x*2){
  187. IOWR(LEDS_RED_BASE, 0, 0);
  188.  
  189. }
  190. }
  191. if(ssw==3){
  192. if(alt_nticks()-sw1 >= x*3){
  193. IOWR(LEDS_RED_BASE, 0, 0);
  194.  
  195. }
  196. }
  197.  
  198. if(ssw==4){
  199. if(alt_nticks()-sw1 >= x*4){
  200. IOWR(LEDS_RED_BASE, 0, 0);
  201. }
  202. }
  203.  
  204. if(ssw==5){
  205. if(alt_nticks()-sw1 >= x*5){
  206. IOWR(LEDS_RED_BASE, 0, 0);
  207. }
  208. }
  209. */
  210. sw1=0;
  211. ssw=0;
  212. }
  213. }
  214.  
  215. return 0;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement