1 | #include "16F877A.h"
|
2 | #device adc=10
|
3 | #use delay(clock=20000000)
|
4 | #include <init_display.c>
|
5 | #include <display.c>
|
6 | #include <adc.c>
|
7 | #include <button.c>
|
8 |
|
9 |
|
10 | #fuses HS,NOWDT,NOPROTECT,NOLVP
|
11 |
|
12 |
|
13 | #define RESET_BUTTON PIN_D0
|
14 | #define STATE 0
|
15 | #define STATE_1 5
|
16 | #define STATE_2 10
|
17 | #define STATE_3 15
|
18 |
|
19 | #byte T1CON = 0x10
|
20 | #byte PIR1 = 0x0C
|
21 | #byte PIE1 = 0x8C
|
22 | #byte TMR1H = 0x0F
|
23 | #byte TMR1L = 0x0E
|
24 | #byte TMR1H = 0x0F
|
25 | #byte ITCON = 0x0B
|
26 | //
|
27 | ////BIT
|
28 | #bit TMR1ON = T1CON.0
|
29 | #bit TMR1CS = T1CON.1
|
30 | #bit TMR1PS0 = T1CON.5
|
31 | #bit TMR1PS1 = T1CON.4
|
32 | #bit TMR1IF = PIR1.0
|
33 | #bit TMR1IE = PIE1.0
|
34 | #bit GIE = ITCON.7
|
35 | #bit PEIE = ITCON.6
|
36 | int8 z_hoch=0,z_runter=0, t=0, wandler=0;
|
37 |
|
38 | #int_ext
|
39 | void isr()
|
40 | {
|
41 |
|
42 | clear_interrupt(INT_EXT);
|
43 |
|
44 | wandler++;
|
45 |
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | #int_TIMER1
|
51 | void TIMER1_isr()
|
52 | {
|
53 | TMR1IF=0;
|
54 | TMR1L=0;
|
55 | TMR1H=0x80; //Timer vorladen(65536-32768)
|
56 |
|
57 | t++;
|
58 |
|
59 |
|
60 | }
|
61 |
|
62 | void main() {
|
63 | set_tris_b(0x01);
|
64 | input(PIN_A0);
|
65 | //Variable
|
66 | int32 ampere=0,bat_volt=0,g_wert=0;
|
67 | boolean change=0;
|
68 | //Timer1
|
69 | TMR1L=0;
|
70 | TMR1H=0x80; //Timer vorladen(65536-32768)
|
71 | TMR1IF=0; //clear Timer flag
|
72 | TMR1ON=1; //Enable Timer1
|
73 | TMR1CS=1; //Use external osc
|
74 | TMR1PS0=0; //Prescale 1:1
|
75 | TMR1PS1=0;
|
76 | TMR1IE=1; //Enable Interrupt Timer overflow
|
77 | GIE = 1; //Enable Global Interrupt
|
78 | PEIE= 1; //Enable all unsmasked peripheral interrupts
|
79 |
|
80 | //Initalisieren LCD und ADC
|
81 | lcd_init();
|
82 | setup_adc_ports(RA0_ANALOG);
|
83 | setup_adc(ADC_CLOCK_INTERNAL);
|
84 | set_adc_channel(0);
|
85 |
|
86 | //Init interrupt
|
87 | ext_int_edge (H_TO_L);
|
88 | clear_interrupt(INT_EXT);
|
89 | enable_interrupts(INT_EXT);
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | //Display
|
95 | while (TRUE) {
|
96 | //
|
97 | input(PIN_A0);
|
98 | input(PIN_E2);
|
99 | g_wert=grenz_abfrage();
|
100 | ampere=adc();
|
101 | // display(ampere);
|
102 | display_a(ampere);
|
103 | display_status(z_runter,z_hoch);
|
104 | delay_ms(200);
|
105 | bat_volt=adc1();
|
106 | display_b(bat_volt);
|
107 | if(ampere>g_wert) //Wenn Strom größer 3 A inventiere Strom ansonsten fahr weiter
|
108 | {
|
109 | change=!change;
|
110 | }
|
111 | if(change==0)
|
112 | {
|
113 | output_low(PIN_B3); //B1=T1,B2=T2,B3=T3,B4=T4
|
114 | output_low(PIN_B2);
|
115 | output_high(PIN_B1);
|
116 | output_high(PIN_B4);
|
117 |
|
118 | delay_ms(200);
|
119 | ampere=adc();
|
120 | if(ampere>g_wert)
|
121 | {
|
122 | output_low(PIN_B3); //B1=T1,B2=T2,B3=T3,B4=T4
|
123 | output_low(PIN_B2);
|
124 | output_low(PIN_B1);
|
125 | output_low(PIN_B4);
|
126 | }
|
127 | }
|
128 | else
|
129 | {
|
130 | output_low(PIN_B1);
|
131 | output_low(PIN_B4);
|
132 | output_high(PIN_B2);
|
133 | output_high(PIN_B3);
|
134 |
|
135 | delay_ms(200);
|
136 | ampere=adc();
|
137 | if(ampere>g_wert)
|
138 | {
|
139 | output_low(PIN_B3); //B1=T1,B2=T2,B3=T3,B4=T4
|
140 | output_low(PIN_B2);
|
141 | output_low(PIN_B1);
|
142 | output_low(PIN_B4);
|
143 | }
|
144 | }
|
145 |
|
146 |
|
147 | delay_ms(50);
|
148 | }
|
149 | }
|