Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How displays adc results on 7-segment display

Status
Not open for further replies.

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
16f676 voltmeter

Hi to all.

I have following code:

Code:
float temp;        //Current Temp
int adc_result;   //store read_adc() in 8 bits mode
temp=5*100*adc_result/255.0;  //LM35 output

ANd now, how can i use this float result to display it on 7-segment displays.???

Thank you
 

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
adc 7 segment

WOW man, thank you very much....
 

metal

Full Member level 6
Joined
Dec 21, 2004
Messages
364
Helped
19
Reputation
38
Reaction score
6
Trophy points
1,298
Activity points
3,833
byte to 7 segment

Hi

Hope you post your final results and code.

Thanks
 

Code Warrior

Full Member level 4
Joined
Dec 30, 2004
Messages
230
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
1,831
unsigned char segments

Hello,
Which microcontroller you are using and which C compiler.

Bye
 

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
adc running 7 segment display

Hi

I want use CCS and 16F84...

Thank you
 

xmli1976

Full Member level 1
Joined
Nov 3, 2004
Messages
95
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
829
int_timer1 example

I'm building a weatherglass using lm35 too,but I write codes with asm.

Added after 27 minutes:

if temperature's double digit, just display the first and second most significant decimal digits of result on lcd,and then display a dot ,and display the third number.
If it's single digit,just don't display first digit on lcd.
 

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
7segment display and adc display

On LCD my code is working very well, but the idea is display the Temp on 7-Segment Display.

Thank
 

metal

Full Member level 6
Joined
Dec 21, 2004
Messages
364
Helped
19
Reputation
38
Reaction score
6
Trophy points
1,298
Activity points
3,833
static 7 segments display

Hi

You will find the 7 segment digit code example and ADC calculations in the voltmeter project in the same site I have already posted, its very easy in deed. You can use the temperature code from the 1st project, and the 7 segment digit code in the voltmeter.

Good luck
 

Code Warrior

Full Member level 4
Joined
Dec 30, 2004
Messages
230
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
1,831
float ke display 7 segment

Mr. metal can you please give me link where is your voltmeter project.
 

Code Warrior

Full Member level 4
Joined
Dec 30, 2004
Messages
230
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
1,831
write code 7 segment .asm

Thanks Mr. metal. Nice project. I am also looking 7 segment multiplexing code. I have seen your code do not understand. Can you please explain little bit. It will help me.
 

metal

Full Member level 6
Joined
Dec 21, 2004
Messages
364
Helped
19
Reputation
38
Reaction score
6
Trophy points
1,298
Activity points
3,833
pic adc seven segment display

Code:
// use PIC16F676
#include <16F676.h>
// ADC resolution is 10 bits
#device adc=10
// Define fuses !!
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
// Define clock used for this MCU
#use delay (clock=4000000) // 4MHz clock
// No need for that any way !!
#rom  0x3ff={0x3444}
// Define PIC Ports
#byte PORTA = 0x05
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISC = 0x87
// I don't see it necessary to redifne ports in another  name
#define SPORTA PORTA
#define SPORTC PORTC
// Define some constants for interuupts
#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000
#define  INTERRUPT_OVERHEAD            35
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
// Here the 7 segment decoder values reside
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
	//                       0    1    2    3    4    5    6    7    8    9
// Used to output manipulate digits, one at a time (MUX)
const char Column[3]   = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};	
static unsigned char ColCount=0x00;
// PIC CPU intialization function protoype
void CPU_SETUP(void);
// Display function protoype
void Display(void);
// ADC result manipulation function protoype
void HTO7S(unsigned int32 Num);

byte i;
unsigned int32 result;
// Interrupt handler routine, use timer 1 interrupt
#INT_TIMER1
void Timer1(void)
{
// Set timer 1 to use its interrupt for display 	muxing
set_timer1(TMR1RESET);    
// Display the result on 7 seg digits
Display();	
}	

void main()
{		
	unsigned char i;
Initialize PIC configuration, nice way to do that in deed	
CPU_SETUP();
	
while(true)
{			
result=0;
// Read adc result 20 times using this for loop
for (i=0;i<20;i++)
{
set_adc_channel(3); 
delay_ms(1); 
// finally, the reslt will contain 20 ADC readings
result=result+read_adc();
}
//result = 0x3fe;
// Take the average of the 20 ADC results readings, and 
// use it to manipulate this to be able to display it on 7 digits	
HTO7S(result/20);	
delay_ms(200);		    
}
	
}

void CPU_SETUP()
{
// not use comparator module 	
setup_comparator(NC_NC_NC_NC);
// A3 as analog input, refrences are Vss, and Vdd	
setup_adc_ports( sAN3 | VSS_VDD); 
//Divide the internal clock for use ADC on 64 = 1000000/64
setup_adc(ADC_CLOCK_DIV_64);
TRISA=0b00011000;
PORTA=0x27;
TRISC=0b00000000;
PORTC=0x37;
   
// Use internal clock, prescalar ratio is 1   
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
// Reset timer 1 now
set_timer1(TMR1RESET);
// Set the global interrupt bit in options register
enable_interrupts(GLOBAL);
// enable timer 1 interrupt now
enable_interrupts(INT_TIMER1);   
}

