Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

7seg temperature display

Status
Not open for further replies.

HanNhuThien

New Member
Hi all, I'm Thien, it's my homework but my code is wrong, please check it out :(

Thank you !

Requirement: 7 seg MPX2 CC temperature display using XC8 , PIC 16F877A, LM 335, IC 74HC595

Here is my code, built successful but on LED was not a number o_O
http://pastebin.com/YW911mJp

Proteus simulation
**broken link removed**
 
Last edited:
Like I said in your OTHER thread!! ADCvalue must be a long...

voltage = ADCvalue *5000 /1023; If ADCvalue was 512 ( half way ) then 512 * 5000 = 2,560,000 an int can only be up to 65,535 this means you number will be negative before you start processing!!!

The other issue is the display has two "select" pins you can only select one at a time 1 or 2 not both!
 
I'm sorry, I missed it

My fixed code here: https://pastebin.com/GuHkwaqe

I did change ADCvalue and f to "long" value and change the select pins code

PORTC = DIGIT[tens];
RD6= 0;
__delay_ms(1);
RD6=1 ;


PORTC = DIGIT[ones];
RD7= 0;
__delay_ms(1);
RD7= 1;


// Result did not change
 
Update #3: I changed " f" back to unsigned int and "value" to unsigned char (value= DIGIT[numero])

// Now it does not work
 
To stop the flickering, I use RC2 to enable the output when It needed.

C:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 1000000
#pragma config FOSC = XT // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
unsigned long volume, value, f, ADCvalue, voltage;
int i, x;
int mask;
const unsigned char DIGIT[10] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
void ADCinit(void){
  ADCS2= ADCS1= 0; ADCS0= 1; //Set Fosc/8
  ADFM= 1; //right justified
  CHS2= CHS1= CHS0= 0; // Choose AN0
  PCFG3= PCFG2= PCFG1= 1; PCFG0= 0;   
}
   
unsigned int atod(void){
  ADON= 1; //A to D on
  GO= 1;
  __delay_ms(1);
  while (GO);
  return (int) ADRESH* 256 + ADRESL; // Dich 8 bit
}
void shift_out(int numero){

   value= DIGIT[numero];
   mask= 1;
   RC3= 0; //Set ST_CP= 0 , open latch
   RC0= 0; // Set SH_CP=0 , enable to write to shift register
   
  for(i=0; i< 7; i++){
  if (value & mask)
  RC1= 1; //DS= 1;
  else  
  RC1=0; //DS= 0;
   
     RC0= 1;
        __delay_us(5);
     RC0= 0; // Next bit
     __delay_us (5);
   
     mask = mask << 1;
  }
  RC3 = 1; // Shift out to Qn gate
   RC2 = 0;   
}
void main (){
  TRISA= 0xff;
   TRISD = 0;
  TRISC= 0x00;
  ADCinit ();
  unsigned int ones,tens=0;
   while(1)
     {
     __delay_ms(1);  
     ADCvalue = atod();
     voltage = ADCvalue *5000 /1023;
     f = voltage / 10 - 273;
     ones= f%10;
     tens= (f/10)%10;
     RC2 = 1;
     RD0 = 0; RD1 = 1;
     shift_out(tens);
     
     __delay_ms(10);
     RC2 = 1;
     RD1 = 0; RD0 = 1;
     shift_out(ones);
     
     __delay_ms(10);
     }
   }

And the circuit!!
upload_2016-3-3_20-37-26.png
 
Thank you so much , much appreciated

It works but there is an error

LM335 -----LED

51 ------------ 51
52 ------------ 52
53 ------------ 53
54 ------------ 53

55 ------------ 54
 
Its fine.... Its just tolerance ( rounding up / down ) 54.9 will display as 54 not 55... To fix this you will need to use floats and then check id the decimal is higher or lower than 0.5 then display the correct value!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top