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

Migration problem
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







PostPosted: Sun Apr 20, 2008 8:23 am     Reply with quote

You are _not_ working with 'hex values'....
The numbers inside the chip, are stored in binary. Hex, is just the 'notation', you have used to input the numbers to the array.

All you need do, is in place of reading 'Map2', just use:

Map1[RES]+4

No magic. The chip couldn't care a damn, whether you have input the numbers in hex, binary, octal, decimal or whatever.

Best Wishes
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sun Apr 20, 2008 9:12 am     Reply with quote

Thanks Ttelmah,

I'll give it a try after I re-map the character map.

Laying down some traces to build this and get it off my breadboard, I noticed that I can change the 595 pinouts in a better arrangment to avoid a bunch of jumper wires or long traces snaking all over the pcb.

To do this, I'll need to completely re-write the character map.

Cheers
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun Apr 20, 2008 11:39 am     Reply with quote

All numbers are notation. Doesn't matter if you write them down by hand or type them into a program. In a program some notations are more useful. Binary notation fits very well with the on off states of electronic components. This means that the notation can often be manipulated directly by Micro computer instructions. The CCS compiler is aware of the advantage of binary notation so it will convert any notation in source code to a binary notation whenever doable. So 123( base 10) or 0xFF (base 16) will be notated as binary after the compiler is done. The compiler handles mixed notation Ex x=0x0A y=4 z=x+y is good because the compiler is internally notating all in binary. Other notations such as floating point will eventually be manipulated as binary operations by the Microprocessor.In the case of floating point an extensive algorithm manipulates the notation and returns the result as notation. Numbers can be expressed in many bases however we are most familiar with base ten. Any base is equal as far as notation for numbers but bases which are a power of two are more useful again due to the underlying on/off nature of electronics. Hex (base 16) or even octal (base 8) but especially binary ( base 2) are great for electronics. Now a world of base 2 notation and our world of base ten notation are equal in stature but not equal in results. This never makes either binary or base ten the correct one. Its just the limitations of the notation itself. Now for whole numbers there is never any issue but for fractions it is not the same. 1/10 in base ten can be notated well but 1/10 (one tenth) in binary cannot. Programming lore has this as a rounding error. The error can be diminished by going from 32 bits to 64 bits but it never will disappear since it is fundamental and relates to notational differences. Natures numbers are universal. The distance to the moon doesn't change if you use a different scale to measure it ( miles versus kilometers) but if the result isn't an integer or an exact power series in the base of our notation then our notation of the distance will introduce a notational limitation on accuracy. Our brains need notation to tame all but the smallest of numbers.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Thu Sep 25, 2008 11:37 pm     Reply with quote

Greetings again,

Its been almost 6 months since I shelved this project to learn more about programming and circuit designs in general.

I've remapped the TPIC6B595n outputs and solved a few issues and I'm happy to say this is now running the way I was expecting.

I have a question I've not been able to answer myself and I'll toss it out to see if anyone can see what I can't at this point.

I am trying to get the code to check for a negative temperature from the sensor, if greater than zero, it will use Map1, if less than zero it will use Map2

Map2 displays all values from .0 to .9
I have utilized the .dp on digit1 to represent a negative sign, so this digit should visually display -0 to -9 for the 10's values.

At this point I get the temperature flashing in super slow motion so I believe I have the code working through both greater than as well as less than sections which has doubled the delay times.

Any suggestions?