//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
// off all digits column and Segment G
PORTA = 0b00100111;
// off segment a-f		  
PORTC = 0b00111111;   
delay_cycles(2);
	
// for loop could be used here, but it will cause a stack overflow !!
if (ColCount>=3) 
ColCount=0;
// Display corresponding digit    	
SPORTC = Segment[ColCount];
// maniplate digit value in order to put the bits on portc and porta.5
// XOR it with 7, solve this your self, its easy
SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
ColCount++;				
}	

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{

unsigned int32 res;

	
Segment[0]=SegCode[30*Num/10230];
// If first digit is 0, turn it off
if (Segment[0]==0x40) 
Segment[0]=0xFF;
// manipulate the result in order to display it on digits, maths trick, but smart one.
// needs another post in deed for me to explain	
res = 30*Num%10230;
Segment[1]=SegCode[10*res/10230];
res=10*res%10230;
Segment[2]=SegCode[10*res/10230];
}

I have modified this code to use it with common cathod display, instead of common anode one, because this is what I found in my components box. Its wasn't easy at the start, but when I figured out what each line of code does, it becamse easy to make those changes.
 

pvinbox@yahoo.com

Full Member level 2
Joined
May 28, 2004
Messages
125
Helped
8
Reputation
16
Reaction score
2
Trophy points
1,298
Location
Coimbatore, INDIA
Activity points
944
adc 7-segment

hai

if the final result in 3 digit
then u have to do like this
this is the sample program written in pic c
the code don't have any comments sorry
just look it. it is very easy to understand
ad result will be divided as 3 digits then displayed in
seven segment using timer



#include<pic.h>
int i,disp,temp,seg3,seg2,seg1,Result;
char lookup[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void main ()
{
ADCON0=0x89;
ADCON1=0X80;
TRISA=0XFF;
PORTA=0X00;
TMR1IE=1;
TMR1H=0xe9;
TMR1L=0;
TRISD=0X00;
PORTD=0X00;
TRISB=0X00;
PORTB=0X00;
T1CON=0x01;
GIE=1;
PEIE=1;


while(1)
{

delay();
ADGO=1;
while(ADGO);
Result=ADRESH*256+ADRESL;
Result=(int)Result/10.24;
split();
}

}


void interrupt isr()
{

if(TMR1IF)
{
TMR1IF= 0;
TMR1L=0X00;
TMR1H=0xe9;
disp++;




if(disp>2)
disp=0;

if(disp==0)
{
RB3=0;
RB1=1;
PORTD=lookup[seg1];
}
if (disp==1)
{
RB2=1;
RB1=0;
PORTD=lookup[seg2];
}

if (disp==2)
{
RB3=1;
RB2=0;
PORTD=lookup[seg3];
}
}
}

delay()
{
for(i=0;i<30000;i++);
}
split()
{
temp=Result;
seg3=temp/100;
temp=temp%100;
seg2=temp/10;
seg1=temp%10;
}

Added after 1 minutes:

hai

still if u have any doubt
no problem send me a pm
 

xmli1976

Full Member level 1
Joined
Nov 3, 2004
Messages
95
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
829
seven segment using tasm

metal's code style much like asm language.
pvinbox@yahoo.com makes use of advantage of c language.
I have a question about the line of codes:
Result=(int)Result/10.24;
Is Result decimal number of temperature, why it's divided by 10.24?
 

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
7- seg display function

Hi

Parallax haves a code for this project...using /10 and /100....really good......only take the int part of division.....

Parallax Analog to Digital....

Thank you very much

Bye
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,471
adc to seven segment display

xmli1976 said:
Is Result decimal number of temperature, why it's divided by 10.24?

Hi xmli1976,

Do you want a sample of kick and run ?

pvinbox@yahoo.com said:
the code don't have any comments sorry

He just pass after 23 jan 2006 but seems didn't bother and treat you disdainfully rather than answer kindly as metal did as requested by

Code Warrior said:
Can you please explain little bit

I think you should send an PM to pvinbox@yahoo.com

pvinbox@yahoo.com said:
still if u have any doubt
no problem send me a pm

And will be no problem for him to answer you in private with silence.....
Don't be astonished by pvinbox@yahoo.com code that makes use of advantage of C language contrary to metal's code style much like asm language.

It's look to me contrary with all those statements:
RB3=0;
RB1=1;
RB2=1;
RB1=0;

Look inside metal's code (in fact it's not his code, he just mentioned a link, then kindly commented out as requested)
you can find this:
Code:
// ADC resolution is 10 bits 
#device adc=10 
A3 as analog input, refrences are Vss, and Vdd

Have you seen this kind of statements in pvinbox@yahoo.com code ? Should I guess if he's running PIC ADC in 8 bits or 10 bits ? Why metal answer to Code Warrior request for comments. Because is another kind of man. No comments further.

