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  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Fri Apr 11, 2008 10:38 pm     Reply with quote

Just looking around the program,

Is there any way to have Winpic800 load the .hex file as soon as its compiled?

EDIT*****

Found it,

User Defined Tools;

After Build
"C:\ blah blah blah\WinPic800\WinPic800.exe" "%H"

It works
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 6:10 pm     Reply with quote

Quote:
This part is not working yet but should be. I may have to look at the ds1820.c file and see if I'm making A1 digital and blocking the led from lighting up.

In the file ds1820.c the whole of portA are made input pins, disregarding the sensor number given.

Try replacing the part:
Code:
#BYTE TRISA=0x85
#BYTE PORTA=0x5
#BYTE STATUS=0x3
#define RP0  5
#define C 0


// The following are standard 1-Wire routines.
void make_ds1820_high_pin(int sensor)
{
   TRISA = 0xff;
}

void make_ds1820_low_pin(int sensor)
{
   PORTA = 0x00;
   TRISA = 0xff & (~(0x01 << sensor));
}
by:
Code:
// The following are standard 1-Wire routines.
void make_ds1820_high_pin(int sensor)
{
   output_float(PIN_A0 + sensor);
}

void make_ds1820_low_pin(int sensor)
{
   output_low(PIN_A0 + sensor);
}
This now respects the sensor number, is easier to read and does no longer use the hard coded address for PortA which makes it easier to port to other processors (remember your porting problem at the start of this thread?).

A nice improvement to your code would be not to pass the sensor number as a parameter but to pass the sensor pin number. That would allow sensors to be connected to other ports beside PortA.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 7:45 pm     Reply with quote

ckielstra,

Whats actually scarier, is that I understood that code change. Shocked

Thanks again.

I've spent the the evening re-mapping the hex code to display .x values for the decimal degree's

Code:
BYTE CONST MAP3[10]={0xFE,0x38,0xED,0X7D,0X3B,0X77,0XF7,0x3C,0xFF,0X7F};


If your change solves the negative symbol , then I can jump back over to the clock code and try to make 2 separate clock run at the same time, one default running, the other will flash like th etemp did, only in a second time format. Think Local and Zulu time.

Cheers
Steve
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 8:05 pm     Reply with quote

Remove these as well?

Code:
#BYTE TRISA=0x85
#BYTE PORTA=0x5
#BYTE STATUS=0x3
#define RP0  5
#define C 0


If I do, I pick 11 new "Undefined identifier" errors.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 2:55 pm     Reply with quote

Here are a few pondering points;

Code:
BYTE CONST MAP1[10]={0xFA,0x30,0xD9,0x79,0X33,0x6B,0xEB,0x38,0xFB,0x7B};
// BYTE CONST MAP2[10]={0xDE,0x18,0xCD,0x5D,0X1B,0x57,0xD7,0x1C,0xDF,0x5F};
BYTE CONST MAP3[10]={0xFE,0x38,0xED,0x7D,0x3B,0x77,0xF7,0x3C,0xFF,0x7F};


Map3 was added to properly display the decimal point for the 1/10th values. .1 through .0

Map2 will still be used for the Clock values for the 2 right digits when its merged back in to the code.

Right now I'm trying to bring PIN_A1 to designate - negative values.

The questions I have is which method would be better:

1.
Code:

#define Tnegsign        PIN_A1
// Show sign
  if (TempIsPos)
  {
    output_high(Tnegsign); // add here your positive sign showing code.
  }
  else
  {
   output_low(Tnegsign); // add here your negative sign showing code.
  }


I've just spent the better part of 4 hours trying to make a code for this, but I cant get it out of my head, so I will try this way.

1. Check Temp value
2. If Positve, run routine A
2. If Negative, Then run routine B

Code:

// This is the current code in the program
Routine A
// Split temperature in a temperature sign, positive degrees and a fraction
  if (Temp16 >= 0)
  {
    TempIsPos = TRUE;
  }
  else
  {
    TempIsPos = FALSE;
    Temp16 = -Temp16;     // Make absolute value
  }
  temp = Temp16 >> 4;
  temp_dec = ((Temp16 & 0x0F) * 10) / 16;

  // Display data
  D_SHIFT=0xE1;      // Show °C
  write_expanded_outputs(D_SHIFT);

  D_SHIFT = MAP3[ 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);

// remove this routine
//// Show sign
//  if (TempIsPos)
//  {
//   output_high(Tnegsign); // add here your positive sign showing code.
//  }
//  else
//  {
//   output_low(Tnegsign); // add here your negative sign showing code.
//  }

output_high(EXP_OUT_LATCH);