Code:
//=================================
// show temperature
//=================================
void show_temp()
{
  signed int16 Temp16;
  int8 sensor;
  int8 n;
  int8 count;
 
  output_high(colon);
  for (count=0;count<8;count++)  // blink temperature 8 times
  {
  output_low(EXP_OUT_LATCH);
  sensor=0;   // DS1820 CONNECT TO PIN A0
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0x44, sensor);  // perform temperature conversion
  while (read_ds1820_one_byte(sensor)==0xff); // wait for conversion complete
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0xbe, sensor);  // read the result
 
  for (n=0; n<DS1820_SCRATCH_BUFFER_SIZE; n++)     // read 9 bytes but, use only one byte
  {
     buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
  }
  Temp16 = make16(buff[1], buff[0]);
     
  if (Temp16 > 0) //greater than Zero
           temp = Temp16 >> 4;
           temp_dec = ((Temp16 & 0x0F) * 10) / 16;
  // Display data
      D_SHIFT=0x00;
      write_expanded_outputs(D_SHIFT);
 
      D_SHIFT=0xD8;      // Show 0xD8=°C, 0xF1=°F, 0x40=-G seg, 0x80=.
      write_expanded_outputs(D_SHIFT);

      D_SHIFT = MAP2[ temp_dec ];  // Show fraction
      write_expanded_outputs(D_SHIFT);

      RES = temp%10;              // Show 1's
      D_SHIFT = MAP1[RES];
      write_expanded_outputs(D_SHIFT);

      RES=temp/10;                // Show 10's
      if (RES==0)
         D_SHIFT=0x00;
      else
         D_SHIFT=MAP1[RES];
         
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      delay_ms(500);

      output_low(EXP_OUT_LATCH);
      for (n=1;n<=4;n++)
      {
         D_SHIFT=0x00;
         write_expanded_outputs(D_SHIFT);
      }
    output_high(EXP_OUT_LATCH);
  delay_ms(500);
  }
}
 
  else
  {
    Temp16 = -Temp16;     // Make absolute value
  }
  temp = Temp16 >> 4;
  temp_dec = ((Temp16 & 0x0F) * 10) / 16;
  // Display data
      D_SHIFT=0x00;
      write_expanded_outputs(D_SHIFT);
 
      D_SHIFT=0xD8;      // Show 0xD8=°C, 0xF1=°F, 0x40=-G seg, 0x80=.
      write_expanded_outputs(D_SHIFT);

      D_SHIFT = MAP2[ temp_dec ];  // Show fraction
      write_expanded_outputs(D_SHIFT);

      RES = temp%10;              // Show 1's
      D_SHIFT = MAP1[RES];
      write_expanded_outputs(D_SHIFT);

      RES=temp/10;                // Show 10's
      if (RES==0)
         D_SHIFT=0x00;
      else
         D_SHIFT=MAP1[RES];
         
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      delay_ms(500);

      output_low(EXP_OUT_LATCH);
      for (n=1;n<=4;n++)
      {
         D_SHIFT=0x00;
         write_expanded_outputs(D_SHIFT);
      }
    output_high(EXP_OUT_LATCH);
  delay_ms(500);
  }
}








This is the entire code below for reference.

Code:
//========================================
//========================================
#include <16F628A.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NOBROWNOUT, NOMCLR, NOLVP, NOCPD //628A

#use delay(clock=4000000)
#include <ds1820.c>

#define RTC_SDA         PIN_A2               
#define RTC_SCL         PIN_A3               
#use i2c(master, sda=RTC_SDA, scl=RTC_SCL)   

BYTE CONST MAP1[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
BYTE CONST MAP2[10]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF};

BYTE buff[DS1820_SCRATCH_BUFFER_SIZE];
BYTE sensor;
BYTE n;
BYTE temp;
BYTE temp_dec;
BYTE sec,min,hour;
BYTE fs_flag;
BYTE RES;
BYTE D_SHIFT;

#define DEC             PIN_B1
#define INC             PIN_B2
#define EXP_OUT_CLOCK   PIN_B3
#define colon           PIN_B4
#define EXP_OUT_DO      PIN_B5
#define EXP_OUT_CLEAR   PIN_B6
#define EXP_OUT_LATCH   PIN_B7

//========================================
// initial DS1307
//========================================
void init_DS1307()
{
output_float(RTC_SCL);
output_float(RTC_SDA);
}

//========================================
// write data one byte to DS1307
//========================================
void write_DS1307(byte address, BYTE data)
{
   short int status;
   i2c_start();
   i2c_write(0xd0);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   i2c_start();
   status=i2c_write(0xd0);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(0xd0);
   }
}

