Continue to Site

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.

seven segment display problem

Status
Not open for further replies.

mariuszoll

Member level 5
Member level 5
Joined
Aug 28, 2012
Messages
82
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
2,147
Hi,

I have to implement a thermometer. I use on my project a PIC18F2620, a LM35, and the temperature is displayed on 3 seven segment display. In order to have a stable display, I use the Timer0, and I read the value of temperature at each 1 sec. The problem is the fact that there is nothing displayed.
Please find attached my C code:
#include <p18f2620.h>
#include <delays.h>
#include <adc.h>

/*****Configuration of internal registers*****/
#pragma config WDT = OFF // watch dog disabled
#pragma config OSC = INTIO67
#pragma config IESO = OFF //Oscillator Switchover mode disabled
#pragma config XINST = OFF
#pragma config BOREN = OFF //Brown-out Reset disabled in hardware and software
#pragma config PBADEN=OFF //PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config STVREN=OFF //Stack full/underflow will not cause Reset
#pragma config LVP=OFF //Single-Supply ICSP disabled

/******definition of variables*****/
unsigned int i=0,n,u=0,d=0,f=0,k=0;
unsigned int dig[3];
float quanta=0.0,val=0.0, val1=0.0,tempinC=0.0, j=0.0;

/*****Local Functions*****/

void init(void)
{
// outputs
TRISC=0; //port C configured as output
TRISBbits.TRISB0=0;
TRISBbits.TRISB1=0;
TRISBbits.TRISB2=0;
TRISBbits.TRISB3=0;
TRISBbits.TRISB4=0;
TRISBbits.TRISB5=0;
TRISAbits.TRISA1=0;

//inputs

TRISAbits.TRISA0=1; // input from senzor

// ADC setings

// Config the required ADC pins as analog pins (AN0)
ADCON1bits.PCFG3=1;
ADCON1bits.PCFG2=1;
ADCON1bits.PCFG1=1;
ADCON1bits.PCFG0=0;

// Set the voltage reference
ADCON1bits.VCFG1=0; // Vref- = Vss
ADCON1bits.VCFG0=1; // Vref+ = AN3

// Select ADC input channel (AN0)
ADCON0bits.CHS3=0;
ADCON0bits.CHS2=0;
ADCON0bits.CHS1=0;
ADCON0bits.CHS0=0;

// Select A/D aquisition time (2Tad)
ADCON2bits.ACQT2=0;
ADCON2bits.ACQT1=0;
ADCON2bits.ACQT0=1;

// Select A/D conversion clock ( Fosc/4)
ADCON2bits.ADCS2=1;
ADCON2bits.ADCS1=0;
ADCON2bits.ADCS0=0;

//Select result format right justified

ADCON2bits.ADFM = 1;

//turn on A/D module
ADCON0bits.ADON=1;

// Oscillator config

OSCCON=0b01100111;

// Timer0 configuration

T0CONbits.T0PS0=1; // TMR0 prescaler=256
T0CONbits.T0PS1=1;
T0CONbits.T0PS2=1;
T0CONbits.PSA=0; // TMR0 assignement
T0CONbits.T0CS=0; // Fosc/4
T0CONbits.T08BIT=1; // 8 bit

INTCONbits.TMR0IE=1; // Enable TMR0 interrupt
INTCONbits.PEIE=1; // Enable peripheral interrupt
INTCONbits.GIE=1; // Enable INTs globally

T0CONbits.TMR0ON=1;

// Port Initialisation
LATC=0xFF;
LATBbits.LATB0=1;
LATBbits.LATB1=1;
LATBbits.LATB2=1;
LATBbits.LATB3=1;
LATBbits.LATB4=1;
LATBbits.LATB5=1;
}

//Functions

