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  
3023 kaklik 8 #define S1 PIN_B0 //Raw up
9 #define S2 PIN_B1 //Raw down
10 #define S3 PIN_D0 //Fine up
11 #define S4 PIN_D1 //Fine down
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  
3023 kaklik 24 #define OUTPUT_ENABLE PIN_C1
25  
2743 kaklik 26 void sound_beep( unsigned int lenght, int16 frequency)
2600 kaklik 27 {
2743 kaklik 28 unsigned int i;
29  
30 for(i=0;i<=lenght;i++)
31 {
32 output_toggle(BEEP);
33 delay_us(1/frequency);
34 }
2600 kaklik 35 }
36  
2596 kaklik 37 void main()
38 {
2744 kaklik 39 unsigned int16 setpoint=43;
2743 kaklik 40 unsigned int16 napeti;
2600 kaklik 41 unsigned int16 plneni=0;
2743 kaklik 42 unsigned int1 button_press; // semafor pro cteni tlacitek
2596 kaklik 43  
44 setup_adc_ports(sAN0|VSS_VDD);
45 setup_adc(ADC_CLOCK_DIV_32);
46 setup_spi(SPI_SS_DISABLED);
47 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
48 setup_timer_1(T1_DISABLED);
49 setup_timer_2(T2_DIV_BY_1,255,1);
50 setup_ccp1(CCP_PWM);
51 setup_ccp2(CCP_PWM);
52 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
53 setup_oscillator(OSC_8MHZ);
54  
55 set_pwm1_duty(0);
56 set_pwm2_duty(0);
57  
2600 kaklik 58 output_high(LED1);
59 output_high(LED2);
60 output_high(LED3);
61 output_high(LED4);
2744 kaklik 62 output_low(BEEP);
2600 kaklik 63  
2744 kaklik 64 lcd_init();
3021 kaklik 65  
66 lcd_gotoxy(1,1);
67 lcd_putc("HVPS01A");
68 lcd_gotoxy(1,2);
69 lcd_putc(" MLAB.cz");
2744 kaklik 70 Delay_ms(1000);
2596 kaklik 71  
2743 kaklik 72 lcd_putc("\f");
2596 kaklik 73  
74 while(true)
75 {
2743 kaklik 76  
2596 kaklik 77 set_adc_channel(1);
78 delay_us(100);
2743 kaklik 79 napeti = (napeti+read_adc())/2;
3023 kaklik 80 if(input(OUTPUT_ENABLE))
2596 kaklik 81 {
3023 kaklik 82 if (napeti <= setpoint)
83 {
84 if (plneni < 300) plneni++;
85 output_low(LED2);
86 }
87 else
88 {
89 if (plneni > 0) plneni--;
90 output_high(LED2);
91 }
92 set_pwm1_duty(plneni);
93 set_pwm2_duty(1023-plneni);
2596 kaklik 94 }
95 else
96 {
3023 kaklik 97 set_pwm1_duty(0);
98 set_pwm2_duty(1023);
2596 kaklik 99 }
2743 kaklik 100  
101 lcd_gotoxy(1,1);
3023 kaklik 102 printf(lcd_putc,"%4lu",napeti);
2743 kaklik 103 lcd_gotoxy(1,2);
2596 kaklik 104  
3023 kaklik 105 if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint);
106 else printf(lcd_putc,"DISABLED");
107  
2743 kaklik 108 if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta.
109 {
110 if(!input(S1))
111 {
112 delay_ms(20);
113 if(!input(S1))
114 {
115 button_press=true;
116 sound_beep(100,700);
3021 kaklik 117 if(setpoint < (1023-5) )setpoint+=5;
2743 kaklik 118 }
119 }
120  
121 if(!input(S2))
122 {
123 delay_ms(20);
124 if(!input(S2))
125 {
126 button_press=true;
127 sound_beep(100,600);
128 if(setpoint > 0x05 ) setpoint-=5;
129 }
130 }
131  
132 if(!input(S3))
133 {
134 delay_ms(20);
135 if(!input(S3))
136 {
137 button_press=true;
138 sound_beep(100,500);
3021 kaklik 139 if(setpoint < 1023 )setpoint++;
2743 kaklik 140 }
141 }
142  
143 if(!input(S4))
144 {
145 delay_ms(20);
146 if(!input(S4))
147 {
148 button_press=true;
149 sound_beep(100,400);
150 if(setpoint > 0x00 ) setpoint--;
151 }
152 }
153 }
154  
155 if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false;
156  
2600 kaklik 157 output_toggle(LED1);
158 delay_ms(10);
2596 kaklik 159 }
160  
161 }