Code:
Routine B
RES=temp/10;                // Show 10's
  if (RES==0)
    D_SHIFT=0x01;        // lights up G segment to show a neg symbol for negative 1's values
 
 else
    D_SHIFT=MAP4[RES];  // uses a NEW MAP similar to MAP3 and rebuild the left digit dot as a negative symbol instead
 
  write_expanded_outputs(D_SHIFT);




What I am wondering is would Routine A/B be better (If I get it to work) for migration to other chips by removing specific PIN_A1 assigment as in the current code?

Would this be considered "better programming methods"
(did I modify routine A/B correctly?

Which method creates less work for the PIC?

Cheers
Steve
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 5:21 pm     Reply with quote

Sorry, I don't completely understand your A/B method. Partially this is because I don't have a good understanding of your hardware. Can you explain again why did you have to introduce the new character maps?
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 5:59 pm     Reply with quote

Hardware= JDM enchanced programmer
(PicKit2 due in on Tuesday, I hope)

If you mean hardware for this project,
http://www.sixca.com/eng/articles/clock/clock.gif
replace the ds1820 with a ds18B20.

4th character map would be for the negative 10's values, by using the dot point of the left digit, I make make it into a negative sign.

So if Temperature is positive;
Map1 displays 0-9 without the dp.
Map3 displays the 1/10th value WITH the dp

Digits 3 and 4 are inversed to digits 1 and 2 to allow the dp's to act as : colon's while in clock mode. Sixca website never really explains why this is needed, especially when PIN_B4 acts as its own colons for seconds pulsing.

It would be no issue that I can see at this point to make all 4 digits uniform in configuration and make use of each of the dp's for °c, .tenths, -10's as well the colon : for seconds.

The led displays are home-made so I can move around the dp's to suit.

So
MAP1 displays time in hours or positive temps in whole numbers.
MAP2 displays time in minutes for the inverted digits
MAP3 displays temp in tenth's with the dp
MAP4 displays NEGATIVE digits in whole degrees below -9.9°c

I was thinking that by modifying this code:
Code:
RES=temp/10;                // Show 10's
  if (RES==0)
    D_SHIFT=0x00;        // blanks the left digit for single digit values 
 else
    D_SHIFT=MAP1[RES];   
  write_expanded_outputs(D_SHIFT);


to add in something like this
Code:
RES=temp/10;                // Show -10's
  if (RES=<-10)
    D_SHIFT=0x01;        // lights up G segment on the left digit to show a neg symbol for negative 1's values
  else
    D_SHIFT=MAP4[RES];  // uses a NEW MAP4 using the dp to display the negative sign instead
   write_expanded_outputs(D_SHIFT);



Just looking for a different way to display the values without doing things like:
#
Code:
define Tnegsign        PIN_A1
// Show sign
  if (TempIsPos)
  {
    output_high(Tnegsign); // add here your positive sign showing code.
  }
  else
  {
   output_low(Tnegsign); // add here your negative sign showing code.
  }


This type of coding requires an additional pair of resistors and a transistor and led's where the MAP method only requires a few addtions led's and a resistor.

Its not that I'm cheap and cant use an extra transistor, I'm trying to learn and understand different methods of reaching the same goal.

Cheers
Steve
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 6:09 pm     Reply with quote

I just wish I new how to build my own or find a Proteus model for a TPIC6B595 chip and I could poke away at this while at work as well.
Would save a lot of chip programming and swapping in and out the chip off the breadboard.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 4:31 pm     Reply with quote

Reading more on this pic programming, I've encountered another question I hope someone may have a quick answer to:

In a typical main file, one of the first things you want to do is
#include <pic you intend to use.h>
in my case its #include <16F628A.h>

Now this calls up the following file

16F628A.h
Code:

Deleted by forum moderator

Now is this a file that requires alteration of any kind? or is it just a template or kind of chip formatting for that specific chip?
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Tue Apr 15, 2008 2:04 pm     Reply with quote

Reading through the manuals on how to set up my Pickit2 to use with CCS. Lots of reading Shocked
I received my PicKit2 Debugger Express kit today.

I'm still hung up on one point of the code to show a negative sign if the Temp is negative.

Code:


  // Split temperature in a temperature sign, positive degrees and a fraction
  if (Temp16 == 0)
  {
    TempIsPos = TRUE;
  }
  else
  {
    TempIsPos = FALSE;
    Temp16 = -Temp16;     // Make absolute value
  }
  temp = Temp16 >> 4;
  temp_dec = ((Temp16 & 0x0F) * 10) / 16;

  // Display data
  D_SHIFT=0xE1;      // Show °C
  write_expanded_outputs(D_SHIFT);

  D_SHIFT = MAP3[ 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);

  // Show sign
  if (TempIsPos)
  {
    TempIsPos = FALSE;
    output_float(PIN_A1);
    output_low(Tnegsign); //  hide the neg sign.
  }
  else
  {
    output_float(PIN_A1);
    output_high(Tnegsign); // show the neg sign.
  }

  output_high(EXP_OUT_LATCH);
}
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sat Apr 19, 2008 12:24 pm     Reply with quote