//========================================
// read data one byte from DS1307
//========================================
BYTE read_DS1307(byte address)
{
   BYTE data;
   i2c_start();
   i2c_write(0xd0);
   i2c_write(address);
   i2c_start();
   i2c_write(0xd1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

//=================================
// WRITE DATA TO 6B595
//=================================
void write_expanded_outputs(BYTE D)
{
   BYTE i;
   for(i=1;i<=8;++i)
   {  // Clock out bits from the eo array
   if ((D & 0x80)==0)
      output_low(EXP_OUT_DO);
   else
      output_high(EXP_OUT_DO);
   D=D<<1;
   output_high(EXP_OUT_CLOCK);
   output_low(EXP_OUT_CLOCK);
   }
}

//=================================
// show temperature
//=================================
void show_temp()
{
  signed int16 Temp16;
  int8 sensor;
  int8 n;
  int8 count;
 
  output_high(colon);
  for (count=0;count<8;count++)  // blink temperature 8 times
  {
  output_low(EXP_OUT_LATCH);
  sensor=0;   // DS1820 CONNECT TO PIN A0
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0x44, sensor);  // perform temperature conversion
  while (read_ds1820_one_byte(sensor)==0xff); // wait for conversion complete
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0xbe, sensor);  // read the result
 
  for (n=0; n<DS1820_SCRATCH_BUFFER_SIZE; n++)     // read 9 bytes but, use only one byte
  {
     buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
  }
  Temp16 = make16(buff[1], buff[0]);

    if (Temp16 > 0)
  {
    TempIsPos = TRUE;
    // place positive values from Map1 and display
  }
  else
  {
    Temp16 = -Temp16;     // Make absolute value
    // display negative values from Map2 using the .dp as the negative sign
  }

// this is the working display sequence but does not distinguish pos/neg temps

  temp = Temp16 >> 4;
  temp_dec = ((Temp16 & 0x0F) * 10) / 16;
  // Display data
      D_SHIFT=0x00;
      write_expanded_outputs(D_SHIFT);
 
      D_SHIFT=0xD8;      // Show 0xD8=°C, 0xF1=°F, 0x40=-G seg, 0x80=.
      write_expanded_outputs(D_SHIFT);

      D_SHIFT = MAP2[ temp_dec ];  // Show fraction
      write_expanded_outputs(D_SHIFT);

      RES = temp%10;              // Show 1's
      D_SHIFT = MAP1[RES];
      write_expanded_outputs(D_SHIFT);

      RES=temp/10;                // Show 10's
      if (RES==0)
         D_SHIFT=0x00;
      else
         D_SHIFT=MAP1[RES];
         
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      delay_ms(500);

      output_low(EXP_OUT_LATCH);
      for (n=1;n<=4;n++)
      {
         D_SHIFT=0x00;
         write_expanded_outputs(D_SHIFT);
      }
    output_high(EXP_OUT_LATCH);
  delay_ms(500);
  }
}



//=================================
// show time 1
//=================================
void show_time1()
{
byte m;
      output_low(EXP_OUT_LATCH);
      output_low(colon);
      min=read_ds1307(1);
      hour=read_ds1307(2);
      m=min & 0x0F;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      m=hour & 0x0F;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      swap(hour);
      m=hour & 0x03;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      swap(min);
      swap(hour);
}

//=================================
// check switch
//=================================
void check_sw()
{
byte j;
if (fs_flag!=0)
{
   if (!input(INC))
   {
      if (fs_flag==1)
      {
         min=read_ds1307(1);
         min++;
         j=min & 0x0F;
         if (j>=0x0A) min=min+0x06;
         if (min>=0x60) min=0;
         write_ds1307(1,min);
      }
      else
      {
         hour=read_ds1307(2);
         hour++;
         j=hour & 0x0F;
         if (j>=0x0A) hour=hour+0x06;
         if (hour>=0x24) hour=0;
         write_ds1307(2,hour);
      }
    show_time1();
   }
   if (!input(DEC))
   {
      if (fs_flag==1)
      {
         min=read_ds1307(1);
         if (min!=0)
         {
            min--;
            j=min & 0x0F;
            if (j>=0x0A) min=min-0x06;
         }
         else min=0x59;
         write_ds1307(1,min);
      }
      else
      {
         hour=read_ds1307(2);
         if (hour!=0)
         {
            hour--;
            j=hour & 0x0F;
            if (j>=0x0A) hour=hour-0x06;
         }
         else hour=0x23;
         write_ds1307(2,hour);
      }
    show_time1();
   }
}
}

//=================================
// show time
//=================================
void show_time(byte fs)
{
byte m;
      output_low(EXP_OUT_LATCH);
      output_low(colon);
      min=read_ds1307(1);
      hour=read_ds1307(2);
      m=min & 0x0F;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      m=hour & 0x0F;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      swap(hour);
      m=hour & 0x03;
      D_SHIFT=MAP1[m];
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      swap(min);
      swap(hour);
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      //delay_ms(500);
      if (fs==0)
      {
         output_high(colon);
      //   delay_ms(500);
      }
      else
      {
         if (fs==1)
         {
            output_high(colon);
            output_low(EXP_OUT_LATCH);
            D_SHIFT=0x00;
            write_expanded_outputs(D_SHIFT);
            D_SHIFT=0x00;
            write_expanded_outputs(D_SHIFT);
            m=hour & 0x0F;
            D_SHIFT=MAP1[m];
            write_expanded_outputs(D_SHIFT);
            swap(hour);
            m=hour & 0x03;
            D_SHIFT=MAP1[m];
            write_expanded_outputs(D_SHIFT);
            output_high(EXP_OUT_LATCH);
            //delay_ms(500);
         }
         else
         {
            output_high(colon);
            output_low(EXP_OUT_LATCH);
            m=min & 0x0F;
            D_SHIFT=MAP1[m];
            write_expanded_outputs(D_SHIFT);
            swap(min);
            m=min & 0x07;
            D_SHIFT=MAP1[m];
            write_expanded_outputs(D_SHIFT);
            D_SHIFT=0x00;
            write_expanded_outputs(D_SHIFT);
            D_SHIFT=0x00;
            write_expanded_outputs(D_SHIFT);
            output_high(EXP_OUT_LATCH);
            //delay_ms(500);
         }
      }
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
      delay_ms(100);
      check_sw();
}
#int_EXT
void EXT_isr()
{
fs_flag++;
if (fs_flag>=3) fs_flag=0;
delay_ms(100);
}

