/programy/C/PIC/mereni/teplomer/1wire.c |
---|
0,0 → 1,43 |
#define ONE_WIRE_PIN PIN_A3 // pro pristup k cidlu jsem zvolil |
void onewire_reset() |
{ |
output_low(ONE_WIRE_PIN); |
delay_us(240); |
output_float(ONE_WIRE_PIN); |
delay_us(150); |
output_float(ONE_WIRE_PIN); |
} |
void onewire_write(int data) |
{ |
int count; |
for (count=0; count<8; ++count) |
{ |
output_low(ONE_WIRE_PIN); |
delay_us( 2 ); |
output_bit(ONE_WIRE_PIN, shift_right(&data,1,1)); |
delay_us( 40 ); |
output_float(ONE_WIRE_PIN); |
delay_us( 2 ); |
} |
} |
int onewire_read() |
{ |
int count, data; |
for (count=0; count<8; ++count) |
{ |
output_low(ONE_WIRE_PIN); |
delay_us( 2 ); |
output_float(ONE_WIRE_PIN); |
delay_us( 8 ); |
shift_right(&data,1,input(ONE_WIRE_PIN)); |
delay_us(5); |
} |
return( data ); |
} |
/programy/C/PIC/mereni/teplomer/main.c |
---|
0,0 → 1,84 |
#include "main.h" |
#define LED_K1 PIN_A2 // anody segmentovek |
#define LED_K2 PIN_A1 |
#include "1wire.c" |
void main() |
{ |
//long duty; // strida PWM |
int znak1; // hodnota jednotek |
int znak2; // hodnota desitek |
int znak; // zobrazovany znak |
int i, n, temp; // i pro for |
int8 temp1, temp2; |
signed int16 temp3; |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_OFF); |
setup_spi(FALSE); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
while(TRUE) |
{ |
temp3 = make16(temp2, temp1); |
temp=(int) (temp3/16); |
znak2=(int) (temp/10); //vydelit deseti a zaokrouhlit dolu = desitky |
znak1=temp-znak2*10; //jednotky rozdil teploty a desitek |
for (n=0;n<=2;n++) |
{ |
for (i=0;i<=2;i++) { //cyklus zobrazeni udaje |
if (i==1) { |
output_low(LED_K2); //dva bloky pro sepnuti aktivniho segmentu na 1 |
if (n==0){ |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0x44); |
} |
output_high(LED_K1); |
znak=znak1; |
} |
if (i==2) { |
output_low(LED_K1); |
if (n==0){ |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0xBE); |
temp1 = onewire_read(); |
temp2 = onewire_read(); |
} |
output_high(LED_K2); |
znak=znak2; |
} |
if (temp>=85) |
{ |
output_high(LED_K1); |
output_high(LED_K2); |
output_b(0b00001101); |
} |
else |
{ |
if (znak==1) output_b(0b11110010); //blok if pro rozeznani zobrazeneho znaku |
if (znak==2) output_b(0b01001000); |
if (znak==3) output_b(0b01100000); |
if (znak==4) output_b(0b00110010); |
if (znak==5) output_b(0b00100100); |
if (znak==6) output_b(0b00000100); |
if (znak==7) output_b(0b11110000); |
if (znak==8) output_b(0b00000000); |
if (znak==9) output_b(0b00100000); |
if (znak==0) output_b(0b10000000); |
} |
Delay_ms(6); |
} |
} |
// duty=104+(2,31*temp); // .000416/(16*(1/4000000)) ....PWM presne podle helpu |
// set_pwm1_duty(duty); |
} |
} |
/programy/C/PIC/mereni/teplomer/main.h |
---|
0,0 → 1,6 |
#include <16F88.h> |
#device adc=8 |
#fuses NOWDT,INTRC_IO, NOPUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO |
#use delay(clock=4000000) |
/programy/C/PIC/mereni/teplomer/main.hex |
---|
0,0 → 1,76 |
:1000000000308A006D290000831685118312851146 |
:10001000A630F700F70B0A28000083168515A630D6 |
:10002000F700F70B11280000851583120034B30187 |
:100030003308073C031C372883168511831285116A |
:10004000000000000314B20C031828288511292889 |
:100050008515831685111330F700F70B2D28000046 |
:1000600000008515000000008312B30A1828003430 |
:10007000B2013208073C031C5A28831685118312EB |
:10008000851100000000831685150230F700F70B7C |
:100090004728000085158312851950280310512820 |
:1000A0000314B30C2730F700F70B542800000000AE |
:1000B000B20A39283308F80000343308350680398D |
:1000C000B700B31F6828B209B309B20A0319B30A0B |
:1000D000B51F6F28B409B509B40A0319B50AF801A8 |
:1000E000F901F701FA013508031D792834080319CD |
:1000F00093281030B6000310B20DB30DF70DFA0DB2 |
:1001000035087A02031D862834087702031C8F28DD |
:100110003408F702031CFA033508FA020314F80D39 |
:10012000F90DB60B7B280000B71F9B28F809F909C9 |
:10013000F80A0319F90A8A11E4288E30F700330807 |
:10014000F8003208F900FA01F808031DB12879080F |
:10015000F800F9010830F702F808031DB128F7018B |
:10016000B9280310F81BB828F90DF80DF703B128CA |
:10017000F81300008A11E828A9010420CC30B2004D |
:1001800017204430B2001720A908031DCB283820BF |
:100190007808A900C4280420CC30B2001720BE3053 |
:1001A000B200172038207808AA0038207808AB0061 |
:1001B0002B08AD002A08AC002D08B3002C08B200B3 |
:1001C000B5011030B4005D287808B301B2009D2855 |
:1001D0007A08B1007908B0007808AF007708AE005F |
:1001E0002E08F7002F08F8003008F9003108FA004F |
:1001F0008A11A7298E30F7002908F7022A08F9008A |
:100200002B08F800F917F708031911290310F9084A |
:10021000031D0D29F80803191129F90CF80CF70B27 |
:100220000629AA1F1829F809F909F80A0319F90A71 |
:1002300000008A11B0292A08F8012902031823298D |
:100240002908F7002F29F7010830AB00A90DF70D99 |
:100250002A0877020318F700F80DAB0B26298A113C |
:10026000BF29F701F801290803102A18F707F70C2E |
:10027000F80CAA18F707F70CF80C2A19F707F70C6F |
:10028000F80CAA19F707F70CF80C2A1AF707F70C5D |
:10029000F80CAA1AF707F70CF80C2A1BF707F70C4B |
:1002A000F80CAA1BF707F70CF80C8A11C62929309D |
:1002B0008400000803196B290130F800F701F70BDF |
:1002C0005F29F80B5E294A30F700F70B652900001B |
:1002D0000000800B5C298A11412A84011F308305AC |
:1002E000603083168F001F129F121B0880399B00FD |
:1002F00007309C001F129F121B0880399B0083123D |
:100300001F109412831606118614061200308312F1 |
:100310009400831694000108C739083881008312BD |
:1003200090010030F80092000030831692000730F0 |
:100330009C0005080330F700F70B9C291C0883126A |
:100340000D1383169D018F010F088312BC287A08B4 |
:10035000AC007908AB007808AA007708A900FA2851 |
:100360007808A3002308093C031CBA292308A40029 |
:10037000A501C9292308A9000A30AA001B29780869 |
:10038000A5002508A9000A30AA003129780823020F |
:10039000A400A7012708013C031C432AA708031D4A |
:1003A000DB298316851083128510831605118312AD |
:1003B00005152408A600270BE729831605118312CB |
:1003C000051183168510831285142508A600260BB7 |
:1003D000EE2983168601F330831286002608023C3C |
:1003E000031DF729831686014930831286002608EB |
:1003F000033C031D002A83168601613083128600A8 |
:100400002608043C031D092A831686013330831213 |
:1004100086002608053C031D122A83168601253016 |
:10042000831286002608063C031D1B2A83168601BC |
:100430000530831286002608073C031D242A8316F4 |
:100440008601F130831286002608083C031D2D2A00 |
:10045000831686010130831286002608093C031D9D |
:10046000362A83168601213083128600A608031DD2 |
:100470003E2A831686018130831286000A30A90045 |
:0C0480005729A70ACA298316A529630082 |
:04400E00F83FFF3F39 |
:00000001FF |
;PIC16F88 |
/programy/C/PIC/mereni/teplomer/main.sta |
---|
0,0 → 1,40 |
ROM used: 582 (14%) |
582 (14%) including unused fragments |
1 Average locations per line |
7 Average locations per statement |
RAM used: 13 (7%) at main() level |
28 (16%) worst case |
Lines Stmts % Files |
----- ----- --- ----- |
88 52 60 D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.c |
19 0 0 D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.h |
279 0 0 C:\Program Files\PICC\devices\16F88.h |
49 22 16 D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\1wire.c |
29 13 8 D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\ds1820.c |
----- ----- |
928 174 Total |
Page ROM % RAM Functions: |
---- --- --- --- ---------- |
0 22 4 1 @delay_ms1 |
0 19 3 0 onewire_reset |
0 33 6 2 onewire_write |
0 37 6 2 onewire_read |
0 62 11 9 ds1820_read |
0 64 11 6 @DIVS1616 |
0 31 5 2 @ITOF |
0 217 37 8 main |
0 33 6 4 @SFTOI |
0 22 4 3 @DIV88 |
0 38 7 2 @MUL88 |
Segment Used Free |
--------- ---- ---- |
00000-00003 4 0 |
00004-007FF 578 1466 |
00800-00FFF 0 2048 |
/programy/C/PIC/mereni/teplomer/main.sym |
---|
0,0 → 1,78 |
015-016 CCP_1 |
015 CCP_1_LOW |
016 CCP_1_HIGH |
021-022 main.duty |
023 main.temp |
024 main.znak1 |
025 main.znak2 |
026 main.znak |
027 main.i |
028 main.n |
029 ds1820_read.busy |
029 @DIV88.P1 |
029 @delay_ms1.P2 |
029 @MUL88.P3 |
029-02C @SFTOI.P4 |
02A @DIV88.P1 |
02A ds1820_read.temp1 |
02A @MUL88.P1 |
02B ds1820_read.temp2 |
02B @DIV88.@SCRATCH |
02C-02D ds1820_read.temp3 |
02E-031 ds1820_read.result |
032 onewire_read.count |
032-033 @ITOF.P1 |
032-033 @DIVS1616.P2 |
032 onewire_write.data |
033 onewire_write.count |
033 onewire_read.data |
034-035 @DIVS1616.P1 |
036 @DIVS1616.@SCRATCH |
037 @DIVS1616.@SCRATCH |
077 @SCRATCH |
078 @SCRATCH |
078 _RETURN_ |
079 @SCRATCH |
07A @SCRATCH |
07B @SCRATCH |
09C.6 C1OUT |
09C.7 C2OUT |
0157 @delay_ms1 |
0004 onewire_reset |
0017 onewire_write |
0038 onewire_read |
00BC ds1820_read |
005D @DIVS1616 |
009D @ITOF |
016D main |
00FA @SFTOI |
011B @DIV88 |
0131 @MUL88 |
016D @cinit |
Project Files: |
D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.c |
D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.h |
C:\Program Files\PICC\devices\16F88.h |
D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\1wire.c |
D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\ds1820.c |
Units: |
D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.c (main) |
Compiler Settings: |
Processor: PIC16F88 |
Pointer Size: 8 |
ADC Range: 0-255 |
Opt Level: 9 |
Short,Int,Long: 1,8,16 |
Output Files: |
Errors: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.err |
INHX8: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.hex |
Symbols: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.sym |
List: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.lst |
Debug/COFF: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.cof |
Call Tree: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.tre |
Statistics: D:\KAKLIK\projekty\programy\C\PIC_C\mereni\teplomer\main.sta |
/programy/C/PIC/mereni/teplomer/main.tre |
---|
0,0 → 1,19 |
ÀÄmain |
ÀÄmain 0/217 Ram=8 |
ÃÄ??0?? |
ÃÄds1820_read 0/62 Ram=9 |
³ ÃÄonewire_reset 0/19 Ram=0 |
³ ÃÄonewire_write 0/33 Ram=2 |
³ ÃÄonewire_write 0/33 Ram=2 |
³ ÃÄonewire_read 0/37 Ram=2 |
³ ÃÄonewire_reset 0/19 Ram=0 |
³ ÃÄonewire_write 0/33 Ram=2 |
³ ÃÄonewire_write 0/33 Ram=2 |
³ ÃÄonewire_read 0/37 Ram=2 |
³ ÃÄonewire_read 0/37 Ram=2 |
³ ÃÄ@DIVS1616 0/64 Ram=6 |
³ ÀÄ@ITOF 0/31 Ram=2 |
ÃÄ@SFTOI 0/33 Ram=4 |
ÃÄ@DIV88 0/22 Ram=3 |
ÃÄ@MUL88 0/38 Ram=2 |
ÀÄ@delay_ms1 0/22 Ram=1 |
/programy/C/PIC/mereni/teplomer/ds1820.c |
---|
0,0 → 1,28 |
float ds1820_read() |
{ |
int8 busy=0, temp1, temp2; |
signed int16 temp3; |
float result; |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0x44); |
while (busy == 0) |
busy = onewire_read(); |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0xBE); |
temp1 = onewire_read(); |
temp2 = onewire_read(); |
temp3 = make16(temp2, temp1); |
result = (int) (temp3/16); //calculation pro DS18B20 with 0.1 deg C |
return(result); |
} |
/programy/C/PIC/mereni/teplomer/main.err |
---|
0,0 → 1,2 |
No Errors |
0 Errors, 0 Warnings. |
/programy/C/PIC/mereni/teplomer/mainhcg.BAK |
---|
0,0 → 1,82 |
#include "main.h" |
#define LED_K1 PIN_A2 // anody segmentovek |
#define LED_K2 PIN_A1 |
//#define LED_D1 PIN_A1 // katody segmentovek ///ted uz nepotreba |
//#define LED_D2 PIN_A2 |
//#define LED_D3 PIN_A3 |
//#define LED_D4 PIN_A4 |
//#define LED_D5 PIN_A5 |
//#define LED_D6 PIN_A6 |
//#define LED_D7 PIN_A7 |
#include "1wire.c" |
#include "ds1820.c" |
void main() |
{ |
float temperature; // teplota z ds1820.c |
long duty; // strida PWM |
int temp; // zaokrouhlena teplota |
int znak1; // hodnota jednotek |
int znak2; // hodnota desitek |
int znak; // zobrazovany znak |
int i; // i pro for |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_OFF); |
setup_spi(FALSE); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
port_b_pullups(TRUE); |
while(TRUE) |
{ |
temperature = ds1820_read(); |
temp = (int) temperature; |
if (temp<10) { //pro teploty 0-10°C |
znak1=temp; |
znak2=0; |
} |
else { |
znak2=(int) (temp/10); //vydelit deseti a zaokrouhlit dolu = desitky |
znak1=temp-((int) (temp/10))*10; //jednotky rozdil teploty a desitek |
} |
for (i=1;i<=2;i++) { //cyklus zobrazeni udaje |
output_low(0x7f); //vymaz display |
if (i==1) { |
output_high(LED_K1); //dva bloky pro sepnuti aktivniho segmentu na 1 |
output_low(LED_K2); |
znak=znak1; |
} |
if (i==2) { |
output_high(LED_K2); |
output_low(LED_K1); |
znak=znak2; |
} |
if (znak==1) output_b(0x4f); //blok if pro rozeznani zobrazeneho znaku |
if (znak==2) output_b(0x12); |
if (znak==3) output_b(0x06); |
if (znak==4) output_b(0x4c); |
if (znak==5) output_b(0x2c); |
if (znak==6) output_b(0x20); |
if (znak==7) output_b(0x0f); |
if (znak==8) output_b(0x00); |
if (znak==9) output_b(0x04); |
if (znak==0) output_b(0x01); |
Delay_ms(50); |
} |
// duty=104+(2,31*temperature); // .000416/(16*(1/4000000)) ....PWM presne podle helpu |
// set_pwm1_duty(duty); |
} |
} |