//7 Segment Display Function
void Seven_Segment (unsigned int n)
{
switch(n)
{
case 0:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=0;
LATCbits.LATC5=0;
LATCbits.LATC6=1;
LATCbits.LATC7=1;
break;
case 1:
LATCbits.LATC0=1;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=1;
LATCbits.LATC4=1;
LATCbits.LATC5=1;
LATCbits.LATC6=1;
LATCbits.LATC7=1;
break;
case 2:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=1;
LATCbits.LATC3=0;
LATCbits.LATC4=0;
LATCbits.LATC5=1;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 3:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=1;
LATCbits.LATC5=1;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 4:
LATCbits.LATC0=1;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=1;
LATCbits.LATC4=1;
LATCbits.LATC5=0;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 5:
LATCbits.LATC0=0;
LATCbits.LATC1=1;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=1;
LATCbits.LATC5=0;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 6:
LATCbits.LATC0=0;
LATCbits.LATC1=1;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=0;
LATCbits.LATC5=0;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 7:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=1;
LATCbits.LATC4=1;
LATCbits.LATC5=1;
LATCbits.LATC6=1;
LATCbits.LATC7=1;
break;
case 8:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=0;
LATCbits.LATC5=0;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
case 9:
LATCbits.LATC0=0;
LATCbits.LATC1=0;
LATCbits.LATC2=0;
LATCbits.LATC3=0;
LATCbits.LATC4=1;
LATCbits.LATC5=0;
LATCbits.LATC6=0;
LATCbits.LATC7=1;
break;
}
}

void DisplayTemp(void)
{
//decimals
LATCbits.LATC7=1;
LATBbits.LATB3=0;
LATBbits.LATB4=1;
LATBbits.LATB5=1;
Seven_Segment(d);
Delay100TCYx(70);

//units
LATCbits.LATC7=0;
LATBbits.LATB3=1;
LATBbits.LATB4=0;
LATBbits.LATB5=1;
Seven_Segment(u);
Delay10TCYx(5);

//fractions
LATCbits.LATC7=1;
Delay1KTCYx(10);
LATBbits.LATB3=1;
LATBbits.LATB4=1;
LATBbits.LATB5=0;
Seven_Segment(f);
Delay10TCYx(5);
}


/***** main ******/
void main(void)
{
init();
LATBbits.LATB0=0; //C
LATBbits.LATB1=0; //C
LATBbits.LATB2=0; //C
k=0;

while(1)
{
val=0.0;

/* for(i=0; i<10; i++)
{
ConvertADC();
while(BusyADC());
val=val+ReadADC();
}

val1=val/10;
quanta=1023/1.22;
tempinC=(val1*100/quanta)-10-2;
n=(int)tempinC;
u=n%10;
n=n/10;
d=n;
j=(tempinC-n)*10;
f=(int)j;

DisplayTemp(); */

if(INTCONbits.TMR0IE && INTCONbits.TMR0IF)
{
k++;
if(k==15) // temperature dispalyed at each 1sec
{
for(i=0; i<10; i++)
{
ConvertADC();
while(BusyADC());
val=val+ReadADC();
}

val1=val/10;
quanta=1023/1.22;
tempinC=(val1*100/quanta)-10;
n=(int)tempinC;
u=n%10;
n=n/10;
d=n;
j=(tempinC-n)*10;
f=(int)j;
DisplayTemp();
// k=0;
}
INTCONbits.TMR0IF=0;
k=0;
}
}
}

Thank you in advance.
 

why you are using LAT register ?? Try to use PORT register
 
I use MPLAB,and the compiller MCC18. I use the internal oscilator, and its frequency is 4Mhz.
 

Here it is the schematic, and the C file.

- - - Updated - - -

Here is the zip with the schematic and the C file.
 

Attachments

  • thermometer.zip
    27.3 KB · Views: 84

There is no interrupt service routine code. I am also getting stack overflow error. Anyways the code is working. I simulated in proteus by assigning some dummy values to d, u, and f. The SSD works but because you don't have ISR so it is not working. Also try to reduce nested functions in your code to eliminate stack overflow error.
 
Last edited:

would you like to help me please with an ISR?
 

This is not fully working. If you want full scale of LM35 then you need to use > 1.5V as Vref+ for ADC as max value LM35 can give is 1.5V. I will fix the code later and post.
 

Attachments

  • SSD LM35.rar
    37.2 KB · Views: 83

i would like suggest for led driver IC which CD4511. for that ic u will save your pin count and also it will easy to send data to seven segment and no driver is needed in between instead this IC work as driver also and decode of you input to output to your seven segment.
i thimk it will easy to use and will solve your problem.
just take a look.

Regards.
 

Your adc is not working. All the time it is displaying 0. If you want I can provide mikroC PRO PIC code.

I am attaching mikroC code which is working. I am also attaching MPLAB Code but it is not working. Debug and fix it.
 

Attachments

  • SSD PIC18F2620 rev1.rar
    69.1 KB · Views: 87
  • SSD LM35 MPLAB C18.rar
    38.1 KB · Views: 84
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top