fork download
  1. #define Time 15
  2. #define D_numPins 10
  3. byte D_Pins[D_numPins] = {2, 3, 4, 6, 7,8,9,10,11,12};
  4. #define A_numPins 4
  5. byte A_Pins[A_numPins] = {A0, A1, A2, A3};
  6.  
  7.  
  8.  
  9. void setup() {
  10. // initialize serial
  11. Serial.begin(57600);
  12.  
  13. // initialize timer1
  14. Initialize_Timer1(Time);
  15. // initialize serial
  16. Initialize_GPIO();
  17. }
  18.  
  19.  
  20. void loop() {
  21. digitalWrite(11, LOW);
  22. digitalWrite(7, LOW);
  23.  
  24. Write_Data_To_Pin(TCNT1);
  25.  
  26. if (TIFR1 & 0x02){
  27. digitalWrite(12, HIGH);//Set Dx til high, for Test
  28. } else {
  29. digitalWrite(12, LOW);//Set Dx til low, for Test
  30. }
  31.  
  32. if (Serial.available() > 0) {
  33. int inByte = Serial.read();
  34. switch (inByte) {
  35. case '1'://Enable Timer1
  36. TCNT1 = 0;
  37. digitalWrite(7, HIGH);
  38. TIMSK1 |= (1 << OCIE1A);
  39. break;
  40. case '2'://Enable Timer1 and clear OCF1A flag
  41. TCNT1 = 0;
  42. digitalWrite(7, HIGH);
  43. TIFR1 |= (1 << OCF1A);
  44. TIMSK1 |= (1 << OCIE1A);
  45. break;
  46. case '3'://Disable Timer1
  47. TCNT1 = 0;
  48. digitalWrite(7, HIGH);
  49. TIMSK1 &= ~(1 << OCIE1A);
  50. break;
  51.  
  52. default:
  53. break;
  54. }
  55. }
  56.  
  57. }
  58. void Initialize_Timer1(int _OCR1A_Value){
  59. noInterrupts(); // disable all interrupts
  60. TCCR1A = 0;
  61. TCCR1B = 0;
  62. TCNT1 = 0;
  63.  
  64. OCR1A = _OCR1A_Value; // compare match register Freq.
  65. TCCR1B |= (1 << WGM12); // CTC mode, Mode=4
  66. TCCR1B |= (1 << CS10); //
  67. TCCR1B |= (1 << CS11); //
  68. TCCR1B |= (1 << CS12); // CS12=1,CS11=1,CS10=1, External clock source on T1 pin. Clock on rising edge.
  69. TIMSK1 &= ~(1 << OCIE1A); // disable timer compare interrupt
  70. interrupts(); // enable all interrupts
  71. }
  72.  
  73.  
  74. void Initialize_GPIO(void){
  75. for(int i = 0; i < D_numPins; i++) {
  76. pinMode(D_Pins[i], OUTPUT);
  77. digitalWrite(D_Pins[i], LOW);
  78. }
  79.  
  80. pinMode(5, INPUT);//Set D5, for Test
  81.  
  82. }
  83. void Write_Data_To_Pin(int var){
  84. digitalWrite(2, HIGH && (var & 1));
  85. digitalWrite(3, HIGH && (var & 2));
  86. digitalWrite(4, HIGH && (var & 4));
  87. digitalWrite(6, HIGH && (var & 8));
  88. // digitalWrite(7, HIGH && (var & 16));
  89. // digitalWrite(8, HIGH && (var & 32));
  90. // digitalWrite(9, HIGH && (var & 64));
  91. // digitalWrite(10, HIGH && (var & 128));
  92. }
  93. ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
  94. {
  95. digitalWrite(11, HIGH);//Set Dx til high, for Test
  96. }
  97.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:1: error: unknown type name 'byte'
 byte D_Pins[D_numPins] = {2, 3, 4, 6, 7,8,9,10,11,12};
 ^
prog.c:5:1: error: unknown type name 'byte'
 byte A_Pins[A_numPins] = {A0, A1, A2, A3};
 ^
prog.c:5:27: error: 'A0' undeclared here (not in a function)
 byte A_Pins[A_numPins] = {A0, A1, A2, A3};
                           ^
prog.c:5:31: error: 'A1' undeclared here (not in a function)
 byte A_Pins[A_numPins] = {A0, A1, A2, A3};
                               ^
prog.c:5:35: error: 'A2' undeclared here (not in a function)
 byte A_Pins[A_numPins] = {A0, A1, A2, A3};
                                   ^
prog.c:5:39: error: 'A3' undeclared here (not in a function)
 byte A_Pins[A_numPins] = {A0, A1, A2, A3};
                                       ^
prog.c: In function 'setup':
prog.c:11:3: error: 'Serial' undeclared (first use in this function)
   Serial.begin(57600);
   ^
prog.c:11:3: note: each undeclared identifier is reported only once for each function it appears in
prog.c:14:3: warning: implicit declaration of function 'Initialize_Timer1' [-Wimplicit-function-declaration]
   Initialize_Timer1(Time);
   ^
prog.c:16:3: warning: implicit declaration of function 'Initialize_GPIO' [-Wimplicit-function-declaration]
   Initialize_GPIO();
   ^
prog.c: In function 'loop':
prog.c:21:3: warning: implicit declaration of function 'digitalWrite' [-Wimplicit-function-declaration]
   digitalWrite(11, LOW);
   ^
