CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pic16f877 with 2 ds18s20

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
azakuri



Joined: 02 Aug 2008
Posts: 4

View user's profile Send private message Yahoo Messenger

pic16f877 with 2 ds18s20
PostPosted: Tue Sep 02, 2008 6:36 am     Reply with quote

again...after along moment, i had studied the ds18s20 and i tried to make the coding but it seems many errors occurs...i just need to make sure this thing happen.

1. sensor 1 - sensor 2 and result in celcius display on lcd.
2. when both sensor differ > 50 degree the buzzer and red led will activate.
3. when it differ between 30 to 50 yellow led will activate.
4. when it differ less than 30 degree, green led will activate.


Code:
#include < 16F877.H >
#include < jonsinc.h >
#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT

#define DS1820_DATA_IN_PIN          PIN_C0
#define DS1820_FET_CONTROL_PIN      PIN_C1
#define DS1820_SKIP_ROM             0xCC
#define DS1820_READ_SCRATCHPAD      0xBE
#define DS1820_CONVERT_T            0x44
// LCD STUFF
#define LCD_D3      PIN_RB3
#define LCD_D4      PIN_RB4
#define LCD_D5      PIN_RB5
#define LCD_D6      PIN_RB6
#define LCD_D7      PIN_RB7
#define LCD_EN      PIN_RE1
#define LCD_RS      PIN_RE0
#define LINE_1      0x00
#define LINE_2      0x40
#define CLEAR_DISP  0x01
#define DEGREE_SYM  0xdf

#use delay ( clock=6000000 )
#use standard_io ( A )
#use standard_io ( B )
#use standard_io ( C )

void ResetDS1820 ( void );
void WriteDS1820 ( void );
void ReadDS1820 ( void );
void WaitForConversion ( void );
void LCD_Init ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar ( unsigned int cX );
void LCD_PutCmd ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );

static char cShiftBit,cDataOut;
static long iTemperature,iDataIn;

void main ( void )
    {
    delay_ms ( 200 );

    LCD_Init();
    LCD_SetPosition ( LINE_1 + 0 );
    printf ( LCD_PutChar, "Temperature is" );
    while ( TRUE )
        {
        ResetDS1820();
        cDataOut = DS1820_SKIP_ROM;
        WriteDS1820();
        cDataOut = DS1820_CONVERT_T;
        WriteDS1820();
        WaitForConversion();

        ResetDS1820();
        cDataOut = DS1820_SKIP_ROM;
        WriteDS1820();
        cDataOut = DS1820_READ_SCRATCHPAD;
        WriteDS1820();
        ReadDS1820();
        iTemperature = iDataIn / 2;
        LCD_SetPosition ( LINE_2 + 5 );
        printf ( LCD_PutChar, "%lu%cC %lu%cF   ", iTemperature, DEGREE_SYM, ( ( 9 * iTemperature ) / 5 ) + 32, DEGREE_SYM  );
        }
    }

void ResetDS1820 ( void )
    {
    output_low ( DS1820_DATA_IN_PIN );         
    delay_us ( 480 );                               
    output_float ( DS1820_DATA_IN_PIN );         
    delay_us ( 480 );                               
    }

void WriteDS1820 ( void )           
    {
    for ( cShiftBit = 1; cShiftBit <= 8; ++cShiftBit )
        {
        output_low ( DS1820_DATA_IN_PIN );
        delay_us ( 5 );
        output_bit ( DS1820_DATA_IN_PIN, shift_right ( &cDataOut, 1, 0 ) );
        delay_us ( 60 );
        output_float ( DS1820_DATA_IN_PIN );
        delay_us ( 5 );       
        }
    //delay_us ( 200 );           
    }

void ReadDS1820 ( void )             
    {
    iDataIn = 0;
    for ( cShiftBit = 1; cShiftBit <= 16; ++cShiftBit )
       {
       output_low ( DS1820_DATA_IN_PIN );
       delay_us ( 5 );
       output_float ( DS1820_DATA_IN_PIN );
       delay_us ( 5 );
       shift_right ( &iDataIn, 2, input ( DS1820_DATA_IN_PIN ) );   
       delay_us ( 55 );         
       }
    ResetDS1820();             
    }

void WaitForConversion ( void )             
    {
    while ( TRUE )
       {
       output_low ( DS1820_DATA_IN_PIN );
       delay_us ( 5 );
       output_float ( DS1820_DATA_IN_PIN );
       delay_us ( 5 );
       if ( input ( DS1820_DATA_IN_PIN ) == 1 )   
           {
           break;
           }
       delay_us ( 55 );         
       }
    }

void LCD_Init ( void )
    {
    LCD_SetData ( 0x00 );
    delay_ms ( 200 );       
    output_low ( LCD_RS );
    LCD_SetData ( 0x03 );   
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_SetData ( 0x02 );   
    LCD_PulseEnable();     
    LCD_PutCmd ( 0x2C );   
    LCD_PutCmd ( 0x0C );   
    LCD_PutCmd ( 0x01 );   
    LCD_PutCmd ( 0x06 );   
    }

void LCD_SetPosition ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    LCD_SetData ( swap ( cX ) | 0x08 );
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );
    LCD_PulseEnable();
    }

void LCD_PutChar ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    output_high ( LCD_RS );
    LCD_SetData ( swap ( cX ) );     
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     
    LCD_PulseEnable();
    output_low ( LCD_RS );
    }

void LCD_PutCmd ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    LCD_SetData ( swap ( cX ) );     
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     
    LCD_PulseEnable();
    }

void LCD_PulseEnable ( void )
    {
    output_high ( LCD_EN );
    delay_us ( 10 );
    output_low ( LCD_EN );
    delay_ms ( 5 );
    }

void LCD_SetData ( unsigned int cX )
    {
    output_bit ( LCD_D0, cX & 0x01 );
    output_bit ( LCD_D1, cX & 0x02 );
    output_bit ( LCD_D2, cX & 0x04 );
    output_bit ( LCD_D3, cX & 0x08 );
    }
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group