#include "C:\RS\Prog\infra\infra.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[26*5]={0b00000001,0b11110110,0b11110110,0b11110110,0b00000001,
                        0b00000001,0b11110110,0b11110110,0b11110110,0b00000001,
                        0b10000001,0b01111110,0b01111110,0b01111110,0b10111101,
                        0b00000000,0b01111110,0b01111110,0b01111110,0b10000001,
                        0b00000000,0b01110110,0b01110110,0b01111110,0b01111110,
                        0b00000000,0b11110110,0b11110110,0b11111110,0b11111110,
                        0b10000001,0b01111110,0b01110110,0b01110110,0b10000101,
                        0b00000000,0b11110111,0b11110111,0b11110111,0b00000000,
                        0b01111110,0b01111110,0b00000000,0b01111110,0b01111110,
                        0b10111110,0b01111110,0b01111110,0b01111110,0b10000000,
                        0b00000000,0b11110111,0b11110111,0b11101011,0b00011100,
                        0b00000000,0b01111111,0b01111111,0b01111111,0b01111111,
                        0b00000000,0b11111110,0b11110000,0b11111110,0b00000000,
                        0b00000000,0b11101111,0b11011111,0b10111111,0b00000000,
                        0b10000001,0b01111110,0b01111110,0b01111110,0b10000001,
                        0b00000000,0b11110110,0b11110110,0b11110110,0b11111001,
                        0b10000001,0b01111110,0b01111110,0b01111110,0b00000001,
                        0b00000000,0b11110110,0b11110110,0b11110110,0b00001001,
                        0b10111001,0b01110110,0b01110110,0b01110110,0b10001101,
                        0b11111110,0b11111110,0b00000000,0b11111110,0b11111110,
                        0b10000000,0b01111111,0b01111111,0b01111111,0b10000000,
                        0b11000000,0b10111111,0b01111111,0b10111111,0b11000000,
                        0b10000000,0b01111111,0b10000000,0b01111111,0b10000000,
                        0b00011100,0b11101011,0b11110111,0b11101011,0b00011100,
                        0b11111000,0b11110111,0b00000111,0b11110111,0b11111000,
                        0b00011110,0b01101110,0b01110110,0b01111010,0b01111100};
                              
   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]);
               output_B(pis[1*5+sloupec]);
               delay_ms(1);
            }
            delay_ms(2);
         }
      }
   }   
}