Subversion Repositories svnkaklik

Rev

Rev 410 | Blame | Compare with Previous | Last modification | View Log | Download

#include ".\hack.h"
#include <stdlib.h>

#define SYNC   PIN_B4      // Spousteni oscyloskopu
#define HACK   PIN_B5      // Zkratovani napajeni SmartCard
#define CLOCK  PIN_B6      // Hodiny ze SmartCard

#int_TIMER1
TIMER1_isr()
{

}

#int_TIMER2
TIMER2_isr()
{

}

void main()
{
   unsigned int16 i;
   char ch;
   char string[10];
   const char ver[]={"HACK v1.0\0"};
   unsigned int16 prescale;
   unsigned int16 ticks;
   int n;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
//   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//   enable_interrupts(INT_TIMER1);
//   enable_interrupts(INT_TIMER2);
//   enable_interrupts(GLOBAL);

   setup_oscillator(OSC_4MHZ|OSC_INTRC);     // 4 MHz interni RC oscilator

   delay_ms(100);
   printf("\n\r\n\r%s", ver);
   output_low(SYNC);
   output_low(HACK);
   ticks=1;
   prescale=0;

   while(true)
   {
      printf("\n\r>");
      n=0;
      do
      {
         ch=getchar();
         printf("%c",ch);
         string[n++]=ch;
      } while((13 != ch) && (n < 10));
      string[n]=0;
      printf("\n\r");
      switch(string[0])
      {
         case 'g':   // GO
               printf("%Lue4 + %Lu GO", prescale, ticks);
               for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
               set_timer1(0); while ( get_timer1() < ticks ) ;
               output_high(SYNC);
               delay_ms(1);
               output_low(SYNC);
               break;

         case 'r':   // REPEAT
               n=0;
               while(true)
               {
                  printf("%Lue4 + %Lu REPEAT %u\n\r", prescale, ticks, n++);
                  for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
                  set_timer1(0); while ( get_timer1() < ticks ) ;
                  output_high(SYNC);
                  delay_ms(20);
                  output_low(SYNC);
                  delay_ms(2000);
               };
               break;

         case 'h':   // HACK
               printf("%Lue4 + %Lu HACK", prescale, ticks);
               for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
               set_timer1(0); while ( get_timer1() < ticks ) ;
               output_high(SYNC);
               output_low(CLOCK);
               delay_ms(10);
               output_high(HACK);
               delay_ms(10000);
               output_low(HACK);
               output_low(SYNC);
               input(CLOCK);
               break;

         case 'i':   // Info
               printf("%s\n\r", ver);
               printf("%Lue4 + %Lu ticks", prescale, ticks);
               break;

         case 'p':
               if (isdigit(string[1]))
               {
                  prescale=atol(string+1);
                  printf("%Lu x 10000 prescale", prescale);
               }
               else
               printf("Error");
               break;

         default:    // fine ticks number
               if (isdigit(string[0]))
               {
                  ticks=atol(string);
                  printf("%Lu ticks", ticks);
               }
               else
               printf("Error");
      };

   };

   while(true)
   {
      output_low(PIN_B4);
      delay_ms(300);
      output_high(PIN_B4);
      delay_ms(300);
   }
}