#include "abcda.h"

#define MAX_SLOVO 10   // Maximalni pocet znaku ve slovu

int8 napis[2*MAX_SLOVO] ={'A','A','A','A','A','A','A','A','A','A','A','A','A','A','A','A','A','A','A','A'};

#int_RDA
void  RDA_isr(void) 
{
   int n;
   output_B(0x55);
   for(n=0;n<(MAX_SLOVO*2);n++)
   {
      napis[n]=getc();
      restart_WDT();
   }
}

void main()
{

   int slovo,pismeno,sloupec,j;


   const int8 pis[2*5]={0b00000001,0b11110110,0b11110110,0b11110110,0b00000001,
                        0b00000001,0b11110110,0b11110110,0b11110110,0b00000001};
      
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_wdt(WDT_2304MS);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   set_adc_channel(0);

   while(TRUE)
   {
      for(slovo=0;slovo<2;slovo++)
      for(j=0;j<=100;j++)   // Jedno slovo se zobrazi stokrat
      {
         while(read_adc()<10);            // Cekani na magnet
         
         for(pismeno=0;pismeno<MAX_SLOVO;pismeno++)
         {
            for(sloupec=0;sloupec<5;sloupec++)
            {
               output_B(pis[(napis[slovo*MAX_SLOVO+pismeno]-0x40)*5+sloupec]);
               delay_ms(1);
            }
            delay_ms(2);
         }
      }
   }   
}