A new weekend is here and too sunny to stay indoors.

A few things struck me last night after leaving the project a few days.

1. The digits are all hand-made, so why complicate the project by inversing and inverting digits.. unless the original code was used on commercial 7 segment led digit units.

Soultion: oriented all the digits the SAME way, saves on wiring confusion and pcb layout. It will also reduces the code a bit ridding itself of the extra MAPx's

To make this happen, would I still need 2 character MAPs?

1 for whole numbers and 2 for decimal numbers?

or is there another way to do this?

Code:
BYTE CONST MAP1[10]={0xFA,0x30,0xD9,0x79,0X33,0x6B,0xEB,0x38,0xFB,0x7B};
BYTE CONST MAP2[10]={0xFE,0x34,0xDD,0x7D,0x37,0x6F,0xEF,0x3C,0xFF,0x7F};


MAP1 = 0,1,2,3,4,5,6,7,8,9
MAP2 = .0,.1,.2,.3,.4,.5,.6,.7,.8,.9


Code:
// Display data
      D_SHIFT=0x00;
      write_expanded_outputs(D_SHIFT);
 
      D_SHIFT=0xE1;      // Show 0xE1=°C, 0x20=° ,0x01=-G seg
      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++)
    output_high(EXP_OUT_LATCH);
  delay_ms(500);
Ttelmah
Guest







PostPosted: Sat Apr 19, 2008 2:23 pm     Reply with quote

Map2, is always the same as the value from Map1, plus 4.
Not exactly complex maths!.... Smile

Best Wishes
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Sat Apr 19, 2008 4:03 pm     Reply with quote

Thanks for that Ttelmah Very Happy

In your detailed explanation were you trying to say that if I just make:

Code:
D_SHIFT = MAP1[ RES+4 ];  // Show fraction
      write_expanded_outputs(D_SHIFT);

instead of
Code:

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


I could do away with the MAP2 character map entirely? and it will work for both the temperature readings as well as the clock readings, providing I rebuild the right two digits in the same format as the left two digits?

I agree, Math is not complex, its finding the right answer and expressing it in a format others can understand that can be complex for some.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun Apr 20, 2008 2:03 am     Reply with quote

Aurbo wrote
Quote:
I agree, Math is not complex, its finding the right answer and expressing it in a format others can understand that can be complex for some.


Ttelmah wrote
Quote:
Map2, is always the same as the value from Map1, plus 4.

Aurbo sees that as MAP1[ RES+4 ]; which means Aurbo may have issues with math that few will ever have. Hopefully Aurbo can discover his own errors.
Ttelmah's suggestion was accurately written.

Altering code without a basic introduction to coding is counter productive. It certainly isn't interesting for others to watch someone chip pieces out of working code and replace it with code based only on the hope that the force is with them .
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

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

I agree that its not interesting to watch some one chip away at other's code and hope for the force to make it happen, or worse give them the answers they dont want or care to understand as long as it gets their homework done for tomorrow. I'm sure we've all encountered that.

I'm hoping someone out there may know of a way to add to a hex value without it becoming difficult or bulky.

I am trying to learn with the assistance of the users of CCS software in C language, 30+ years poking about Basic on occassion gave rise to many bad coding practises that the group here have been gracious enough to help me identify and try to correct before I venture deeper into C.

Being recently retired I've got plenty of time to read and try other things code wise, but its always good to have a correct method handy to compare my tests against.

In this regard 'ckielstra' has been of great help to point out the errors and suggest alternate solutions with proper coding in mind.

And yes, I see the error, RES+4 would advance the resultant value +4 and not adjust the the character map hex value by 4.

What I dont see is how to properly add 4 units to a hex value without becoming bogged down in code going off on a tangent. I'm at over 75% useable rom on my chip and I dont wish to add more code unless its absolutley required.

Trying out different code lines last evening quickly identified that my first assumption on the alteration was incorrect, but not wrong as it places a real solution within reach. But will the solution be practical.

Converting to binary to add 4 then back does not appear to add any benefical gain or reduce code space. Which makes this approach un-practical.

While personal vanity says I dont need to go back and learn Basic again, that I can jump right into C, reality and users like ckielstra have shown me I need to spend more time reading C tutorials.

Other posts dropped into threads that lack anything beyond a "Nelson Munse" comment, while sometimes entertaining, reduces the effectiveness of serious posts.

Perhaps Mr Kennedy or someone else may know of a method to advance a hex value in C without converting to binary first.


Regards
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  Next
Page 3 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