|
|
View previous topic :: View next topic |
Author |
Message |
cxiong
Joined: 09 Sep 2003 Posts: 52
|
delay for 7-segment |
Posted: Fri Nov 05, 2004 3:58 pm |
|
|
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
|
|
Posted: Fri Nov 05, 2004 4:07 pm |
|
|
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 |
|
|
|
|
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
|