View previous topic :: View next topic |
Author |
Message |
edhaslam
Joined: 15 Jul 2005 Posts: 89 Location: UK
|
Interrupt routine for 7-seg display update? |
Posted: Fri Jul 15, 2005 7:18 am |
|
|
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
|
|
Posted: Fri Jul 15, 2005 8:48 am |
|
|
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
|
|
Posted: Fri Jul 15, 2005 10:05 am |
|
|
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
|
|
Posted: Fri Jul 15, 2005 10:09 am |
|
|
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
|
|
Posted: Fri Jul 15, 2005 10:14 am |
|
|
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! |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Fri Jul 15, 2005 10:28 am |
|
|
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
|
|
Posted: Sat Jul 16, 2005 5:26 am |
|
|
MikeValencia wrote: | My 7-segment 5-digit LED display (colon included) looks like
88:88
|
Thanks Mike! |
|
|
|