fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define uchar unsigned char
  6. #define uint unsigned int
  7.  
  8. void secint(void); //timer isr per second
  9. void print_byte(char byte); //converted to binary formatted
  10.  
  11. struct{
  12. uint delay;
  13. uchar pattern;
  14. } cycle[] = {
  15.  
  16. {1, 0x12}, //0
  17. {3, 0x41}, //1
  18. {1, 0x21}, //2
  19. {5, 0x14}, //3
  20. {3, 0xc1}, //4
  21. {5, 0x1c} //5
  22. };
  23.  
  24. const char* bit_rep[16] = {
  25. [ 0] = "0000", [ 1] = "0001", [ 2] = "0010", [ 3] = "0011",
  26. [ 4] = "0100", [ 5] = "0101", [ 6] = "0110", [ 7] = "0111",
  27. [ 8] = "1000", [ 9] = "1001", [10] = "1010", [11] = "1011",
  28. [12] = "1100", [13] = "1101", [14] = "1110", [15] = "1111",
  29. };
  30.  
  31. uchar walk, LEDS;
  32.  
  33. void main(void){
  34. /*initialize*/
  35. clock_t start_t = 0, end_t = 0;
  36.  
  37. while(1){
  38. if(end_t-start_t){
  39. start_t = end_t;
  40. /*inerrupt function*/
  41. secint();
  42. }
  43. else{
  44. end_t = clock() / CLOCKS_PER_SEC;
  45. /*main program*/
  46. walk=2;
  47. }
  48. }
  49. printf("should not be here\n");
  50. }
  51.  
  52. void secint(void){
  53. static uchar count;
  54. static uchar index;
  55. static uint countdown;
  56. uchar i;
  57.  
  58. count++;
  59. printf("count = %d\n",count);
  60. LEDS=cycle[i].pattern; print_byte(LEDS);
  61. countdown = cycle[i].delay;
  62.  
  63. if(--countdown == 0){
  64. index++;
  65. if(index==4)index=0;
  66. switch(index){
  67. case 1:
  68. if((walk&0x2) == 2){
  69. printf("should be here\n");
  70. walk = walk & 0xfd;
  71. printf("walk = %d\n", walk);
  72. i=index+3;
  73. printf("i = %d\n", i);
  74. }
  75. break;
  76. case 3:
  77. if((walk&0x1) == 1){
  78. walk= walk & 0xfe;
  79. i=index+2;
  80. }
  81. break;
  82. default: i=index;
  83. }
  84. }
  85. }
  86. void print_byte(char byte){
  87. printf("%s %s\n", bit_rep[byte>>4], bit_rep[byte&0x0f]);
  88. }
  89.  
Time limit exceeded #stdin #stdout 5s 9424KB
stdin
Standard input is empty
stdout
Standard output is empty