Subversion Repositories svnkaklik

Rev

Rev 410 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
#include ".\hack.h"
2
#include <stdlib.h>
3
 
4
#define SYNC   PIN_B4      // Spousteni oscyloskopu
5
#define HACK   PIN_B5      // Zkratovani napajeni SmartCard
6
#define CLOCK  PIN_B6      // Hodiny ze SmartCard
7
 
8
#int_TIMER1
9
TIMER1_isr()
10
{
11
 
12
}
13
 
14
#int_TIMER2
15
TIMER2_isr()
16
{
17
 
18
}
19
 
20
void main()
21
{
22
   unsigned int16 i;
23
   char ch;
24
   char string[10];
25
   const char ver[]={"HACK v1.0\0"};
26
   unsigned int16 prescale;
27
   unsigned int16 ticks;
28
   int n;
29
 
30
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
31
   setup_adc(ADC_OFF);
32
   setup_spi(FALSE);
33
   setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
34
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
35
//   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
36
   setup_timer_2(T2_DISABLED,0,1);
37
   setup_comparator(NC_NC_NC_NC);
38
   setup_vref(FALSE);
39
//   enable_interrupts(INT_TIMER1);
40
//   enable_interrupts(INT_TIMER2);
41
//   enable_interrupts(GLOBAL);
42
 
43
   setup_oscillator(OSC_4MHZ|OSC_INTRC);     // 4 MHz interni RC oscilator
44
 
45
   delay_ms(100);
46
   printf("\n\r\n\r%s", ver);
47
   output_low(SYNC);
48
   output_low(HACK);
49
   ticks=1;
50
   prescale=0;
51
 
52
   while(true)
53
   {
54
      printf("\n\r>");
55
      n=0;
56
      do
57
      {
58
         ch=getchar();
59
         printf("%c",ch);
60
         string[n++]=ch;
61
      } while((13 != ch) && (n < 10));
62
      string[n]=0;
63
      printf("\n\r");
64
      switch(string[0])
65
      {
66
         case 'g':   // GO
67
               printf("%Lue4 + %Lu GO", prescale, ticks);
68
               for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
69
               set_timer1(0); while ( get_timer1() < ticks ) ;
70
               output_high(SYNC);
71
               delay_ms(1);
72
               output_low(SYNC);
73
               break;
74
 
75
         case 'r':   // REPEAT
76
               n=0;
77
               while(true)
78
               {
79
                  printf("%Lue4 + %Lu REPEAT %u\n\r", prescale, ticks, n++);
80
                  for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
81
                  set_timer1(0); while ( get_timer1() < ticks ) ;
82
                  output_high(SYNC);
83
                  delay_ms(20);
84
                  output_low(SYNC);
85
                  delay_ms(2000);
86
               };
87
               break;
88
 
89
         case 'h':   // HACK
90
               printf("%Lue4 + %Lu HACK", prescale, ticks);
91
               for(i=0; i<prescale; i++) { set_timer1(0); while ( get_timer1() < 10000 ) ; };
92
               set_timer1(0); while ( get_timer1() < ticks ) ;
93
               output_high(SYNC);
94
               output_low(CLOCK);
95
               delay_ms(10);
96
               output_high(HACK);
97
               delay_ms(10000);
98
               output_low(HACK);
99
               output_low(SYNC);
100
               input(CLOCK);
101
               break;
102
 
103
         case 'i':   // Info
104
               printf("%s\n\r", ver);
105
               printf("%Lue4 + %Lu ticks", prescale, ticks);
106
               break;
107
 
108
         case 'p':
109
               if (isdigit(string[1]))
110
               {
111
                  prescale=atol(string+1);
112
                  printf("%Lu x 10000 prescale", prescale);
113
               }
114
               else
115
               printf("Error");
116
               break;
117
 
118
         default:    // fine ticks number
119
               if (isdigit(string[0]))
120
               {
121
                  ticks=atol(string);
122
                  printf("%Lu ticks", ticks);
123
               }
124
               else
125
               printf("Error");
126
      };
127
 
128
   };
129
 
130
   while(true)
131
   {
132
      output_low(PIN_B4);
133
      delay_ms(300);
134
      output_high(PIN_B4);
135
      delay_ms(300);
136
   }
137
}