Subversion Repositories svnkaklik

Rev

Rev 410 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 410 Rev 659
1
#include ".\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 int8 hodnota;
13
signed int8 hodnota;
14
unsigned int8 i, offset;
14
unsigned int8 i, offset;
15
 
15
 
16
   setup_adc_ports(ALL_ANALOG);
16
   setup_adc_ports(ALL_ANALOG);
17
   setup_adc(ADC_CLOCK_DIV_2);
17
   setup_adc(ADC_CLOCK_DIV_2);
18
   setup_spi(FALSE);
18
   setup_spi(FALSE);
19
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
19
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
20
   setup_timer_1(T1_DISABLED);
20
   setup_timer_1(T1_DISABLED);
21
   setup_timer_2(T2_DISABLED,0,1);
21
   setup_timer_2(T2_DISABLED,0,1);
22
 
22
 
23
   lcd_init();
23
   lcd_init();
24
   Delay_ms(100);
24
   Delay_ms(100);
25
   set_adc_channel(1);
25
   set_adc_channel(1);
26
 
26
 
27
   LCD_gotoxy(1,1);
27
   LCD_gotoxy(1,1);
28
   printf(lcd_putc,"Gmetr 0.1.2 Beta");
28
   printf(lcd_putc,"Gmetr 0.1.2 Beta");
29
   LCD_gotoxy(1,2);
29
   LCD_gotoxy(1,2);
30
   printf(lcd_putc,"Kaklik@mlab.cz");
30
   printf(lcd_putc,"Kaklik@mlab.cz");
31
   Delay_ms(500);
31
   Delay_ms(500);
32
 
32
 
33
   LCD_clr();
33
   LCD_clr();
34
   LCD_gotoxy(1,1);
34
   LCD_gotoxy(1,1);
35
   printf(lcd_putc,"Clibration...");
35
   printf(lcd_putc,"Clibration...");
36
 
36
 
37
   stred = 0; 
37
   stred = 0; 
38
   for(i=0;i<=127;i++)
38
   for(i=0;i<=127;i++)
39
   {
39
   {
40
     Delay_ms(10);
40
     Delay_ms(10);
41
     stred = stred + read_adc();
41
     stred = stred + read_adc();
42
   }
42
   }
43
   stred = stred >> 7;
43
   stred = stred >> 7;
44
 
44
 
45
   while(true)
45
   while(true)
46
   {
46
   {
47
      hodnota = read_adc();
47
      hodnota = read_adc();
48
      Delay_ms(50);
48
      Delay_ms(50);
49
      LCD_clr();
49
      LCD_clr();
50
      LCD_gotoxy(6,1);
50
      LCD_gotoxy(6,1);
51
      printf(lcd_putc," %03ld ",(stred - hodnota));
51
      printf(lcd_putc," %03ld ",(stred - hodnota));
52
      if (hodnota >= stred)
52
      if (hodnota >= stred)
53
      {
53
      {
54
        offset = hodnota - stred;
54
        offset = hodnota - stred;
55
        offset = (offset >> 5) + 8;
55
        offset = (offset >> 5) + 8;
56
      }
56
      }
57
      else
57
      else
58
      {
58
      {
59
        offset = stred - hodnota;
59
        offset = stred - hodnota;
60
        offset = offset >> 5;
60
        offset = offset >> 5;
61
      }
61
      }
62
      LCD_gotoxy(offset,2);
62
      LCD_gotoxy(offset,2);
63
      printf(lcd_putc,"*");
63
      printf(lcd_putc,"*");
64
   }
64
   }
65
}
65
}