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 support@ccsinfo.com

question about time temp project

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



Joined: 25 Mar 2007
Posts: 19

View user's profile Send private message

question about time temp project
PostPosted: Sun Apr 01, 2007 10:30 pm     Reply with quote

I've completed this project, thanks to everyone for their help. My next step is I want to add a barometer to the circuit, with the empty pins, I'm thinking MPX4115, however I have a question.

The circuit I'm using is



The RSIN and RESET pins are going to a text-to-speech board that isn't shown on the schematic.

The DS1307 is running off I2C protocol, The DS1620 is running with output_bit, output_high, output_low. I know the MPX4115 sends voltage to the ADC of the PIC, is there a tutorial anywhere for performing ADC voltage out of the sensor to the PIC? I've looked at many examples but they are all in ASM, and the ones included with the compiler aren't helping me much either. Any suggestions or ideas, on how to approach this would be appreciated thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 01, 2007 10:48 pm     Reply with quote

MPX4115 project using the CCS compiler:
http://members.cox.net/igalysh/pressure.html
mcnscott2



Joined: 25 Mar 2007
Posts: 19

View user's profile Send private message

PostPosted: Sun Apr 01, 2007 11:41 pm     Reply with quote

wonderful! Thanks a bunch PCM. I'll begin to analyze this and work to apply it into my project.
mcnscott2



Joined: 25 Mar 2007
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 8:49 am     Reply with quote

I've started looking at the DS 1 wire protocol, do you think it is possible to apply it to this setup? I'm already using RS-232 for the text-to-speech card, so I'm a bit confused how to use RS-232 for another device, such as the pressure sensor.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 9:56 pm     Reply with quote

Quote:
I've started looking at the DS 1 wire protocol, do you think it is possible to apply it to this setup?


You've got unused pins, you should be able to do it. What do you plan on using it for?

Quote:
I'm already using RS-232 for the text-to-speech card, so I'm a bit confused how to use RS-232 for another device, such as the pressure sensor.


You can make a second RS232 port in software. Are you thinking of a different pressure sensor... a serial one? If you do add a second one, timing becomes an issue, but it doesn't appear that your project relies on critical RS232 communications, so it shouldn't be a factor.

Most of the examples in the CCS library are 'bit-banged' software driven drivers. In other words, they can be used without having a hardware serial port available.

John
mcnscott2



Joined: 25 Mar 2007
Posts: 19

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 11:02 pm     Reply with quote

Thanks for the tip! I'm looking at using the unused pins to make a barometer now for the circuit using the MPX4115 and the PIC's internal ADC to reference the supply voltage, thereby making the barometer. Eventually I may put in a humidity sensor, however, that is way down the road, from the posts I've read SHT11 is a good one but has compatibility issues.

