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

Interrupt routine for 7-seg display update?

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



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

Interrupt routine for 7-seg display update?
PostPosted: Fri Jul 15, 2005 7:18 am     Reply with quote

Hi All,

I've just started learning embedded C and I've just finished going through the sample code included with the CCS PCWH compiler. I'm attempting to write my own code, but i'm struggling to get interrupts to work.

I'm basically reading the temperature from a DS1631 device and displaying the 'tens' value on a dual 7-seg display. The problem being that the DS1631 only updates every 750ms. Obviously if I add this delay in the code below, the 7-seg will also only update every 750ms.

Is there a way I can add in an interrupt routine that reads the temp every 750ms, but allows the display to update in the main() routine?

Any help/pointers would be very much appriciated.

Code:

//******************************************************************************
//
// Author:   Ed Haslam
// Date:     15.07.05
// Project:  -
// File:     Ed_1.c
//
// Description:
//
// Digital Thermometer with 7 Segment Display - buggy, needs interruts?
//
//******************************************************************************

#include <prototype.h>
#include <ds1631.c>


byte CONST LED_MAP[10] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

void display_number( int n ) {
   output_b(LED_MAP[n/10]);
   output_low(PIN_C0);
   delay_ms(2);
   output_high(PIN_C0);
   output_b(LED_MAP[n%10]);
   output_low(PIN_C1);
   delay_ms(2);
   output_high(PIN_C1);
}

void main() {
   int value;

   init_temp();

   while(TRUE) {
      value = read_full_temp();
      display_number(value);
      delay_ms(750);
   }
}



regards,
Ed
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 8:48 am     Reply with quote

You can do this by multi tasking.
Code:

while (true)
{  if(Read_Temp_Delay)
   {  --Read_Temp_Delay;
   }
   else
   {  Read_Temp_Delay=750;
      Pull_Temp_Reading();
   }
   Update_Display():
   delay_ms(1);
}
edhaslam



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 10:05 am     Reply with quote

Neutone,

Not too sure how the code below works? Can you perhaps explain it a bit more as i'm not entirely sure what's going on. Sorry to have to make you spell it out...

Ed

Neutone wrote:
You can do this by multi tasking.
Code:

while (true)
{  if(Read_Temp_Delay)
   {  --Read_Temp_Delay;
   }
   else
   {  Read_Temp_Delay=750;
      Pull_Temp_Reading();
   }
   Update_Display():
   delay_ms(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 10:09 am     Reply with quote

Quote:

I'm basically reading the temperature from a DS1631 device and
displaying the 'tens' value on a dual 7-seg display. The problem
being that the DS1631 only updates every 750ms. Obviously if I
add this delay in the code below, the 7-seg will also only update
every 750ms.

http://www.ccsinfo.com/forum/viewtopic.php?t=17189&highlight=multitasking
edhaslam



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 10:14 am     Reply with quote

PCM programmer wrote:
Quote:

I'm basically reading the temperature from a DS1631 device and
displaying the 'tens' value on a dual 7-seg display. The problem
being that the DS1631 only updates every 750ms. Obviously if I
add this delay in the code below, the 7-seg will also only update
every 750ms.

http://www.ccsinfo.com/forum/viewtopic.php?t=17189&highlight=multitasking


Many thanks PCM programmer! Smile
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Jul 15, 2005 10:28 am     Reply with quote

My 7-segment 5-digit LED display (colon included) looks like

88:88

ca_io[] is a char array of size 5:
ca_io[0] = pattern for digit 1
ca_io[1] = pattern for digit 2
ca_io[2] = colon on/off
ca_io[3] = pattern for digit 3
ca_io[4] = pattern for digit 4

I refresh it continuously with my RTCC isr:

Code:

#INT_RTCC
void timer1_isr(void)
{
    static int x = 0;

    if (!GLOBAL_inhibit_all_leds)
    {
        port_a = ca_io[x];
        port_d = GLOBAL_character[x];
    }
 
    x++;
    if (x == 5)
    {
        x = 0;
    }

}


Furthermore, I have my RTCC set at
xtal: 8Mhz
PLLx4 enabled: gives effective 32MHz Fosc.

(4 * 128 * 256) / 32000000 = 4ms per timer overflow interrupt

Code:

    set_timer0(0);
    setup_counters( RTCC_INTERNAL, RTCC_DIV_128 | RTCC_8_BIT);
    enable_interrupts(INT_RTCC);
    enable_interrupts(GLOBAL);
Guest








PostPosted: Sat Jul 16, 2005 5:26 am     Reply with quote

MikeValencia wrote:
My 7-segment 5-digit LED display (colon included) looks like

88:88



Thanks Mike!
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