Rev Author Line No. Line
2596 kaklik 1 #include ".\main.h"
2  
2600 kaklik 3 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
4 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
2743 kaklik 5 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
6 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
2596 kaklik 7  
2743 kaklik 8 #define S1 PIN_B0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
9 #define S2 PIN_B1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
10 #define S3 PIN_D0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
11 #define S4 PIN_D1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
2596 kaklik 12  
2743 kaklik 13 #define BEEP PIN_D2 //piezo beeper
14  
15 #define LCD_ENABLE_PIN PIN_E0 ////
16 #define LCD_RS_PIN PIN_E1 ////
17 #define LCD_RW_PIN PIN_E2 ////
18 #define LCD_DATA4 PIN_D4 ////
19 #define LCD_DATA5 PIN_D5 ////
20 #define LCD_DATA6 PIN_D6 ////
21 #define LCD_DATA7 PIN_D7
22 #include <lcd.c>
23  
24 void sound_beep( unsigned int lenght, int16 frequency)
2600 kaklik 25 {
2743 kaklik 26 unsigned int i;
27  
28 for(i=0;i<=lenght;i++)
29 {
30 output_toggle(BEEP);
31 delay_us(1/frequency);
32 }
2600 kaklik 33 }
34  
2596 kaklik 35 void main()
36 {
2744 kaklik 37 unsigned int16 setpoint=43;
2743 kaklik 38 unsigned int16 napeti;
2600 kaklik 39 unsigned int16 plneni=0;
2743 kaklik 40 unsigned int1 button_press; // semafor pro cteni tlacitek
2596 kaklik 41  
42 setup_adc_ports(sAN0|VSS_VDD);
43 setup_adc(ADC_CLOCK_DIV_32);
44 setup_spi(SPI_SS_DISABLED);
45 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
46 setup_timer_1(T1_DISABLED);
47 setup_timer_2(T2_DIV_BY_1,255,1);
48 setup_ccp1(CCP_PWM);
49 setup_ccp2(CCP_PWM);
50 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
51 setup_oscillator(OSC_8MHZ);
52  
53 set_pwm1_duty(0);
54 set_pwm2_duty(0);
55  
2600 kaklik 56 output_high(LED1);
57 output_high(LED2);
58 output_high(LED3);
59 output_high(LED4);
2744 kaklik 60 output_low(BEEP);
2600 kaklik 61  
2744 kaklik 62 lcd_init();
3021 kaklik 63  
64 lcd_gotoxy(1,1);
65 lcd_putc("HVPS01A");
66 lcd_gotoxy(1,2);
67 lcd_putc(" MLAB.cz");
2744 kaklik 68 Delay_ms(1000);
2596 kaklik 69  
2743 kaklik 70 lcd_putc("\f");
2596 kaklik 71  
72 while(true)
73 {
2743 kaklik 74  
2596 kaklik 75 set_adc_channel(1);
76 delay_us(100);
2743 kaklik 77 napeti = (napeti+read_adc())/2;
2596 kaklik 78  
79 if (napeti <= setpoint)
80 {
2600 kaklik 81 if (plneni < 300) plneni++;
82 output_low(LED2);
2596 kaklik 83 }
84 else
85 {
86 if (plneni > 0) plneni--;
2600 kaklik 87 output_high(LED2);
2596 kaklik 88 }
2743 kaklik 89 set_pwm1_duty(plneni);
90 set_pwm2_duty(1023-plneni);
91  
92 lcd_gotoxy(1,1);
3021 kaklik 93 printf(lcd_putc,"%lu",napeti);
2743 kaklik 94 lcd_gotoxy(1,2);
3021 kaklik 95 printf(lcd_putc,"Set:%lu"setpoint);
2596 kaklik 96  
2743 kaklik 97 if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta.
98 {
99 if(!input(S1))
100 {
101 delay_ms(20);
102 if(!input(S1))
103 {
104 button_press=true;
105 sound_beep(100,700);
3021 kaklik 106 if(setpoint < (1023-5) )setpoint+=5;
2743 kaklik 107 }
108 }
109  
110 if(!input(S2))
111 {
112 delay_ms(20);
113 if(!input(S2))
114 {
115 button_press=true;
116 sound_beep(100,600);
117 if(setpoint > 0x05 ) setpoint-=5;
118 }
119 }
120  
121 if(!input(S3))
122 {
123 delay_ms(20);
124 if(!input(S3))
125 {
126 button_press=true;
127 sound_beep(100,500);
3021 kaklik 128 if(setpoint < 1023 )setpoint++;
2743 kaklik 129 }
130 }
131  
132 if(!input(S4))
133 {
134 delay_ms(20);
135 if(!input(S4))
136 {
137 button_press=true;
138 sound_beep(100,400);
139 if(setpoint > 0x00 ) setpoint--;
140 }
141 }
142 }
143  
144 if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false;
145  
2600 kaklik 146 output_toggle(LED1);
147 delay_ms(10);
2596 kaklik 148 }
149  
150 }