prog.c:21:20: error: 'LOW' undeclared (first use in this function)
   digitalWrite(11, LOW);
                    ^
prog.c:24:3: warning: implicit declaration of function 'Write_Data_To_Pin' [-Wimplicit-function-declaration]
   Write_Data_To_Pin(TCNT1);
   ^
prog.c:24:21: error: 'TCNT1' undeclared (first use in this function)
   Write_Data_To_Pin(TCNT1);
                     ^
prog.c:26:7: error: 'TIFR1' undeclared (first use in this function)
   if (TIFR1 & 0x02){
       ^
prog.c:27:22: error: 'HIGH' undeclared (first use in this function)
     digitalWrite(12, HIGH);//Set Dx til high, for Test
                      ^
prog.c:32:7: error: 'Serial' undeclared (first use in this function)
   if (Serial.available() > 0) {
       ^
prog.c:38:9: error: 'TIMSK1' undeclared (first use in this function)
         TIMSK1 |= (1 << OCIE1A);
         ^
prog.c:38:25: error: 'OCIE1A' undeclared (first use in this function)
         TIMSK1 |= (1 << OCIE1A);
                         ^
prog.c:43:24: error: 'OCF1A' undeclared (first use in this function)
         TIFR1 |= (1 << OCF1A);
                        ^
prog.c: At top level:
prog.c:58:6: warning: conflicting types for 'Initialize_Timer1'
 void Initialize_Timer1(int _OCR1A_Value){
      ^
prog.c:14:3: note: previous implicit declaration of 'Initialize_Timer1' was here
   Initialize_Timer1(Time);
   ^
prog.c: In function 'Initialize_Timer1':
prog.c:59:3: warning: implicit declaration of function 'noInterrupts' [-Wimplicit-function-declaration]
   noInterrupts();           // disable all interrupts
   ^
prog.c:60:3: error: 'TCCR1A' undeclared (first use in this function)
   TCCR1A = 0;
   ^
prog.c:61:3: error: 'TCCR1B' undeclared (first use in this function)
   TCCR1B = 0;
   ^
prog.c:62:3: error: 'TCNT1' undeclared (first use in this function)
   TCNT1  = 0;            
   ^
prog.c:64:3: error: 'OCR1A' undeclared (first use in this function)
   OCR1A = _OCR1A_Value;      // compare match register Freq.
   ^
prog.c:65:19: error: 'WGM12' undeclared (first use in this function)
   TCCR1B |= (1 << WGM12);   // CTC mode, Mode=4
                   ^
prog.c:66:19: error: 'CS10' undeclared (first use in this function)
   TCCR1B |= (1 << CS10);    // 
                   ^
prog.c:67:19: error: 'CS11' undeclared (first use in this function)
   TCCR1B |= (1 << CS11);    // 
                   ^
prog.c:68:19: error: 'CS12' undeclared (first use in this function)
   TCCR1B |= (1 << CS12);    // CS12=1,CS11=1,CS10=1, External clock source on T1 pin. Clock on rising edge.
                   ^
prog.c:69:3: error: 'TIMSK1' undeclared (first use in this function)
   TIMSK1 &= ~(1 << OCIE1A); // disable timer compare interrupt
   ^
prog.c:69:20: error: 'OCIE1A' undeclared (first use in this function)
   TIMSK1 &= ~(1 << OCIE1A); // disable timer compare interrupt
                    ^
prog.c:70:3: warning: implicit declaration of function 'interrupts' [-Wimplicit-function-declaration]
   interrupts();             // enable all interrupts
   ^
prog.c: At top level:
prog.c:74:6: warning: conflicting types for 'Initialize_GPIO'
 void Initialize_GPIO(void){
      ^
prog.c:16:3: note: previous implicit declaration of 'Initialize_GPIO' was here
   Initialize_GPIO();
   ^
prog.c: In function 'Initialize_GPIO':
prog.c:76:5: warning: implicit declaration of function 'pinMode' [-Wimplicit-function-declaration]
     pinMode(D_Pins[i], OUTPUT);
     ^
prog.c:76:24: error: 'OUTPUT' undeclared (first use in this function)
     pinMode(D_Pins[i], OUTPUT);
                        ^
prog.c:77:29: error: 'LOW' undeclared (first use in this function)
     digitalWrite(D_Pins[i], LOW);
                             ^
prog.c:80:14: error: 'INPUT' undeclared (first use in this function)
   pinMode(5, INPUT);//Set D5, for Test
              ^
prog.c: At top level:
prog.c:83:6: warning: conflicting types for 'Write_Data_To_Pin'
 void Write_Data_To_Pin(int var){
      ^
prog.c:24:3: note: previous implicit declaration of 'Write_Data_To_Pin' was here
   Write_Data_To_Pin(TCNT1);
   ^
prog.c: In function 'Write_Data_To_Pin':
prog.c:84:21: error: 'HIGH' undeclared (first use in this function)
     digitalWrite(2, HIGH && (var & 1));
                     ^
prog.c: At top level:
prog.c:93:1: warning: return type defaults to 'int' [-Wimplicit-int]
 ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
 ^
prog.c: In function 'ISR':
prog.c:93:1: warning: type of 'TIMER1_COMPA_vect' defaults to 'int' [-Wimplicit-int]
prog.c:95:21: error: 'HIGH' undeclared (first use in this function)
    digitalWrite(11, HIGH);//Set Dx til high, for Test
                     ^
prog.c:96:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty