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

Migration problem
Goto page 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

Migration problem
PostPosted: Wed Apr 09, 2008 3:20 pm     Reply with quote

Greetings,

By no means an expert,
I was lucky enough to convert a 16F628A code to an 18F4525 without any major issues.. except one. By converting, I replaced the #include <16F628A.h> with #include <18F4525.h> and re-compiled.

The Temp sensor, original ds1820 has been replaced with a newer ds18b20. The timer code runs fine, but the temperature sensor is reading 0, which to me means its not reading, not converting, or just plain broken.

I'm not sure where the error could be, perhaps Pin_A0 is not digital and I've no clue what I need to do to set PIN_A0 to digital to see if that is my error.

Can anyone see a possible culprit in this?

Code:

//================================================
// DIGITAL 24 Hour Clock with Thermometer project
// Compiler : PIC C
// Code originally from Sixca.com
//================================================
#include <18F4525.h>
#use delay(clock=4000000)
#fuses NOSTVREN,NOWDT,NOMCLR,NOPROTECT,NOBROWNOUT,NOPUT,NOLVP,NOPBADEN,XT
//#fuses NOWDT,XT, NOPUT, PROTECT,NOLVP,NOMCLR,NOLVP  // for 628
#include <ds1820.c>
#define DS1307_SDA  PIN_A2
#define DS1307_SCL  PIN_A3
#use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL)
//ADCON1 = 0b00001111;        //configuring analog port to digital
//TRISA = 0b00000001;        //PORT A0 as digital i/p

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 sec,min,hour;
byte fs_flag;
#define EXP_OUT_LATCH   PIN_B7
#define EXP_OUT_CLOCK   PIN_B3
#define EXP_OUT_DO      PIN_B5
#define EXP_OUT_CLEAR   PIN_B6
#define colon           PIN_B4
#define DEC             PIN_B1
#define INC             PIN_B2
#define Tsensor          PIN_A0

BYTE buff[9], sensor, n,temp,temp_dec,RES;
BYTE D_SHIFT;

//==========================
// initial DS1307
//==========================
void init_DS1307()
{
output_float(DS1307_SCL);
output_float(DS1307_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()
{
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<9; n++)     // read 9 bytes but, use only one byte
   {
      buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
   }
   temp=buff[0]>>1;
   if ((buff[0] & 0x1)==1)
      temp_dec=5;
   else
      temp_dec=0;
   D_SHIFT=0x00;
   write_expanded_outputs(D_SHIFT);
   D_SHIFT=0xE1;  // show 'C
   write_expanded_outputs(D_SHIFT);
   RES=TEMP%10;
   D_SHIFT=MAP1[RES];
   write_expanded_outputs(D_SHIFT);
   RES=TEMP/10;
   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=MAP2[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP2[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=MAP2[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP2[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=MAP2[m];
            write_expanded_outputs(D_SHIFT);
            swap(min);
            m=min & 0x07;
            D_SHIFT=MAP2[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);
for(RES=0;RES<80;RES++)
{
 // ADCON1 = {0b00001111};        //configuring analog port to digital
 // TRISA = {0b00000001};        //PORT A0 as digital i/p
   sensor=1;   // 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<9; n++)     // read 9 bytes but, use only one byte
   {
      buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
   }
}
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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 4:14 pm     Reply with quote

Post your compiler version. You can find it at the top of the .LST file
for this program. Look in the project directory for .LST file.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 4:56 pm     Reply with quote

CCS PCH C Compiler, Version 4.038, 18306 09-Apr-08 19:09
ckielstra



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

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:06 pm     Reply with quote

Quote:
CCS PCH C Compiler, Version 4.038
This is an old compiler release and not very stable, it might work but no guarantees. Best is to use the old v3.249 or upgrade to a recent version.

Quote:
I'm not sure where the error could be, perhaps Pin_A0 is not digital and I've no clue what I need to do to set PIN_A0 to digital to see if that is my error.
Add the following to the start of your main:
Code:
setup_adc_ports( NO_ANALOGS );


Code:
#use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL)

...

void init_DS1307()
{
output_float(DS1307_SCL);
output_float(DS1307_SDA);
}
Do not call the output_float() function for the I2C lines. The compiler will take care of all this and now you might interfere with the compiler handling of these lines.

Code:
void write_expanded_outputs(BYTE *D)
Here is a bug: The variable D isn't a pointer and you will get unpredictable results. Get rid of the '*'.

Last edited by ckielstra on Wed Apr 09, 2008 6:20 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:17 pm     Reply with quote

Quote:
ds1820 has been replaced with a newer ds18b20

These are different chips.

From the DS1820 data sheet:
Quote:

Temperature is read as a 9–bit digital value.


From the DS18B20 data sheet:
Quote:
The resolution of the temperature sensor is user-configurable to 9, 10, 11, or 12 bits. The default resolution at power-up is 12-bit.


I suggest that you remove the ds1820 from the old board and move it
to the new board. Then your program might work.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:19 pm     Reply with quote

Thanks for the tips,

My son-in-law's laptop and software, I'll encourage him to go get an upgrade on this software once he returns from his tour. I just tinker with it and keep his emails and anti-virus up to date.

So just remove the * and the entire float routine?
ckielstra



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

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:27 pm     Reply with quote

Quote:
So just remove the * and the entire float routine?
You posted this while I was editing and PCM Programmer added another issue.
- Remove the *
- Get rid of the init_DS1307 routine.
- Add a call to setup_adc_ports( NO_ANALOGS ) at program start.
- Get the circuit running with the old chip. After that we can help you with modifications for the new chip.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:36 pm     Reply with quote

I'll go back to the old 16F628A right now,

As for the other stuff, I'll step through each and see what happens

Thanks again for the help.. This Pic stuff is pretty interesting, should have tried it a decade or so ago while I was still surrounded with the young bucks in the dev shop.
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 7:28 pm     Reply with quote

OK, back on the 16F628A

removed the * and init 1307 routine, nothing worked.

Returned everything to original, and its all back.

timer code is working, the temp sensor is reading 7 degrees, ( not correct)

I've never had a ds1820, I've only got the ds18b20's which would explain why the temp sensor has never worked for me.

I'm not sure how to proceed from here,

Strip out the code for the ds1820 , leaving only the clock.
Then use the correct code and drivers/.h/.c files needed to make it run correctly.
Just because its running, does not mean its running right, and I'll never learn the correct methods of programming these things by sticking to bad code.
Once the clock functions are correct, I can look at bringing in the proper ds18b20 device.

I know enough Basic to be dangerous, but C is compelling.

Does this sound like a better approach than trying to repair this code, most of which is still a mystery to me?

My goal is to have a nice big led clock in the front window of the house by July 3rd, the day my son-in-law return from over there.

I'll keep the "broken" code that runs the clock safely stashed to use in case I cant get this thing running in time.

Thanks again
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 1:06 pm     Reply with quote

Ok, new day, fresh perspective;

I've removed all the code for the ds1820 sensor, What remains below is currently working and keeping correct time.

What if any changes need be done to this code, before I attempt to introduce the new ds18b20 routines.

*EDIT = Selection/set button is not responding properly on PIN_B0 (fs_flag)? on initial power on the clock flashes :00 to allow minute adjustment, but its not accepting the selection/set button to allow Hours or exit the "check switch routine"


Cheers

Code:

//========================================
//========================================
//          24 Hour Clock
//          Dallas ds1307
//           TPIC6B595N
//                2008
//========================================
//========================================
#include <16F628A.h>
#use delay(clock=4000000)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection

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

#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

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 sec,min,hour;
BYTE fs_flag;
BYTE RES;
BYTE D_SHIFT;

//========================================
// 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 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=MAP2[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP2[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=MAP2[m];
      write_expanded_outputs(D_SHIFT);
      swap(min);
      m=min & 0x07;
      D_SHIFT=MAP2[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=MAP2[m];
            write_expanded_outputs(D_SHIFT);
            swap(min);
            m=min & 0x07;
            D_SHIFT=MAP2[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);
for(RES=0;RES<80;RES++)
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

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 2:52 pm     Reply with quote

Quote:
Selection/set button is not responding properly on PIN_B0.

Look at your posted code. Is there any reference to PIN_B0 anywhere
in the program ?
ckielstra



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

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 3:08 pm     Reply with quote

Code:
   disable_interrupts(INT_EXT);
   if (fs_flag==0)
 //  {
 //     show_temp();
 //  }
   enable_interrupts(INT_EXT);
You are disabling the code here in a wrong way. What remains is:
Code:
   disable_interrupts(INT_EXT);
   if (fs_flag==0)
      enable_interrupts(INT_EXT);
After the first button press fs_flag will be unequal to zero, interrupts get never enabled again and the switch stops responding...

I had a look at the file ds1820.c and I'm not happy with what I see there, for example it contains hard coded addresses which explains why your code didn't work on the PIC18. I will come back to this later.
ckielstra



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

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 3:13 pm     Reply with quote

PCM programmer wrote:
Quote:
Selection/set button is not responding properly on PIN_B0.

Look at your posted code. Is there any reference to PIN_B0 anywhere
in the program ?
It's there, INT_EXT.
I've seen better styled programs but as the original poster says, it is working (kind of).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 3:28 pm     Reply with quote

OK, sorry. I blew one. Bummed Out
Thanks for catching it. Very Happy
Aurbo



Joined: 07 Apr 2008
Posts: 49

View user's profile Send private message

PostPosted: Thu Apr 10, 2008 5:01 pm     Reply with quote

Thanks.. I didnt see that last remaining bit of temperature code.
OK, so by removing the three lines of // disabled code, it will allow the enable _ interrupts again? or am I missing another enabler?

On a similar note, I'm using a JDM Enhanced programmer to write to the chip, There MUST be an easier way than to swap it in and out with the old chip pliers.

Will an ICD or other device aid in all of this? suggestions?

Cheers
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 1, 2, 3, 4  Next
Page 1 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