| 470 |
kaklik |
1 |
#include "main.h"
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
#define LED_K1 PIN_A2 // anody segmentovek
|
|
|
5 |
#define LED_K2 PIN_A1
|
|
|
6 |
//#define LED_D1 PIN_A1 // katody segmentovek ///ted uz nepotreba
|
|
|
7 |
//#define LED_D2 PIN_A2
|
|
|
8 |
//#define LED_D3 PIN_A3
|
|
|
9 |
//#define LED_D4 PIN_A4
|
|
|
10 |
//#define LED_D5 PIN_A5
|
|
|
11 |
//#define LED_D6 PIN_A6
|
|
|
12 |
//#define LED_D7 PIN_A7
|
|
|
13 |
|
|
|
14 |
#include "1wire.c"
|
|
|
15 |
#include "ds1820.c"
|
|
|
16 |
|
|
|
17 |
void main()
|
|
|
18 |
{
|
|
|
19 |
float temperature; // teplota z ds1820.c
|
|
|
20 |
long duty; // strida PWM
|
|
|
21 |
int temp; // zaokrouhlena teplota
|
|
|
22 |
int znak1; // hodnota jednotek
|
|
|
23 |
int znak2; // hodnota desitek
|
|
|
24 |
int znak; // zobrazovany znak
|
|
|
25 |
int i; // i pro for
|
|
|
26 |
|
|
|
27 |
setup_adc_ports(NO_ANALOGS|VSS_VDD);
|
|
|
28 |
setup_adc(ADC_OFF);
|
|
|
29 |
setup_spi(FALSE);
|
|
|
30 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
|
|
|
31 |
setup_timer_1(T1_DISABLED);
|
|
|
32 |
setup_timer_2(T2_DISABLED,0,1);
|
|
|
33 |
setup_comparator(NC_NC_NC_NC);
|
|
|
34 |
setup_vref(FALSE);
|
|
|
35 |
port_b_pullups(TRUE);
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
while(TRUE)
|
|
|
39 |
{
|
|
|
40 |
temperature = ds1820_read();
|
|
|
41 |
temp = (int) temperature;
|
|
|
42 |
|
|
|
43 |
if (temp<10) { //pro teploty 0-10°C
|
|
|
44 |
znak1=temp;
|
|
|
45 |
znak2=0;
|
|
|
46 |
}
|
|
|
47 |
else {
|
|
|
48 |
znak2=(int) (temp/10); //vydelit deseti a zaokrouhlit dolu = desitky
|
|
|
49 |
znak1=temp-((int) (temp/10))*10; //jednotky rozdil teploty a desitek
|
|
|
50 |
}
|
|
|
51 |
for (i=1;i<=2;i++) { //cyklus zobrazeni udaje
|
|
|
52 |
output_low(0x7f); //vymaz display
|
|
|
53 |
if (i==1) {
|
|
|
54 |
output_high(LED_K1); //dva bloky pro sepnuti aktivniho segmentu na 1
|
|
|
55 |
output_low(LED_K2);
|
|
|
56 |
znak=znak1;
|
|
|
57 |
}
|
|
|
58 |
if (i==2) {
|
|
|
59 |
output_high(LED_K2);
|
|
|
60 |
output_low(LED_K1);
|
|
|
61 |
znak=znak2;
|
|
|
62 |
}
|
|
|
63 |
if (znak==1) output_b(0x4f); //blok if pro rozeznani zobrazeneho znaku
|
|
|
64 |
if (znak==2) output_b(0x12);
|
|
|
65 |
if (znak==3) output_b(0x06);
|
|
|
66 |
if (znak==4) output_b(0x4c);
|
|
|
67 |
if (znak==5) output_b(0x2c);
|
|
|
68 |
if (znak==6) output_b(0x20);
|
|
|
69 |
if (znak==7) output_b(0x0f);
|
|
|
70 |
if (znak==8) output_b(0x00);
|
|
|
71 |
if (znak==9) output_b(0x04);
|
|
|
72 |
if (znak==0) output_b(0x01);
|
|
|
73 |
Delay_ms(50);
|
|
|
74 |
}
|
|
|
75 |
// duty=104+(2,31*temperature); // .000416/(16*(1/4000000)) ....PWM presne podle helpu
|
|
|
76 |
// set_pwm1_duty(duty);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
}
|