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

delay for 7-segment

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



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

delay for 7-segment
PostPosted: Fri Nov 05, 2004 3:58 pm     Reply with quote

Anybody know how to delay on pointer in C? I write my code to display
numbers (0-9 )and (.) on the 7-segment. But it was too fast and I don't
even see the numbers display on the 7-segment module.

Here is my code:

Code:


#include <18f458.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#include <stdio.h>

int my_array[] = {0x3f,0x06,0x5B,0x4F,0x66,0x6D,0X7D,0X07,0X7F,0X6F,0X80};

void main(void)
{
    int i;
   int ptr;
    ptr = &my_array[0];     // point our pointer to the first
    while(1)            //element of the array
   {                                 

      output_d(my_array[0]);
      delay_ms(500);
      output_d(my_array[1]);
      delay_ms(500);
      output_d(my_array[2]);
      delay_ms(500);
      output_d(my_array[3]);
      delay_ms(500);
      output_d(my_array[4]);
      delay_ms(500);
      output_d(my_array[5]);
      delay_ms(500);
      output_d(my_array[6]);
      delay_ms(500);
      output_d(my_array[7]);
      delay_ms(500);
      output_d(my_array[8]);
      delay_ms(500);
      output_d(my_array[9]);
      delay_ms(500);
      output_d(my_array[10]);
      delay_ms(500);
      
    }
}



Is this the write way to display a digit in a 7-segment? I will use 3
segments in serial to display temperature data. But first I need to write a
routine to test the 7-segment.

I will appreciate any help...
Ttelmah
Guest







PostPosted: Fri Nov 05, 2004 4:07 pm     Reply with quote

The first comment, is that you cannot store a 'pointer', in an integer. A pointer can potentially point anywhere in RAM, and on the 18chips, needs more than 8bits of storage.
The second comment, is 'why bother'?. You are not using this 'pointer' anywhere at all. You can simply loop to keep the code a lot shorter. So:
Code:

#include <18f458.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#include <stdio.h>

int my_array[] = {0x3f,0x06,0x5B,0x4F,0x66,0x6D,0X7D,0X07,0X7F,0X6F,0X80};

void main(void)
{
   int i;
   //If you want a 'pointer', for use elsewhere, declare it as:
   int *ptr;
   ptr = &my_array[0];     // point our pointer to the first
   //element of the array if required.
   while(1) {                                 
      for (i=0;i<11;i++) {
          output_d(my_array[i]);
          delay_ms(500);
      }
   }
}


Best Wishes
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