Subversion Repositories svnkaklik

Rev

Rev 150 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
141 kakl 1
#include ".\camerus.h"
136 kakl 2
 
149 kakl 3
#USE FAST_IO (C)
136 kakl 4
 
150 kakl 5
// kroutitka
6
#define  CERVENA  1  // AN1
7
#define  CERNA    4  // AN4
8
#define  ZELENA   3  // AN3
9
#define  MODRA    0  // AN0
10
 
11
// I/O
149 kakl 12
#define LED    PIN_C0
13
#define HREF   PIN_C5
14
#define PIX    PIN_C6
15
#define SERVO  PIN_B7
136 kakl 16
 
17
void main()
18
{
19
   int8 cas;
150 kakl 20
   int16 offset;
136 kakl 21
 
22
   setup_adc_ports(ALL_ANALOG);
23
   setup_adc(ADC_CLOCK_INTERNAL);
24
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
25
   setup_timer_1(T1_DISABLED);
149 kakl 26
   setup_timer_2(T2_DIV_BY_16,255,1);
136 kakl 27
   setup_ccp1(CCP_PWM); // RC1
28
   setup_ccp2(CCP_PWM); // RC2
29
   setup_comparator(NC_NC_NC_NC);
30
   setup_vref(FALSE);
31
 
149 kakl 32
   set_tris_c(0b11111000);
141 kakl 33
 
136 kakl 34
   output_high(LED);
35
 
152 kakl 36
   delay_ms(200);
37
 
136 kakl 38
   i2c_start();      // Reset
39
   i2c_write(0xC0);
40
   i2c_write(0x12);
41
   i2c_write(0x80 | 0x24);
42
   i2c_stop();
43
 
44
   i2c_start();      // BW
45
   i2c_write(0xC0);
46
   i2c_write(0x28);
47
   i2c_write(0b01000001);
48
   i2c_stop();
49
 
152 kakl 50
 
136 kakl 51
   i2c_start();      // Contrast
52
   i2c_write(0xC0);
53
   i2c_write(0x05);
152 kakl 54
   i2c_write(0xA0);
136 kakl 55
   i2c_stop();
152 kakl 56
/*
136 kakl 57
 
58
   i2c_start();      // Brightness
59
   i2c_write(0xC0);
60
   i2c_write(0x06);
61
   i2c_write(0x80);
62
   i2c_stop();
63
 
64
   i2c_start();      // Band Filter
65
   i2c_write(0xC0);
66
   i2c_write(0x2D);
67
   i2c_write(0x04 | 0x03);
68
   i2c_stop();
69
 
70
   i2c_start();      // 4-bit, (CLK/4)
71
   i2c_write(0xC0);
72
   i2c_write(0x3E);
73
   i2c_write(0x10 | 0x80);
74
   i2c_stop();
75
*/
76
   i2c_start();      // VSTRT
77
   i2c_write(0xC0);
78
   i2c_write(0x19);
79
   i2c_write(45);
80
   i2c_stop();
81
 
82
   i2c_start();      // VEND
83
   i2c_write(0xC0);
84
   i2c_write(0x1A);
85
   i2c_write(45);
86
   i2c_stop();
87
 
88
   output_low(LED);
152 kakl 89
   delay_ms(100);
90
 
91
/*
92
   i2c_start();      // BW + freeze AGC/AEC
93
   i2c_write(0xC0);
94
   i2c_write(0x28);
95
   i2c_write(0b01010001);
96
   i2c_stop();
97
*/
98
   output_high(LED);
99
   delay_ms(100);
100
   output_low(LED);
101
 
150 kakl 102
   cas=128;
136 kakl 103
 
104
   while(true)
105
   {
106
      while(!input(HREF));
152 kakl 107
//      delay_cycles(4);
136 kakl 108
      set_timer0(0);
149 kakl 109
      while(input(HREF))
110
      {
152 kakl 111
         if(!input(PIX))
112
         if(!input(PIX))
113
         {
114
            cas=get_timer0();
115
            cas=255-cas;
116
            break;
117
         };
149 kakl 118
      };
150 kakl 119
 
120
      set_adc_channel(MODRA);
121
      Delay_ms(1);
122
      offset=read_adc();
149 kakl 123
      output_high(SERVO);
152 kakl 124
      delay_us(1000);
150 kakl 125
      delay_us(offset);
152 kakl 126
      delay_us(offset);
149 kakl 127
      delay_us(cas);
128
      delay_us(cas);
152 kakl 129
//      delay_us(cas);
130
      output_low(SERVO);
149 kakl 131
      set_pwm1_duty(cas);
132
      set_pwm2_duty(255-cas);
136 kakl 133
   };
134
}