To answer your question, there will be just 1 pressure sensor, I was wondering about the DS1 wire protocol, because it looked easier, looking deeper though, I think I should just go with the motorola sensor. it's just a matter of me figuring out how to program the PIC for it, since I've only done ADC in asm and never as complex as a barometer ( just referencing voltages to turn on LED's).
mcnscott2



Joined: 25 Mar 2007
Posts: 19

View user's profile Send private message

PostPosted: Wed Apr 04, 2007 8:11 am     Reply with quote

Another question, following the link on the website PCM Programmer provided, they are using an MPX4115 and an eeprom to store the data, for my project adding a pressure sensor I don't need to keep the data stored.

I'm not sure If I will use the MPX4115 with a seperate ADC or the internal PIC ADC. I'm reading all the documentation I can find on setting up ADC.

current flow chart
1. initialize IC's
2. display time and temp on the 7 segment display
3. on the hour initialize text-to-speech card
4. send the data to the text-to-speech card
5. reset the card
6. continue monitoring time and temp until next hour

I want to add

a. setup PIC for ADC
b. read data from sensor convert to digital
c. display pressure on 7 segment
d. on the hour send data to card
e. say the pressure after the temp on the hour
f. continue monitoring time, temp, pressure.
I don't want anyone to write the code I want to learn it
Questions though:

1. do I need an eeprom, since I won't be "storing" the data?
2. does my method for data flow look ok?
3. Is there anything obvious problem I may run into, coding wise?

here is the original source code

by Bruce Reynolds, Reynolds Electronics
all copyrights, IP and licenses are his.

Code:
/*

File name: SLED4C_1620a.c

Talking time & temp with display of time & temperature on the
SLED4C serial LED display module. Uses the DS1620 temp sensor,
DS1307 RTC, and EMIC text-to-speech module

When the temperature >= the high alarm setpoint, display the OUCH
message. Below setpoint, display the temp normally with voice
updates of time & temp on every hour.

MAX temperature range is from 0 to 99

*/

#include <SLED4C_1620a.h>          // header file & function prototypes

void Main(void)
{
   int announce=0;                 // holds # of time/temp announcements

   init();                         // initialize I/O & peripherals

   while(1)                        // loop forever
   {
     read_time();                  // read & display DS1307 time
     read_temp();                  // read & display DS1620 temp

     // announce time/temp on roll-over from 59 to 00 minutes
     if(ds1307_regs[MINUTES_REG]==0x00)
     {
       if(!announce)               // say time & temp only if announce=0
       {
         say_time();               // say the current time
         delay_ms(3000);           // delay 3 seconds
         say_temp();               // say the current temperature
         announce +=1;             // increment announcement counts
       }
     }

     if(!ds1307_regs[MINUTES_REG]==0x00)
        announce=0;                // clear announcements until it's time
   }
}

// initialize hardware
void init(void)
{
   port_b_pullups(FALSE);          // portb internal pull-ups off
   setup_comparator(NC_NC_NC_NC);  // all comparators = off
   disable();                      // SLED4C enable pin must idle high
   output_bit(CLK,0);              // SLED4C clock pin must idle low
   disable_interrupts(GLOBAL);     // global interrupts off
   setup_EMIC(2,1);                // set EMIC volume 0=low 7=max & pitch 0=low to 6=high
   set_time();                     // set ds1307 time on power-up
   init_1620();                    // inititialize DS1620 temp sensor
   setpoint=0x85;                  // set high temp alarm setpoint here
}

// shift out 8-bits in DAT MSB first
void send_byte(int DAT)
{
   int n;
   for(n=0; n<8; n++)              // loop for 8-bits total
   {
     output_bit(DOUT,DAT & 0x80);  // output MSB of 8-bit value
     output_bit(CLK, 1);           // clock pin = 1
     output_bit(CLK, 0);           // clock pin = 0
     DAT = DAT << 1;               // shift lower bits left into MSB of byte
   }
}

// shift out low nibble in NIB MSB first
void send_nib(int NIB)
{
   int n;
   for(n=0; n<4; n++)              // loop for 4-bits total
   {
     output_bit(DOUT,NIB & 0x08);  // output MSB of 4-bit value
     output_bit(CLK, 1);           // clock pin = 1
     output_bit(CLK, 0);           // clock pin = 0
     NIB = NIB << 1;               // shift lower bits left into MSB of nibble
   }
}

// take SLED4C enable pin low
void enable(void)
{
   output_bit(EN,0);               // this enables data entry into SLED4C
}                                  // onboard config & data display registers

// take SLED4C enable pin high
void disable(void)
{
   output_bit(EN,1);               // this transfers data to the SLED4C internal
}                                  // registers then disables further data entry

// write a byte to the DS1620
void write_1620(byte cmd)
{
   byte i;

   for(i=0; i<8; i++)
   {
     output_low(CLKD);
     output_bit(DQ, shift_right(&cmd,1,0));
     output_high(CLKD);
   }
}

// initialize the DS1620
void init_1620(void)
{
   // set CLK and RST to correct states
   output_high(CLKD);
   delay_us(2);
   output_low(RST);

   // set DS1620 config to continuous convert
   // and CPU communications mode
   output_high(RST);
   write_1620(0x0C);           // send Write Config command
   write_1620(0x02);           // configure for CPU mode, continuous convert
   output_low(RST);

   // start conversion
   output_high(RST);
   write_1620(0xEE);           // send Start Convert command
   output_low(RST);
}

// read & display temperature from DS1620.
void read_temp(void)
{
   byte i;

   output_high(RST);
   write_1620(0xAA);          // send Read Temp command

   temp_data = 0;             // clear temp_data on entry

   for(i=0; i<9; i++)         // loop for 9-bits
   {
     output_low(CLKD);
     temp_data = temp_data >> 1;
     if (input(DQ))
     {
        temp_data = temp_data | 0x100;
     }
     output_high(CLKD);
   }

   temp_data = temp_data/2;      // convert temp_data to whole deg C

   output_low(RST);

   convert();                    // convert C to F then to BCD

   if (temp_r >= setpoint)       // if temp >= setpoint display OUCH
   {
      ouch();                    // call OUCH function if temp >= high setpt
      return;                    // do not update temp display when temp >= setpt
   }

   enable();                     // enable SLED4C data entry
   send_byte(0b11001011);        // digits 5,4,2 HEX decode. Digits 3,1 special
   disable();                    // write config value into config register

   delay_ms(1);                  // short pause between config & display reg write

   enable();                     // enable SLED4C data entry
   send_nib(0x00);               // DIM display + DP's off
   send_byte(temp_r);            // display temp on digits 5/4
   send_byte(0xFF);              // display Deg F on digits 3/2
   send_nib(0x00);               // turn colon off
   disable();                    // write data into display registers
   delay_ms(2000);               // wait 2 seonds between temp & time updates
}

// convert temp from deg C to deg F, then pass
// to BCD conversion conversion function
void convert(void)
{
   temp_data = (temp_data * 9/5)+32; // convert C to F
   temp_r = toBCD(temp_data);        // convert to BCD for display
}

// display OUCH when temp >= high alarm setpoint
void ouch(void)
{
   int y = 8, n;

   enable();                     // enable data entry
   send_byte(0b11010111);        // digits 5,3 hex decode. 4,2,1 special
   disable();                    // write config data into config register

   for(n=0; n<8; n++)            // execute ouch display function 8 times
   {
      y ^= 8;                    // toggle y.bit.3
      enable();                  // enable SLED4C data entry
      send_nib(y);               // toggle DIM & BRIGHT, no DP's
      send_byte(0x0A);           // display OU on digits 5/4
      send_byte(0xC2);           // display CH on digits 3/2

      send_nib(0x00);            // turn colon off
      disable();                 // write display data into display registers
      delay_ms(250);             // set display "blink loop" delay time in mS
   }
}

// this function converts an 8 bit binary value
// to an 8 bit BCD value. Input range from 0 to 99.

char toBCD(char bin_val)
{
   char temp;
   char retval;

   temp = bin_val;
   retval = 0;

   while(1)
   {
   // get tens digit by multiple subtraction
   // of 10 from bin_val
      if(temp >= 10)
      {
         temp -= 10;
         retval += 0x10; // increment tens digit
      }
         else            // get ones digit by adding remainder
      {
         retval += temp; // adjusted result
         break;
      }
   }
         return(retval);
}

// set time & date on power-up
void set_time(void)
{
   char i;

   // put initial date/time into array
   ds1307_regs[SECONDS_REG]     = 55;// seconds
   ds1307_regs[MINUTES_REG]     = 59;// minutes
   ds1307_regs[HOURS_REG]       = 21;// hour
   ds1307_regs[DAY_OF_WEEK_REG] = 0; // not used
   ds1307_regs[DATE_REG]        = 14;// date
   ds1307_regs[MONTH_REG]       = 07;// month
   ds1307_regs[YEAR_REG]        = 04;// year

   // convert to BCD

   for(i=0; i<7; i++)
   {
      ds1307_regs[i] = toBCD(ds1307_regs[i]);
   }

   ds1307_regs[SECONDS_REG] &= 0x7f;
   ds1307_regs[HOURS_REG] &= 0x3f;

   // write 7 bytes of BCD data to ds1307
   i2c_start();
   i2c_write(WRITE_CNTRL);

   // start at seconds register
   i2c_write(SECONDS_REG);

   // write 7 bytes to registers 0 to 6
   for(i=0; i<7; i++)
   {
      i2c_write(ds1307_regs[i]);
   }
   i2c_write(CONTROL_INIT_VAL);
   i2c_stop();
}

// read time & date from DS1307
void read_time(void)
{
   i2c_start();
   i2c_write(WRITE_CNTRL);

   // start i2c read at seconds register
   i2c_write(SECONDS_REG);

   i2c_start();
   i2c_write(READ_CNTRL);

   // read the 7 bytes from the ds1307. Mask off the unused bits
   ds1307_regs[SECONDS_REG]     = i2c_read() & 0x7f;
   ds1307_regs[MINUTES_REG]     = i2c_read() & 0x7f;
   ds1307_regs[HOURS_REG]       = i2c_read() & 0x3f;
   ds1307_regs[DAY_OF_WEEK_REG] = i2c_read() & 0x07;
   ds1307_regs[DATE_REG]        = i2c_read() & 0x3f;
   ds1307_regs[MONTH_REG]       = i2c_read() & 0x1f;
   ds1307_regs[YEAR_REG]        = i2c_read(0);

   i2c_stop();

   enable();                     // enable SLED4C data entry
   send_byte(0b11000001);        // all banks HEX decode
   disable();                    // write config value into config register

   enable();                     // enable SLED4C data entry
   send_nib(0x00);               // DIM display + DP's off
   send_byte(ds1307_regs[HOURS_REG]);   // display hour on banks 5/4
   send_byte(ds1307_regs[MINUTES_REG]); // display minutes on banks 3/2

   send_nib(0x02);               // turn colon on
   disable();                    // write data into display registers
   delay_ms(2000);               // wait 2 seconds between temp & time updates
}

// say the time
void say_time(void)
{
   printf("say=the time iz %X  %X;",ds1307_regs[HOURS_REG],ds1307_regs[MINUTES_REG]);
   delay_ms(2000);          // allow time for message to play
}                           // adjust as required for message length

// say the temperature
void say_temp(void)
{
   printf("say=the temperature iz %Ld degrees faren hyte;",temp_data);
   delay_ms(2000);          // allow time for message to play
}                           // adjust as required for message length

// initialize EMIC module & set volume + pitch
void setup_EMIC(int vol, int pitch)
{
   output_bit(EM_Rst,0);     // hard reset the EMIC module
   delay_us(200);            // wait a minimum of 100uS
   output_float(EM_Rst);     // float reset output to release
   delay_ms(1000);           // wait for EMIC OK response before proceeding
   printf("volume=%d;",vol); // send volume setting
   delay_ms(1000);           // wait for EMIC OK response before proceeding
   printf("pitch=%d;",pitch);
   delay_ms(1000);
}



The Header File:
/*
File name: SLED4C_1620a.h
Header file for SLED4C_1620a.c

*/

#include <16f876A.h>
#use delay(clock=20000000)
#use rs232(baud=2400, xmit=PIN_C0)
#use i2c(Master, SDA=PIN_B0, SCL=PIN_B1)


// Define DS1620 interface pins
#define DQ PIN_B2     // Wire rb2 to pin #1 on DS1620
#define CLKD PIN_B3   // Wire rb3 to pin #2 on DS1620
#define RST PIN_B4    // Wire rb4 to pin #3 on DS1620

// Define SLED4C interface pins
#define EN PIN_B5     // Wire rb5 to enable pin #5 on SLED4C
#define CLK PIN_B6    // Wire rb6 to clock pin #4 on SLED4C
#define DOUT PIN_B7   // Wire rb7 to data pin #3 on SLED4C

// DS1307 control bytes
#define WRITE_CNTRL 0xd0
#define READ_CNTRL 0xd1

// DS1307 register offsets
#define SECONDS_REG 0
#define MINUTES_REG 1
#define HOURS_REG 2
#define DAY_OF_WEEK_REG 3
#define DATE_REG 4
#define MONTH_REG 5
#define YEAR_REG 6
#define CONTROL_REG 7
#define DATE_TIME_BYTE_COUNT 7
#define DS1307_NVRAM_START_ADDR 8
#define CONTROL_INIT_VAL 0x80

// EMIC text to speech constants
#define EM_Rst PIN_C1       // EMIC voice module reset pin #14


// Global vars
signed long temp_data;      // raw temp
int8 temp_r;                // final BCD temp result
int setpoint;               // high temp setpoint

// PIC I/O & peripheral init function prototype
void init(void);            // PIC port & peripheral initialization

// SLED4C serial display function Prototypes
void send_byte(int DAT);    // send byte value to SLED4C
void send_nib(int NIB);     // send nibble value to SLED4C
void enable(void);          // enable data entry into SLED4C registers
void disable(void);         // write data into SLED4C registers & disable

// DS1620 & temp related function prototypes
void write_1620(byte cmd);  // write to DS1620
void init_1620(void);       // initialize DS1620
void read_temp(void);       // read temp from DS1620
void convert(void);         // convert C to F then to BCD for display
void ouch(void);            // display OUCH when >= high temp setpoint
char toBCD(char bin_val);   // conversion to BCD

// DS1307 function prototypes
void set_time(void);
void read_time(void);
char read_byte(char addr);
void write_byte(char addr, char value);

//EMIC text-to-speech module function prototypes
void say_time(void);
void say_temp(void);
void setup_EMIC(int vol, int pitch);

int ds1307_regs[DATE_TIME_BYTE_COUNT];

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