Go to https://www.winpicprog.co.uk/pic_tutorial11.htm and read the paragraph immediately bellow of table with "Bits required in ADCON1" in the middle of the web page.

Bear in mind that LM35 and has a scale factor of linear + 10.0 mV/°C
 

xmli1976

Full Member level 1
Joined
Nov 3, 2004
Messages
95
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
829
integer 7 segment ccs

I just want to say that codes that metal post is like the codes i write in asm.

to silvio:
Are you Chinese?You speak English like Chinese.
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,471
adc 7 segment ccs

No I'm not. It's easy to figure out that english it's not my native language.
I don't mind at all if you can send me a PM with the correct grammar and spelling of my words.
Really I don't mind. I'm allways eager to learn from my mistakes.

Once, a genuine english guy told me that the most important thing is even if I don't speak like him, at least I can communicate and change opinions.

Chinese do the same thing. Even more, when they talk close to me I feel like that genuine english guy when I talk with my wife in my native language.
 

terka

Advanced Member level 4
Joined
Dec 15, 2003
Messages
100
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
936
seg disp code for asm language

Hi....well.....uffff...i have already mi code working...

I have connected a LM35DZ (0° to 100°C) to AN0...formula to °C=Vref*Full_Scale*read_adc()/(2^n-1), where n=8 bits....A LM358 multiplied LM35 output by 2, to obtain 20mv/°C..according to 8 bit ADC resolution...

°C=5*100*read_adc()/255= 500*read_adc()/255

To Drive decimal point, connect PORTC.1 by resitor to DP of displays...

Enjoy

Code:
#include <16f877a.h>

//#device *=16
#device adc=8
#FUSES NOWDT                 	//No Watch Dog Timer
#FUSES XT                    	//Crystal osc <= 4mhz
#FUSES PUT                   	//Power Up Timer
#FUSES NOPROTECT             	//Code not protected from reading
#FUSES NODEBUG               	//No Debug mode for ICD
#FUSES BROWNOUT              	//Reset when brownout detected
#FUSES NOLVP                 	//No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                 	//No EE protection
#FUSES NOWRT                 	//Program memory not write protected
#use delay(clock=4000000,RESTART_WDT)

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000
#define  INTERRUPT_OVERHEAD            35
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

#byte PORTB = 0x06    //it have conneted all 7 segment displays
#byte PORTC = 0x07    //it have connected all BC557 display driver
#byte TRISB = 0x86
#byte TRISC = 0x87

//// CA display
//// segment activates on LOW state of pins..

const char SegCode[11] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xFF};

//                          0    1    2    3    4    5    6    7    8    9   OFF


const  char Column [3] = {0x06,0x05,0x03};     //0x06 MS digit
static char Segment[3] = {0x7f,0x7f,0x7f};     //Start value for all segmenta, OFF
static unsigned char  ColCount=0x00;

void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num);

byte i;
unsigned int32 result;

#INT_TIMER1
void Timer1(void)
{
	set_timer1(TMR1RESET);
	Display();
}

void CPU_SETUP()
{
   setup_spi(FALSE);
   setup_psp(PSP_DISABLED);
   setup_vref(FALSE);
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_64);
   setup_comparator(NC_NC_NC_NC);	// not use comparator module
     
   TRISC=0x00;    //PortC as OUTPUT
   PORTC=0x07;   //All BC557in OFF. LOW is active
   TRISB=0x00;    //PortB as OUTPUT
   PORTB=0xFF;    //All segment in OFF state


   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   set_timer1(TMR1RESET);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER1);
}

//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
	PORTC=0x07;            //BC557 OFF. 	
   PORTB=0xFF;            //All segment OFF
	delay_cycles(2);


	if (ColCount>=3)
	ColCount=0;

	PORTB = Segment[ColCount];
	PORTC = Column[ColCount];
	ColCount++;
}

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{

	unsigned int32 res;                   

	Segment[0]=SegCode[500*Num/2550];  // V=(Vref*read_adc())/(255*10)
   if (Segment[0]==0x40)                  	
   Segment[0]=0xFF;
   res = 500*Num%2550;                    // V=(Vref*read_adc())%(255*10) 
                                          

	Segment[1]=SegCode[10*res/2550];       // res/255. 
	res=10*res%2550;                       // res%255. 
	Segment[2]=SegCode[10*res/2550];       //  res/255
   
   
                                          
}

void main()
{
	unsigned char i;

	CPU_SETUP();

	while(true)                     // reading LM35DZ output
	{
		result=0;
		for (i=0;i<100;i++)
		{
			set_adc_channel(0);        //LM35DZ connected to AN0
			delay_ms(1);
			result=result+read_adc();  		
}
                             //divide by 100 as average value
		//result = 0x3fe;          //
	 	HTO7S(result/100);             //Convert result/100 to 7 segments
      delay_ms(200);
	}

}


Thankz to all..

Bye
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top