[APL] Vidéo avec Arduino, afficher sur moniteur

Dans la suite des expérimentations, voici la version sous interruption :

#define _SYNC 0x00
#define _BLACK  0x01
#define _GRAY  0x02
#define _WHITE  0x03

// compensation chargement us de 1 incluse
/*
#define _NORMAL_SYNC 32
#define _LONG_SYNC 240
#define _SHORT_SYNC 16
#define _LONG_SYNC_DELAI 16
#define _SHORT_SYNC_DELAI 240
*/

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

byte memVideo[_NB_PIXELS][_NB_LIGNES];
byte index, index2;
int noligne = 0;
byte diviseur = 0;

SIGNAL(SIG_OVERFLOW0)
{
  TCNT0 = 256 - 128;
  PORTB = _SYNC;
      
  if (noligne == 3 || noligne == 4)
  {
    // SYNCHRO
    while (TCNT0 < 128 + 4); // 2 uS
        
    PORTB = _BLACK;
    while (TCNT0 < 128 + 60 + 4); // 32 us 
    
    PORTB = _SYNC;
    while (TCNT0 < 128 + 60 + 4 + 4);
    
    PORTB = _BLACK;
  }
    
  // fin
  if (noligne >= 309)
  {
    // SHORT
    while (TCNT0 < 128 + 4); // 2 uS
    
    PORTB = _BLACK;
    while (TCNT0 < 128 + 60 + 4); // 32 us
    
    // SHORT
    PORTB = _SYNC;
    while (TCNT0 < 128 + 60 + 4 + 4);
    
    PORTB = _BLACK;
  }

  // image
  if (noligne >= 5 && noligne < 309)
  {
    // SYNC
    while (TCNT0 < 128 + 8);
    
    PORTB = _BLACK; // porch
    while (TCNT0 < 128 + 8 + 8);
    
    //** image ligne 52 uS
//    if (noligne >= 16 && noligne < 304)
      for (index = 0; index < _NB_PIXELS; index++)
      {
        PORTB = memVideo[index][(noligne>>4)];
        PORTB = PORTB;
        PORTB = PORTB;
      }
    
    PORTB = _BLACK;
  }
  
  if (noligne < 2)
  {
    // SYNCHRO
    while (TCNT0 < 128 + 60);
    
    PORTB = _BLACK;
    while (TCNT0 < 128 + 60 + 4);

    PORTB = _SYNC;
    while (TCNT0 < 128 + 60 + 4 + 60);

    PORTB = _BLACK;
  }
      
  // COMPTEUR LIGNE
  if (noligne == 311)
    noligne = 0;
  else
    noligne++;
}

void InitTimer()
{
  #if defined(__AVR_ATmega168__)
      sbi(TCCR0A, WGM01);
      sbi(TCCR0A, WGM00);
  #endif  
      // set timer 0 prescale factor to 8
  #if defined(__AVR_ATmega168__)
        cbi(TCCR0B, CS02);
      sbi(TCCR0B, CS01);
      cbi(TCCR0B, CS00);
  #else
        cbi(TCCR0, CS02);
      sbi(TCCR0, CS01);
      cbi(TCCR0, CS00);
  #endif

      // enable timer 0 overflow interrupt
  #if defined(__AVR_ATmega168__)
        sbi(TIMSK0, TOIE0);
  #else
        sbi(TIMSK, TOIE0);
  #endif
}

void setup()
{
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  digitalWrite (8, HIGH);
  digitalWrite (9, HIGH);

  Serial.begin(19200);
  Serial.print ("GO");
  Serial.print (13, BYTE);
  
  for (index2 = 0; index2 < _NB_LIGNES; index2++)
     for (index = 0; index < _NB_PIXELS; index++)
     {
       /*memVideo[index][index2] = _BLACK;*/
       memVideo[index][index2] = (index + index2) % 3 + 1;
     }

  memVideo[2][2] = _WHITE;

  InitTimer();
}

int ligne;
char car;
int cx=0, cy=0;
byte couleur = _BLACK;

void loop()
{

}

Cette version fonctionne et tente de s'affranchir des problème de temporisation. Il y a encore quelques comportements que je ne comprends pas mais je vous la livre pour que vous puissiez aussi y regarder...

Il vous faudra mettre en commentaire la fonction "SIGNAL(SIG_OVERFLOW0)" dans le fichier wiring.c comme ceci :

/*
SIGNAL(SIG_OVERFLOW0)
{
      timer0_overflow_count++;
}
*/

woula !