//=====================================
// main program start here
//=====================================
void main(void)
{
   byte u;
      delay_ms(5);
      port_b_pullups(true);
      output_low(EXP_OUT_CLEAR);
      delay_us(10);
      output_high(EXP_OUT_CLEAR);
     
      init_ds1307();
      u=read_ds1307(0);
      sec=u & 0x7F;// enable RTC
      write_ds1307(0,sec);   // set second to 00 and enable clock(bit7=0)
      output_low(EXP_OUT_CLOCK);
     
      fs_flag=0;
      ext_int_edge(H_TO_L);      // init interrupt triggering for button press
      enable_interrupts(INT_EXT);
      enable_interrupts(GLOBAL);
     
  while(true)
   {
      disable_interrupts(INT_EXT);
      if (fs_flag==0)
      {
         show_temp();
      }
      enable_interrupts(INT_EXT);
      for (u=0;u<20;u++)
      {
         show_time(fs_flag);
      }
   }
} //end of main program
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Fri Sep 26, 2008 2:21 pm     Reply with quote

I think I solved the problem.

Wont know now until I can get a negative temperature to verify

Code:

BYTE Map_Choice;
BYTE ZERO;

//=================================
// show temperature
//=================================
void show_temp()
{
  signed int16 Temp16;
  int1 TempIsPos;
  int8 sensor;
  int8 n;
  int8 count;
 
  output_high(colon);
  for (count=0;count<8;count++)  // blink temperature 8 times
  {
  output_low(EXP_OUT_LATCH);
  sensor=0;   // DS1820 CONNECT TO PIN A0
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0x44, sensor);  // perform temperature conversion
  while (read_ds1820_one_byte(sensor)==0xff); // wait for conversion complete
  init_ds1820(sensor);
  write_ds1820_one_byte(0xcc, sensor);  // skip ROM
  write_ds1820_one_byte(0xbe, sensor);  // read the result
 
  for (n=0; n<DS1820_SCRATCH_BUFFER_SIZE; n++)     // read 9 bytes but, use only one byte
  {
     buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
  }
  Temp16 = make16(buff[1], buff[0]);

    // Split temperature in a temperature sign, positive degrees and a fraction
  if (Temp16 > 0)
  {
    TempIsPos = TRUE;
    Map_Choice = MAP1[RES]; //  use normal
    ZERO=0x00;
  }
  else
  {
    TempIsPos = FALSE;
    Temp16 = -Temp16;     // Make absolute value
    Map_Choice = MAP2[RES]; // show the neg sign
    ZERO=0xBF;
  }
  temp = Temp16 >> 4;
  temp_dec = ((Temp16 & 0x0F) * 10) / 16;
  // Display data
      D_SHIFT=0x00;
      write_expanded_outputs(D_SHIFT);
 
      D_SHIFT=0xD8;      // Show 0xD8=°C, 0xF1=°F, 0xBF=-0 seg, 0x80=.
      write_expanded_outputs(D_SHIFT);

      D_SHIFT = MAP2[ temp_dec ];  // Show fraction
      write_expanded_outputs(D_SHIFT);

      RES = temp%10;              // Show 1's
      D_SHIFT = MAP1[RES];
      write_expanded_outputs(D_SHIFT);

      RES=temp/10;                // Show 10's
      if (RES==0)
         D_SHIFT=ZERO;
      else
         D_SHIFT=Map_Choice;
         
      write_expanded_outputs(D_SHIFT);
      output_high(EXP_OUT_LATCH);
      delay_ms(500);

      output_low(EXP_OUT_LATCH);
      for (n=1;n<=4;n++)
      {
         D_SHIFT=0x00;
         write_expanded_outputs(D_SHIFT);
      }
    output_high(EXP_OUT_LATCH);
  delay_ms(500);
  }
}

Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Fri Sep 26, 2008 8:22 pm     Reply with quote

Its a chilly -18.8C up here near the North Pole and I confirmed the negative temps are displaying correctly.

Now to get the code to display Days and Hours instead of Hours and Minutes. This is the next step in my alterations.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
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