Rev 2740 Rev 2743
Line 1... Line 1...
1 #include ".\main.h" 1 #include ".\main.h"
2 //#include <LCD.C> -  
3   2  
4 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 3 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
5 #define LED2 PIN_C5 //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
6 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 5 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
7 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 6 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
8   7  
-   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
-   12  
-   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>
9   23  
10 #int_EXT -  
11 void EXT_isr(void) 24 void sound_beep( unsigned int lenght, int16 frequency)
12 { 25 {
-   26 unsigned int i;
-   27
-   28 for(i=0;i<=lenght;i++)
-   29 {
13 output_toggle(LED3); 30 output_toggle(BEEP);
-   31 delay_us(1/frequency);
-   32 }
14 } 33 }
15   34  
16 //#define LCD_TYPE 1 -  
17 //#include <lcd.c> -  
18 void main() 35 void main()
19 { 36 {
20 unsigned int setpoint; 37 unsigned int16 setpoint;
21 unsigned int napeti; 38 unsigned int16 napeti;
22 unsigned int16 plneni=0; 39 unsigned int16 plneni=0;
-   40 unsigned int1 button_press; // semafor pro cteni tlacitek
23   41  
24 /* lcd_init(); 42 lcd_init();
25   43  
26 lcd_putc("\fReady...\n"); 44 lcd_putc("\fHVPS01A 2013 MLAB\n");
27   -  
28 while (TRUE) { -  
29 k=kbd_getc(); -  
30 if(k!=0) 45 Delay_ms(1000);
31 if(k=='*') -  
32 lcd_putc('\f'); -  
33 else -  
34 lcd_putc(k); -  
35 } -  
36 */ -  
37   46  
38 setup_adc_ports(sAN0|VSS_VDD); 47 setup_adc_ports(sAN0|VSS_VDD);
39 setup_adc(ADC_CLOCK_DIV_32); 48 setup_adc(ADC_CLOCK_DIV_32);
40 setup_spi(SPI_SS_DISABLED); 49 setup_spi(SPI_SS_DISABLED);
41 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); 50 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
Line 53... Line 62...
53 output_high(LED1); 62 output_high(LED1);
54 output_high(LED2); 63 output_high(LED2);
55 output_high(LED3); 64 output_high(LED3);
56 output_high(LED4); 65 output_high(LED4);
57   66  
58 ext_int_edge( L_TO_H ); // Sets up EXT 67 // ext_int_edge( L_TO_H ); // Sets up EXT
59 enable_interrupts(INT_EXT); 68 // enable_interrupts(INT_EXT);
60 enable_interrupts(GLOBAL); 69 // enable_interrupts(GLOBAL);
61   -  
62 // lcd_init(); -  
63 70
64 setpoint = 43; 71 setpoint = 43;
-   72 lcd_putc("\f");
65 73
66 while(true) 74 while(true)
67 { 75 {
-   76
68 set_adc_channel(1); 77 set_adc_channel(1);
69 delay_us(100); 78 delay_us(100);
70 napeti = read_adc(); 79 napeti = (napeti+read_adc())/2;
71   80  
72 if (napeti <= setpoint) 81 if (napeti <= setpoint)
73 { 82 {
74 if (plneni < 300) plneni++; 83 if (plneni < 300) plneni++;
75 output_low(LED2); 84 output_low(LED2);
Line 77... Line 86...
77 else 86 else
78 { 87 {
79 if (plneni > 0) plneni--; 88 if (plneni > 0) plneni--;
80 output_high(LED2); 89 output_high(LED2);
81 } 90 }
-   91 set_pwm1_duty(plneni);
-   92 set_pwm2_duty(1023-plneni);
-   93
-   94 lcd_gotoxy(1,1);
-   95 printf(lcd_putc,"Actual: %lu V ",napeti);
-   96 lcd_gotoxy(1,2);
-   97 printf(lcd_putc,"Set: %lu V ",setpoint);
-   98  
82   99  
-   100 if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta.
-   101 {
-   102 if(!input(S1))
-   103 {
-   104 delay_ms(20);
83 set_pwm1_duty(plneni); 105 if(!input(S1))
-   106 {
-   107 button_press=true;
-   108 sound_beep(100,700);
-   109 if(setpoint < 0xfa )setpoint+=5;
-   110 }
-   111 }
-   112  
-   113 if(!input(S2))
-   114 {
-   115 delay_ms(20);
-   116 if(!input(S2))
-   117 {
-   118 button_press=true;
-   119 sound_beep(100,600);
-   120 if(setpoint > 0x05 ) setpoint-=5;
-   121 }
-   122 }
-   123  
-   124 if(!input(S3))
-   125 {
-   126 delay_ms(20);
-   127 if(!input(S3))
-   128 {
-   129 button_press=true;
-   130 sound_beep(100,500);
-   131 if(setpoint < 0xff )setpoint++;
-   132 }
-   133 }
-   134  
-   135 if(!input(S4))
-   136 {
-   137 delay_ms(20);
-   138 if(!input(S4))
-   139 {
-   140 button_press=true;
84 set_pwm2_duty(1023-plneni); 141 sound_beep(100,400);
-   142 if(setpoint > 0x00 ) setpoint--;
-   143 }
-   144 }
-   145 }
-   146
-   147 if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false;
85   148  
86 output_toggle(LED1); 149 output_toggle(LED1);
87 delay_ms(10); 150 delay_ms(10);
88 } 151 }
89   152