|
|
View previous topic :: View next topic |
Author |
Message |
blink Guest
|
dual 7 segment |
Posted: Wed Jan 16, 2008 3:14 am |
|
|
hi everyone.. i plan to connect a temperature transducer to 2 seven segments and display the readings of the transducer in the 7 segments.. i came up with this code
Code: |
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#device ADC=10
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
// declare functions
void findnumbers(int temp);
void sendhex(int number, int digit);
void displaynumbers(int tens, int ones);
int getavgtemp();
void main() {
float value, value1;
int value3;
int temp;
int i=0;
setup_adc (ADC_CLOCK_INTERNAL);
setup_adc_ports(PIN_A1);
set_adc_channel (1);
set_tris_b(0);
temp = 0;
output_b (0x00);
while(TRUE) {
value = read_adc ();
delay_ms (500);
value1 = ((value * 5) /1023) * 1000;
value3 = value1 - 273.15;
temp = value3;
for(i=0; i<200; i++)
{
findnumbers(temp);
}
}
}
// function to find number
void findnumbers(int temp)
{
int tens = 0; // tens position
int ones = 0; // ones position
output_high(PIN_D0); // lite led to tell me im in findnumbers
if (temp <100> 0)
{
sendhex(tens, 2);
sendhex(ones, 1);
}else{
sendhex(ones, 1);
}
output_low(PIN_D2);
}
|
the problem however with this code is that it displays the digits one number at a time.. for ex. i get a value of 20 degrees Celcius. it first display the number 2 on the first 7 segment while the second 7 segment remains blank.. then the second 7 segment will display the number 0 while the first 7 segment becomes blank.. i cant really figure out why is this happening... can anybody help me out with this? thanks.. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE |
Posted: Wed Jan 16, 2008 7:10 am |
|
|
Hi,
You must enable the first digit, then quickly enable the second digit (after disabling digit 1), the proces should be repeated continously and very quickly .
If the speed is slow then you can actually see the digits flicker.
Are you using a seven segment decoder such as a 7447 for decoding segment data???
thanks
arunb |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Wed Jan 16, 2008 7:17 am |
|
|
Did this line compile? You havent shown all your code so it's hard to see why it doesnt work |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 16, 2008 7:33 am |
|
|
I'd expect the line to compile, but not work....
Statements evaluate left to right, unless precedence rules apply.
So this will evaluate as 'temp<100', which will return true/false, and then this logic value will be tested to see if it is greater than 0 (which will be true if it is true).
To test a number being in a 'range', you need:
if ((temp<100>=10))
which would appear to be what is required (temp is between 10, and 99, therefore tow digits are needed).
How the numbers need to be displayed, will depend on how they are wired. If the two values are 'multiplexed' (share the individual segment lines), then arunb is right, and ideally a timer interrupt should be used to display each digit in turn _quickly_ to avoid flicker. If they are separately wored, then this is not necessary, but six more pins will be needed on the PIC (another seven segments, less the digit selects).
Best Wishes |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Wed Jan 16, 2008 8:05 am |
|
|
True, it is valid (if not sensible!) C
Quote: | Code: | if ((temp<100>=10)) |
|
Did you mean
Code: | if ((temp<100) && (temp>=10)) |
? |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 16, 2008 9:09 am |
|
|
Yes, I think I may have been hit by the 'html' problem.
Hadn't turned it off for a 'one line' posting, and it seems to have garbaged what I typed...
Why oh why is it not the default for this to be off......
Best Wishes |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jan 16, 2008 10:10 am |
|
|
Bad HTML! (smacks it's nose with a rolled up news paper) Bad HTML!
|
|
|
blink Guest
|
Re: dual 7 segment |
Posted: Wed Jan 16, 2008 9:21 pm |
|
|
hi everyone.. im truly sorry that i didnt post the whole code.. here it is
Code: |
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#device ADC=10
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
// declare functions
void findnumbers(int temp);
void sendhex(int number, int digit);
void displaynumbers(int tens, int ones);
int getavgtemp();
void main() {
float value, value1;
int value3;
int temp;
int i=0;
setup_adc (ADC_CLOCK_INTERNAL);
setup_adc_ports(PIN_A1);
set_adc_channel (1);
set_tris_b(0);
temp = 0;
output_b (0x00);
while(TRUE) {
value = read_adc ();
delay_ms (500);
value1 = ((value * 5) /1023) * 1000;
value3 = value1 - 273.15;
temp = value3;
for(i=0; i<200; i++)
{
findnumbers(temp);
}
}
}
// function to find number
void findnumbers(int temp) // get tens ones (for seven seg display)
{
int tens = 0; // tens position
int ones = 0; // ones position
output_high(PIN_D0); // lite led to tell me im in findnumbers
if (temp <100> 0)
{
sendhex(tens, 2);
sendhex(ones, 1);
}else{
sendhex(ones, 1);
}
output_low(PIN_D2);
}
|
there was a typo error on my first post.. i change it already to
(temp < 100).. my apologies.. |
|
|
blink Guest
|
Re: dual 7 segment |
Posted: Wed Jan 16, 2008 9:24 pm |
|
|
hi everyone.. im truly sorry that i didnt post the whole code.. here it is
Code: |
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#device ADC=10
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
// declare functions
void findnumbers(int temp);
void sendhex(int number, int digit);
void displaynumbers(int tens, int ones);
int getavgtemp();
void main() {
float value, value1;
int value3;
int temp;
int i=0;
setup_adc (ADC_CLOCK_INTERNAL);
setup_adc_ports(PIN_A1);
set_adc_channel (1);
set_tris_b(0);
temp = 0;
output_b (0x00);
while(TRUE) {
value = read_adc ();
delay_ms (500);
value1 = ((value * 5) /1023) * 1000;
value3 = value1 - 273.15;
temp = value3;
for(i=0; i<200; i++)
{
findnumbers(temp);
}
}
}
// function to find number
void findnumbers(int temp) // get tens ones (for seven seg display)
{
int tens = 0; // tens position
int ones = 0; // ones position
output_high(PIN_D0); // lite led to tell me im in findnumbers
if (temp <100> 0)
{
sendhex(tens, 2);
sendhex(ones, 1);
}else{
sendhex(ones, 1);
}
output_low(PIN_D2);
}
|
there was a typo error on my first post.. i change it already to
(temp < 100).. my apologies.. |
|
|
blink Guest
|
Re: dual 7 segment |
Posted: Wed Jan 16, 2008 9:29 pm |
|
|
why is it that i cant post my whole code? its being cut-off.. when i paste my code, everything was there but when i submit it, its being cut-off.. to all the mods, my apologies.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 16, 2008 9:46 pm |
|
|
When you post the code, look for a tickbox just below the posting window.
It looks like this:
Quote: | x Disable HTML in this post |
Make sure it is selected (has a checkmark in the box) before you
click the submit button.
Also, use the Preview button to check the code, to see how it will look,
before you click the Submit button. |
|
|
Guest
|
|
Posted: Thu Jan 17, 2008 12:02 am |
|
|
thanks for your advice..
Code: |
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#device ADC=10
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
// declare functions
void findnumbers(int temp);
void sendhex(int number, int digit);
void displaynumbers(int tens, int ones);
int getavgtemp();
void main() {
float value, value1;
int value3;
int temp;
int i=0;
setup_adc (ADC_CLOCK_INTERNAL);
setup_adc_ports(PIN_A1);
set_adc_channel (1);
set_tris_b(0);
temp = 0;
output_b (0x00);
while(TRUE) {
value = read_adc ();
delay_ms (500);
value1 = ((value * 5) /1023) * 1000;
value3 = value1 - 273.15;
temp = value3;
for(i=0; i<200; i++)
{
findnumbers(temp);
}
}
}
// function to find number
void findnumbers(int temp) // get tens ones (for seven seg display)
{
int tens = 0; // tens position
int ones = 0; // ones position
output_high(PIN_D0); // lite led to tell me im in findnumbers
if (temp < 100) // temp should never be over 100
{
tens = (temp/10)%(10);
ones = (temp%10);
}else{tens, ones = 2;}
displaynumbers(tens,ones);
}
// this converts a number to the desired high/low combination
// for the 7 seg led display
void sendhex(int number, int digit)
{
output_high(PIN_D1);
if (digit == 1){output_low(PIN_E1);
output_high(PIN_E0);}
if (digit == 2){output_low(PIN_E0);
output_high(PIN_E1);}
delay_us(50);
// send hex to port b to make number
if (number == 0){output_b (0xC0);} // output 0 to port b
if (number == 1){output_b (0xF9);} // 1
if (number == 2){output_b (0xA4);}
if (number == 3){output_b (0xB0);}
if (number == 4){output_b (0x99);}
if (number == 5){output_b (0x92);}
if (number == 6){output_b (0x82);}
if (number == 7){output_b (0xF8);}
if (number == 8){output_b (0x80);}
if (number == 9){output_b (0x90);}
delay_us(500);
output_low(PIN_D1);
}
void displaynumbers(int tens, int ones)// send to led
{
int i = 0;
output_high(PIN_D2); // light led to tell me im in this function
// if its more than 100 display eg. 102 else display eg. 67F
if(tens > 0)
{
sendhex(tens, 2);
sendhex(ones, 1);
}else{
sendhex(ones, 1);
}
output_low(PIN_D2);
}
|
this is the whole code.. for those still interested to help, please help.. im still stuck with my problem.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 17, 2008 12:43 am |
|
|
Quote: | setup_adc (ADC_CLOCK_INTERNAL);
setup_adc_ports(PIN_A1); <== Problem
set_adc_channel (1); |
This is not correct. Look in the 16F877.H file to see the constants
that you're allowed to use as a parameter for the setup_adc_ports()
function. Here is the directory where the file is located:
Quote: | c:\Program Files\PICC\Devices\16f877.h |
If you want to use pin A1 as an analog pin, you are forced to also
configure pins A0 and A3 as analog pins. It's a limitation of the PIC
design. Here's the constant from the 16F877.H file.
This is why it's best to choose pin A0, if you only want one analog pin.
It can be setup as the only pin. There is a constant available to do this:
|
|
|
blink Guest
|
Re: dual 7 segment |
Posted: Thu Jan 17, 2008 1:26 am |
|
|
hi.. thanks for the reply but it still doesnt solve the problem... it still displays the digits one at a time.. please help me so that both digits will be displayed in the 2 7 segments at the same time.. |
|
|
Guest
|
Re: dual 7 segment |
Posted: Thu Jan 17, 2008 1:31 am |
|
|
i got it... i just changed the delay from delay_ms(500) to delay_us (500) and it worked.. thanks for all your help... |
|
|
|
|
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
|