Sari la conținut
ELFORUM - Forumul electronistilor

Termometru-PIC16F877!!!!!!!!!!!!!!!!!!!!


Vizitator Gladiatorul1933

Postări Recomandate

Vizitator Gladiatorul1933

Trebuie sa fac un proiect cu PIC16F84-DS18B20-LCD16x2 ....si am nevoie urgenta de un cod!!Va rog frumos pe cei care aveti sau stiti si puteti sa ma ajutati ...........v-as fi foarte recunoscator!!!!!!!

Link spre comentariu
  • Răspunsuri 1
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

  • gr1ph0n

    1

Top autori în acest subiect

Codul principal:

#include <16f84.h>#use delay(clock=4000000)#fuses NOWDT,XT, NOPUT, NOPROTECT#include "1wire.c"#include "mylcd.c"float ds1820_read(){int8 busy=0, temp1, temp2;signed int16 temp3;float result;onewire_reset();onewire_write(0xCC);onewire_write(0x44);delay_ms(200);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 = (float) temp3 / 16.0;  //0.1 deg C resolutiondelay_ms(200);return(result);}void main(){float temperature; delay_ms(50);   lcd_init();//for  10 bit resolution modonewire_write(0xCC);onewire_write(0x4E);onewire_write(125);  onewire_write(-55); //this should be done for proper working of DS18B20   onewire_write(127);onewire_reset();   onewire_write(0xCC);    onewire_write(0x48);    delay_ms(15);while (1){  temperature = ds1820_read();lcd_putc("\f");printf(lcd_putc,"Temp:");printf (lcd_putc," %d", (signed int) temperature);delay_ms(100);}} //enf of main program

1wire.c

#ifndef ONE_WIRE_C#define ONE_WIRE_C/* * One wire (1-wire) driver for CCS C compiler. Suitable for use with devices * such as the DS18B20 1-wire digital temperature sensor. */#define ONE_WIRE_PIN PIN_A0/* * onewire_reset() * Description: Initiates the one wire bus. */// OK if just using a single permanently connected devicevoid onewire_reset() {    output_low(ONE_WIRE_PIN);       // pull the bus low for reset    delay_us(500);    output_float(ONE_WIRE_PIN);     // float the bus high    delay_us(500);                  // wait-out remaining initialisation window    output_float(ONE_WIRE_PIN);}/* * onewire_write(int8 data) * Arguments: a byte of data. * Description: writes a byte of data to the device. */void onewire_write(int8 data) {    int8 count;    for(count = 0; count < 8; ++count) {        output_low(ONE_WIRE_PIN);        delay_us(2);                // pull 1-wire low to initiate write time-slot.        output_bit(ONE_WIRE_PIN, shift_right(&data, 1, 0)); // set output bit on 1-wire        delay_us(60);               // wait until end of write slot.        output_float(ONE_WIRE_PIN); // set 1-wire high again,        delay_us(2);                // for more than 1us minimum.    }}/* * onewire_read() * Description: reads and returns a byte of data from the device. */int onewire_read() {    int count, data;    for(count = 0; count < 8; ++count) {        output_low(ONE_WIRE_PIN);        delay_us(2);                // pull 1-wire low to initiate read time-slot.        output_float(ONE_WIRE_PIN); // now let 1-wire float high,        delay_us(8);                // let device state stabilise,        shift_right(&data, 1, input(ONE_WIRE_PIN)); // and load result.        delay_us(120);              // wait until end of read slot.    }    return data;}#endif /*ONE_WIRE_C*/

 

mylcd.c

struct lcd_pin_map {                 // This structure is overlayed           BOOLEAN enable;           // on to an I/O port to gain           BOOLEAN rs;               // access to the LCD pins.           BOOLEAN rw;               // The bits are allocated from           BOOLEAN unused;           // low order up.  ENABLE will           int     data : 4;         // be pin B0.        }        lcd;#byte lcd = 6                  // on to port B (at address 6)#define set_tris_lcd(x) set_tris_b(x)#define lcd_type 1           // 1 lines#define lcd_line_two 0x40    // LCD RAM address for the second lineBYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 3),0xC,1,6};                             // These bytes need to be sent to the LCD                             // to start it up.                             // The following are used for setting                             // the I/O port direction register.struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are outstruct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are inBYTE lcd_read_byte(){      BYTE low,high;      set_tris_lcd(LCD_READ);      lcd.rw = 1;      delay_cycles(1);      lcd.enable = 1;      delay_cycles(1);      high = lcd.data;      lcd.enable = 0;      delay_cycles(1);      lcd.enable = 1;      delay_us(1);      low = lcd.data;      lcd.enable = 0;      set_tris_lcd(LCD_WRITE);      return( (high<<4) | low);}void lcd_send_nibble( BYTE n ){      lcd.data = n;      delay_cycles(1);      lcd.enable = 1;      delay_us(2);      lcd.enable = 0;}void lcd_send_byte( BYTE address, BYTE n ){      lcd.rs = 0;      while ( bit_test(lcd_read_byte(),7) ) ;      lcd.rs = address;      delay_cycles(1);      lcd.rw = 0;      delay_cycles(1);      lcd.enable = 0;      lcd_send_nibble(n >> 4);      lcd_send_nibble(n & 0xf);}void lcd_init(){    BYTE i;    set_tris_lcd(LCD_WRITE);    lcd.rs = 0;    lcd.rw = 0;    lcd.enable = 0;    delay_ms(15);    for(i=1;i<=3;++i) {       lcd_send_nibble(3);       delay_ms(5);    }    lcd_send_nibble(2);    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=lcd_line_two;   else     address=0;   address+=x-1;   lcd_send_byte(0,0x80|address);}void lcd_putc( char c){   switch (c) {     case '\f'   : lcd_send_byte(0,1);                   delay_ms(2);                                           break;     case '\n'   : lcd_gotoxy(1,2);        break;     case '\b'   : lcd_send_byte(0,0x10);  break;     default     : lcd_send_byte(1,c);     break;   }}char lcd_getc( BYTE x, BYTE y){   char value;    lcd_gotoxy(x,y);    while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low    lcd.rs=1;    value = lcd_read_byte();    lcd.rs=0;    return(value);

Nu stiu daca o sa functioneze la tine, nu ai specificat nicio schema. Vrei cod pentru PIC16F84 sau PIC 16F877?

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum



×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări