Subversion Repositories svnkaklik

Rev

Rev 149 | 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
 
36
   i2c_start();      // Reset
37
   i2c_write(0xC0);
38
   i2c_write(0x12);
39
   i2c_write(0x80 | 0x24);
40
   i2c_stop();
41
 
42
   i2c_start();      // BW
43
   i2c_write(0xC0);
44
   i2c_write(0x28);
45
   i2c_write(0b01000001);
46
   i2c_stop();
47
 
48
   i2c_start();      // Contrast
49
   i2c_write(0xC0);
50
   i2c_write(0x05);
51
   i2c_write(0xFF);
52
   i2c_stop();
53
 
54
   i2c_start();      // Brightness
55
   i2c_write(0xC0);
56
   i2c_write(0x06);
57
   i2c_write(0x80);
58
   i2c_stop();
59
 
60
/*
61
   i2c_start();      // Band Filter
62
   i2c_write(0xC0);
63
   i2c_write(0x2D);
64
   i2c_write(0x04 | 0x03);
65
   i2c_stop();
66
 
67
   i2c_start();      // 4-bit, (CLK/4)
68
   i2c_write(0xC0);
69
   i2c_write(0x3E);
70
   i2c_write(0x10 | 0x80);
71
   i2c_stop();
72
*/
73
   i2c_start();      // VSTRT
74
   i2c_write(0xC0);
75
   i2c_write(0x19);
76
   i2c_write(45);
77
   i2c_stop();
78
 
79
   i2c_start();      // VEND
80
   i2c_write(0xC0);
81
   i2c_write(0x1A);
82
   i2c_write(45);
83
   i2c_stop();
84
 
85
   output_low(LED);
150 kakl 86
 
87
   cas=128;
136 kakl 88
 
89
   while(true)
90
   {
91
      while(!input(HREF));
92
      set_timer0(0);
149 kakl 93
      while(input(HREF))
94
      {
95
        if(!input(PIX))
96
        {
97
          cas=get_timer0();
98
          break;
99
        }
100
      };
150 kakl 101
 
102
      cas=255-cas;
103
 
104
      set_adc_channel(MODRA);
105
      Delay_ms(1);
106
      offset=read_adc();
149 kakl 107
      output_high(SERVO);
150 kakl 108
      delay_us(900);
109
      delay_us(offset);
149 kakl 110
      delay_us(cas);
111
      delay_us(cas);
112
      delay_us(cas);
150 kakl 113
      output_LOW(SERVO);
149 kakl 114
      set_pwm1_duty(cas);
115
      set_pwm2_duty(255-cas);
136 kakl 116
   };
117
}