So mein Code:
*********************Code:************************************** main.c: #include "setting.h" #include "display.h" #include "ds18S20.h" void main() { set_tris_a(BIT2+BIT3); set_tris_b(BIT2); lcd_int(); // Initialisierung der LCD-Anzeige delay_ms(50); while(1) { make_measure(); lcd_gotoxy(1,4); printf(lcd_putc,"Temperatur: %d,%02u C",temp_2,temp_1); delay_ms(500); } } setting.h: #include <16f628.h> #use delay(clock=4000000) #fuses XT,NOWDT,NOLVP #use fast_IO(b) #define DS18S20 PIN_A2 // TempSensor enum BITSTELLE { Bit0=1,BIT1=2,BIT2=4,BIT3=8,BIT4=16,BIT5=32,BIT6=64,BIT7=128 }; display.h: struct port_b_layout { // Layout des Ports b short blank; // freier Portpin short rs; // LCD RS short rw; // LCD RW - jetzt freier Portpin short enable; // LCD ENABLE int lcddata:4; // LCD-Daten D4...D7 } portb; #byte portb=6 //LCD an Port B #define NOP() { #asm nop #endasm } #define lcd_type 0x28 // 0x24=5x10, 0x28=2 lines byte const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0x0C, 0x01, 6}; #define LCD_BLANK() {lcd_send_byte(0,1);delay_ms(2);} void lcd_send_nibble( byte n ) { portb.lcddata = n; nop(); portb.enable = 1; delay_us(4); portb.enable = 0; } void lcd_send_byte( byte address, byte n ) { portb.rs = 0; portb.rs = address; nop(); // portb.rw = 0; // Ist jetzt auch frei nop(); portb.enable = 0; lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); } void lcd_int() { byte i; set_tris_b(4); portb.rs = 0; // siehe 4-Bit Initialisierung (LCD-Datenblatt) portb.enable = 0; delay_ms(15); // 15 ms Pause for(i=1;i<=3;++i) { lcd_send_nibble(3); // 3-mal 0011 mit mind. 5ms Pause delay_ms(5); } lcd_send_nibble(2); // 0010 = 4-Bit Interface for(i=0;i<=3;++i) lcd_send_byte(0,LCD_INIT_STRING[i]); } void lcd_gotoxy( byte x, byte y) { byte address; if (y==1) address=0; if (y==2) address=0x40; if (y==3) address=0x14; if (y==4) address=0x54; address+=x-1; lcd_send_byte(0,0x80|address); } void lcd_putc( char f) { // switch (f) // { // case '\c' : lcd_send_byte(0,1); // delay_ms(2); // break; // case '\1' : lcd_gotoxy(1,1); break; // case '\2' : lcd_gotoxy(1,2); break; // case '\3' : lcd_gotoxy(1,3); break; // case '\4' : lcd_gotoxy(1,4); break; // default : lcd_send_byte(1,f); break; // } lcd_send_byte(1,f); } DS18S20.h: #define temp_SkippRom 204 #define temp_readPower 180 #define temp_TempComp 68 #define temp_readScrachp 190 void temp_init() { set_tris_a(Bit3+Bit4); // Port A auf output Setzen output_low(DS18S20); // Pin des DS18S20 auf low setzen delay_us(500); // für mindestens 450ms warten set_tris_a(bit2+Bit3+Bit4); // Port A auf input setzen und warten while(input(DS18S20)) // ob der 1-ware bus aus low gezogen wird, { // d.h. dann es antwordet mindesten ein DS18S20 } // auf die initalisierung delay_ms(5); } void temp_send(int code) { int n; set_tris_a(Bit3+Bit4); //setze output for(n=0; n <= 7; n++) { if(bit_test(code,n)) { output_low(DS18S20); //sende 0 delay_us(2); //int write slot output_high(DS18S20); //send 1 delay_us(65); //duration für 1 und fertig } else { output_low(DS18S20); //sende 0 delay_us(65); //int write slot & send 0 } output_high(DS18S20); delay_us(2); } set_tris_a(bit2+Bit3+Bit4); //wieder auf input setzen delay_ms(1); } byte temp_read() { byte in; int b; in = 0; delay_ms(4); for(b=0; b<=7; b++) { delay_us(1); set_tris_a(Bit3+Bit4); //output output_low(DS18S20); // init read delay_us(1); set_tris_a(bit2+Bit3+Bit4); //input delay_us(2); if(input(DS18S20)) { bit_set(in,b); } delay_us(60); } return(in); } // Variablen für Termo int temp_1; int temp_2; long int null; long int eins; int scratchpad[8]; int i; make_measure() { temp_init(); temp_send(temp_SkippRom); //skippRom temp_send(temp_TempComp); //make measure delay_ms(500); //warten bis TempCompare abgeschlossen... temp_init(); temp_send(temp_SkippRom); //skippRom temp_send(temp_readScrachp); //read scratchpad for (i=0; i<8;i++) { scratchpad[i] = temp_read(); // Hier noch ein paar Berechungen zum Temperatur } temp_1 = (scratchpad[0])/2; // Im scratchpad[0] steht die Temperatur in 0,5C schritten temp_1 = temp_1-1; // also noch ein wenig Rechnen, dann bekommt man eine Auflösung // von 0,05 Grad! null = (temp_1); null = null*100; null = null-25; eins = (16 - scratchpad[6]); eins = eins*100; eins = eins/16; null = null+eins; temp_2 = null/100; eins = temp_2*100; temp_1 = null - eins; }
folgendes Problem
ich verwende kein LED Display
das heißt ich schick alles über den RS232 an den PC
...Problem is halt die Sachen rauszugeben die für mich unnötig sind,dass es aber trotzdem Funktioniert
danke für Eure Hilfe,
hat jemand event. einen andren Code??
ps:wo finde ich die 1820 und setting header files??







Zitieren

Lesezeichen