Subversion Repositories svnkaklik

Rev

Rev 6 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 6 Rev 328
Line 1... Line 1...
1
#include "D:\KAKLIK\programy\PIC_C\mereni\gmetr\gmetr.h"
1
#include ".\gmetr.h"
2
 
2
 
3
#define LCD_RS          PIN_B1      // rizeni registru LCD displeje
3
#define LCD_RS          PIN_B1      // rizeni registru LCD displeje
4
#define LCD_E           PIN_B0      // enable LCD displeje
4
#define LCD_E           PIN_B0      // enable LCD displeje
5
#define LCD_DATA_LSB    PIN_C4      // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
5
#define LCD_DATA_LSB    PIN_C4      // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
6
 
6
 
7
#include "C:\library\CCS\lcd.c"
7
#include "C:\library\CCS\lcd.c"
8
 
8
 
9
 
9
 
10
void main()
10
void main()
11
{
11
{
12
   signed int16 stred;
12
signed int16 stred;
13
   signed int16 hodnota;
13
signed int8 hodnota;
-
 
14
unsigned int8 i, offset;
14
   
15
 
15
   setup_adc_ports(ALL_ANALOG);
16
   setup_adc_ports(ALL_ANALOG);
16
   setup_adc(ADC_CLOCK_DIV_2);
17
   setup_adc(ADC_CLOCK_DIV_2);
17
   setup_spi(FALSE);
18
   setup_spi(FALSE);
18
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
19
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
19
   setup_timer_1(T1_DISABLED);
20
   setup_timer_1(T1_DISABLED);
20
   setup_timer_2(T2_DISABLED,0,1);
21
   setup_timer_2(T2_DISABLED,0,1);
21
 
22
 
22
   lcd_init();
23
   lcd_init();
23
   Delay_ms(100);
24
   Delay_ms(100);
24
   set_adc_channel(1);
25
   set_adc_channel(1);
-
 
26
 
-
 
27
   LCD_gotoxy(1,1);
-
 
28
   printf(lcd_putc,"Gmetr 0.1.2 Beta");
-
 
29
   LCD_gotoxy(1,2);
-
 
30
   printf(lcd_putc,"Kaklik@mlab.cz");
25
   Delay_ms(500);
31
   Delay_ms(500);
-
 
32
 
-
 
33
   LCD_clr();
-
 
34
   LCD_gotoxy(1,1);
-
 
35
   printf(lcd_putc,"Clibration...");
-
 
36
 
-
 
37
   stred = 0; 
-
 
38
   for(i=0;i<=127;i++)
-
 
39
   {
-
 
40
     Delay_ms(10);
26
   stred = read_adc();
41
     stred = stred + read_adc();
27
   
42
   }
-
 
43
   stred = stred >> 7;
-
 
44
 
28
   while(true)
45
   while(true)
29
   {
46
   {
30
      hodnota = stred - read_adc();
47
      hodnota = read_adc();
31
      Delay_ms(100);
48
      Delay_ms(50);
-
 
49
      LCD_clr();
32
      LCD_gotoxy(1,1);
50
      LCD_gotoxy(6,1);
33
      printf(lcd_putc,"                ");
51
      printf(lcd_putc," %03ld ",(stred - hodnota));
34
      if (hodnota<0)
52
      if (hodnota > stred)
35
      {
53
      {
36
         LCD_gotoxy(5,2);
-
 
37
         printf(lcd_putc," %03ld  ",hodnota);
-
 
38
         LCD_gotoxy(8-hodnota,1);
54
        offset = hodnota - stred;
39
         printf(lcd_putc,"* ",hodnota);
55
        offset = (offset >> 5) + 8;
40
      }
56
      }
41
      else
57
      else
42
      {
58
      {
43
         LCD_gotoxy(6,2);
-
 
44
         printf(lcd_putc," %03ld  ",hodnota);
59
        offset = stred - hodnota;
45
         LCD_gotoxy(8-hodnota,1);
60
        offset = offset >> 5;
46
         printf(lcd_putc," *",hodnota);
-
 
47
      }
61
      }
-
 
62
      LCD_gotoxy(offset,2);
-
 
63
      printf(lcd_putc,"*");
48
   }
64
   }
49
}
65
}