Subversion Repositories svnkaklik

Rev

Rev 148 | 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
 
149 kakl 5
#define LED    PIN_C0
6
#define HREF   PIN_C5
7
#define PIX    PIN_C6
8
#define SERVO  PIN_B7
136 kakl 9
 
10
void main()
11
{
12
   int8 cas;
13
 
14
   setup_adc_ports(ALL_ANALOG);
15
   setup_adc(ADC_CLOCK_INTERNAL);
16
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
17
   setup_timer_1(T1_DISABLED);
149 kakl 18
   setup_timer_2(T2_DIV_BY_16,255,1);
136 kakl 19
   setup_ccp1(CCP_PWM); // RC1
20
   setup_ccp2(CCP_PWM); // RC2
21
   setup_comparator(NC_NC_NC_NC);
22
   setup_vref(FALSE);
23
 
149 kakl 24
   set_tris_c(0b11111000);
141 kakl 25
 
136 kakl 26
   output_high(LED);
27
 
28
   i2c_start();      // Reset
29
   i2c_write(0xC0);
30
   i2c_write(0x12);
31
   i2c_write(0x80 | 0x24);
32
   i2c_stop();
33
 
34
   i2c_start();      // BW
35
   i2c_write(0xC0);
36
   i2c_write(0x28);
37
   i2c_write(0b01000001);
38
   i2c_stop();
39
 
40
   i2c_start();      // Contrast
41
   i2c_write(0xC0);
42
   i2c_write(0x05);
43
   i2c_write(0xFF);
44
   i2c_stop();
45
 
46
   i2c_start();      // Brightness
47
   i2c_write(0xC0);
48
   i2c_write(0x06);
49
   i2c_write(0x80);
50
   i2c_stop();
51
 
52
/*
53
   i2c_start();      // Band Filter
54
   i2c_write(0xC0);
55
   i2c_write(0x2D);
56
   i2c_write(0x04 | 0x03);
57
   i2c_stop();
58
 
59
   i2c_start();      // 4-bit, (CLK/4)
60
   i2c_write(0xC0);
61
   i2c_write(0x3E);
62
   i2c_write(0x10 | 0x80);
63
   i2c_stop();
64
*/
65
   i2c_start();      // VSTRT
66
   i2c_write(0xC0);
67
   i2c_write(0x19);
68
   i2c_write(45);
69
   i2c_stop();
70
 
71
   i2c_start();      // VEND
72
   i2c_write(0xC0);
73
   i2c_write(0x1A);
74
   i2c_write(45);
75
   i2c_stop();
76
 
77
   output_low(LED);
78
 
79
   while(true)
80
   {
81
      while(!input(HREF));
82
      set_timer0(0);
149 kakl 83
      while(input(HREF))
84
      {
85
        if(!input(PIX))
86
        {
87
          cas=get_timer0();
88
          break;
89
        }
90
      };
91
      output_high(SERVO);
92
      delay_us(1000);
93
      delay_us(cas);
94
      delay_us(cas);
95
      delay_us(cas);
96
      output_LOW(SERVO);     
97
      set_pwm1_duty(cas);
98
      set_pwm2_duty(255-cas);
136 kakl 99
   };
100
}