13 Jan 2009 @ 5:51 PM 

There were requests for a picture … this was all i could find, it gives you a idea how the display might have been hooked up

3 digit 7 seg display

3 digit 7 seg display

This was for our intro to engineering project It is a thermometer with a lm34 connected to ra0. It multiplexed 3 “7Segment” led displays connected to the ports, i think the digit was port E and the 7 led’s of the “7Segment” displays were connected to B. You can easily use it on a 877a also if you include the .h for the 877a . I will try and post the schematic but it was all pretty much done on the fly, a schematic was only made for half of it.
It has a lot of functions to do stupid stuff, you dont need them. Any questions post a reply. I would not use this code because i doubt you will have the same setup but it would be a great reference.

/******************************************************************************
/ Program for a pic 16F877 to take analoge input from RA0 in the range
/ of 0- ? volts and display it to a three digit 7 segment Led display. The
/ display is multiplexed and the common cathode/anode is controlled by
/ port E and the actual hex of the number is sent through port B
/
/ by, Michael
/ 10-3-07
/ www.zonemikel.com
/*****************************************************************************/

#include "877.h"
#include <stdio.h>
#include <stdlib.h>

// declare functions
void findnumbers(float temp, int choice);
void sendhex(int number, int digit);
void displaynumbers(int hundreds, int tens, int ones);
int getavgtemp();
void demo(int k);
void showled(float temp, int choice);
void blink();

void main()
{
int i = 0;
int choice = 0; // current menu choice
int16 adc_value; // adc read from AN0 0-1023
float volts; // volts 0-5v
float total = 0; // total for average
float temp = 0; // chop off the .xx
float tempC = 0; // temp in celcius
int scroll[19] = {16,16,16,5,15,14,12,17,16,14,1,11,16,1,0,0,0,0,16};
int k =0;
int n=0;

// tell them what i am
for(k=0;k<20;k++)
{
if (!input(PIN_C1) || !input(PIN_C1)) // did they hit a button ?
{break;} // if so get out of here !
for(i=0; i<200; i++){
for(n=0; n<5; n++)
{
sendhex(scroll[k],1);
sendhex(scroll[(k-1)],2);
sendhex(scroll[(k-2)],3);
}// end for n
}// end for i
}

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);

while(1)
{

if (!input(PIN_C1))
{
choice++;
while(!input(PIN_C1)) // let us see we are piking cX menu choice
{displaynumbers(11, 0, choice);}
output_e (0x00); // turn off digit of 7 seg display if not it continues
// to display the last digit of whatever u had b4
}
if (!input(PIN_C3))
{
choice--;
while(!input(PIN_C3)) // let us see we are piking cX menu choice
{displaynumbers(11, 0, choice);}
output_e (0x00); // turn off digit of 7 seg display if not it continues
// to display the last digit of whatever u had b4
}

switch(choice)
{
case 0:
// get the average and store it in var temp in F
total = 0;
for (i=0; i<20; i++)
{

findnumbers(temp, choice);
adc_value = read_adc();
volts = (float)(adc_value * 4.8)/1023.0;
//delay_us(100);
total += volts;
}

temp = ((total/20)*100);
showled(temp,choice); // turn on color led for hot/med/cold/freezing
// display temp on 3 digit 7seg led, turn on light to do with temp
for (i=0; i<50; i++)
{if (!input(PIN_C1) || !input(PIN_C3))
{break;}
findnumbers(temp, choice);}

break;

case 1:
// get the average and store it in var temp in C
total = 0;
for (i=0; i<20; i++)
{
findnumbers(tempC,choice);
adc_value = read_adc();
volts = (float)(adc_value * 4.8)/1023.0;
//delay_us(100);
total += volts;
}

tempC = ((((total/20)*100)-32)/1.8);
// display temp on 3 digit 7seg led, turn on light to do with temp
showled(tempC,choice); // turn on color led for hot/med/cold/freezing
// display temp on 3 digit 7seg led, turn on light to do with temp
for (i=0; i<50; i++)
{if (!input(PIN_C1) || !input(PIN_C3))
{break;}
findnumbers(tempC, choice);}
break;

case 2:
// send information to serial (uart) for commuication with other device
for (i=0; i<3; i++)
{
if (!input(PIN_C1) || !input(PIN_C1)) // did they hit a button ?
{break;} // if so get out of here !
if (i == 2){output_high(PIN_E0);}
if (i == 1){output_high(PIN_E1);}
if (i == 0){output_high(PIN_E2);}
delay_ms(100);
output_b (0b1000000);
delay_ms(100);
output_b (0b0100000);
delay_ms(100);
output_b (0b0010000);
delay_ms(100);
output_b (0b0001000);
delay_ms(100);
output_b (0b0000100);
delay_ms(100);
output_b (0b0000010);
delay_ms(100);
output_b (0b0000001);
delay_ms(100);
}
total = 0;
for (i=0; i<20; i++)
{
adc_value = read_adc();
volts = (float)(adc_value * 4.8)/1023.0;
//delay_us(100);
total += volts;
}

temp = ((total/20)*100);
delay_ms(200);
printf("\f ADC0: %f temp: %f total: %f i: %i", volts, temp, total, i);
delay_ms(200);
break;

case 3:
// a colorful placeholder thing, flashes lights and counts
demo(5);
break;

case 4:
// something to display on the seven seg display
// super pic 1000 is displayed

for(k=0;k<20;k++)
{
if (!input(PIN_C1) || !input(PIN_C1)) // did they hit a button ?
{break;} // if so get out of here !
for(i=0; i<100; i++){
for(n=0; n<5; n++)
{
sendhex(scroll[k],1);
sendhex(scroll[(k-1)],2);
sendhex(scroll[(k-2)],3);
}// end for n
}// end for i
}// end for k

break;

case 5:
blink();
break;

default: // out of bounds set to 0 (zero) again
choice = 0;
break;
}
}// end of while(1)
}// end of main

// blinks led of temp range
void showled(float temp, int choice)
{
if (choice == 1){temp = (((temp*9)/5)+32);}
output_d (0x00); // all off

if (temp > 0 && temp < 50)
{
output_high(PIN_D0);
}
if (temp > 50 && temp < 70)
{
output_high(PIN_D1);
}
if (temp > 70 && temp < 90)
{
output_high(PIN_D2);
}
if (temp > 90)
{
output_high(PIN_D3);
}
}
// function to find number
void findnumbers(float temp, int choice) // get hundreds tens ones (for seven seg display)
{

int inttemp = 0; // temp with decimal removed
int hundreds = 0; // hundreds position
int tens = 0; // tens position
int ones = 0; // ones position
int ForC; // f or c temp
if (choice == 0){ForC = 13;}
if (choice == 1){ForC = 11;}
if (choice == 3){ForC = 16;} // dont do this print nothing
if (temp < 100)
{
inttemp = temp;

hundreds = (inttemp/100)%(10);
tens = (inttemp/10)%(10);
ones = (inttemp%10);
displaynumbers(tens, ones, ForC);
}

if (temp > 100)
{
inttemp = temp;

hundreds = (inttemp/100)%(10);
tens = (inttemp/10)%(10);
ones = (inttemp%10);
displaynumbers(hundreds, tens, ones);
}
if (temp > 255)
{
displaynumbers(12, 0, 1);
}

}

// this converts a number to the desired high/low combination
// for the 7 seg led display
void sendhex(int number, int digit)
{
//dot 	g 	f 	e 	d 	c 	b 	a
// 0 	0 	0 	1 	1 	1 	1 	1 	1 	3F
output_e (0x00);
// send hex to port b to make number
if (number == 0){output_b (0x3F);} // output 0 to port b 11000000
if (number == 1){output_b (0x6);} // 1 11111001
if (number == 2){output_b (0x5B);} // 2 10100100
if (number == 3){output_b (0x4F);} // 3
if (number == 4){output_b (0x66);}
if (number == 5){output_b (0x6D);}
if (number == 6){output_b (0x7D);}
if (number == 7){output_b (0x07);}
if (number == 8){output_b (0x7F);}
if (number == 9){output_b (0x67);}
// all these need to be fixed for common cathode
if (number == 10){output_b (0x88);} // A
if (number == 11){output_b (0x39);} // C // cathode 11000110 00111001
if (number == 12){output_b (0xF9);} // E // for cathode   11111001
if (number == 13){output_b (0x71);} // F // 10001110 01110001
if (number == 14){output_b (0x73);} // P // 10001100 01110011
if (number == 15){output_b (0x3E);} // U // 01111110 00111110
if (number == 16){output_b (0x0);} // nothing at all
if (number == 17){output_b (0x50);} // lower case r  01010000

//turn on the digit(send high to common cathode via transistor)
if (digit == 3){output_high(PIN_E0);}
if (digit == 2){output_high(PIN_E1);}
if (digit == 1){output_high(PIN_E2);}
delay_us(100);

}

// this just sends the right number to the right digit if its less than
// 100 it will use the extra digit to display a F eg. 45F
void displaynumbers(int hundreds, int tens, int ones)// send to led
{
int i = 0;

// if its more than 100 display eg. 102 else display eg. 67F
if(hundreds >= 0) // always do this loop when u dont want F
{
for(i=0; i<200; i++)
{
sendhex(hundreds, 3);
sendhex(tens, 2);
sendhex(ones, 1);
}
}else{
for(i=0; i<200; i++)
{
sendhex(tens, 3);
sendhex(ones, 2);
sendhex(12, 1); // 12 is F
}
}
}
void demo(int k) // do neat stuff
{
int i = 0;

for (i = 0; i < 255; i++)
{
if (!input(PIN_C1) || !input(PIN_C3)) // did they hit a button ?
{break;}
output_high(PIN_D0);
delay_ms((k*i)/200);
output_low(PIN_D0);
//findnumbers(k); // k is normally unchanging.
output_high(PIN_D1);
findnumbers(i,3);
delay_ms((k*i)/100);
output_low(PIN_D1);
//
output_high(PIN_D2);
//findnumbers(i);
delay_ms((k*i)/200);
output_low(PIN_D2);
//
output_high(PIN_D3);
//findnumbers(i);
delay_ms((k*i)/100);
output_low(PIN_D3);

delay_ms((k*i)/100);
// reverse

output_high(PIN_D3);
//findnumbers(i);
delay_ms((k*i)/200);
output_low(PIN_D3);
//
output_high(PIN_D2);
//findnumbers(i);
delay_ms((k*i)/100);
output_low(PIN_D2);
//
output_high(PIN_D1);
//findnumbers(i);
delay_ms((k*i)/200);
output_low(PIN_D1);
//
output_high(PIN_D0);
//findnumbers(i);
delay_ms((k*i)/100);
output_low(PIN_D0);
}
}

void blink()
{
int i = 0;
while(1)
{
if (!input(PIN_C1)) // get out if they hit button one
{break;}

if (!input(PIN_C3)) // if they hit button two incrament i
{i++;}
findnumbers(i,3);
// lights high
output_high(PIN_D3);
output_high(PIN_D2);
output_high(PIN_D1);
output_high(PIN_D0);
delay_ms(i);
output_low(PIN_D2);
output_low(PIN_D1);
output_low(PIN_D0);
output_low(PIN_D3);
delay_ms(i);

}
}

/* table so i dont have to calculate again !!!
For common Cathode :

Hex Number

Seven Segment conversion

Seven Segment equivalent
dot 	g 	f 	e 	d 	c 	b 	a
0 	0 	0 	1 	1 	1 	1 	1 	1 	3F
1 	0 	0 	0 	0 	0 	1 	1 	0 	06
2 	0 	1 	0 	1 	1 	0 	1 	1 	5B
3 	0 	1 	0 	0 	1 	1 	1 	1 	4F
4 	0 	1 	1 	0 	0 	1 	1 	0 	66
5 	0 	1 	1 	0 	1 	1 	0 	1 	6D
6 	0 	1 	1 	1 	1 	1 	0 	1 	7D
7 	0 	0 	0 	0 	0 	1 	1 	1 	07
8 	0 	1 	1 	1 	1 	1 	1 	1 	7F
9 	0 	1 	1 	0 	0 	1 	1 	1 	67

For common Anode :

Hex Number

Seven Segment conversion

Seven Segment equivalent
dot 	g 	f 	e 	d 	c 	b 	a
0 	1 	1 	0 	0 	0 	0 	0 	0 	C0
1 	1 	1 	1 	1 	1 	0 	0 	1 	F9
2 	1 	0 	1 	0 	0 	1 	0 	0 	A4
3 	1 	0 	1 	1 	0 	0 	0 	0 	B0
4 	1 	0 	0 	1 	1 	0 	0 	1 	99
5 	1 	0 	0 	1 	0 	0 	1 	0 	92
6 	1 	0 	0 	0 	0 	0 	1 	0 	82
7 	1 	1 	1 	1 	1 	0 	0 	0 	F8
8 	1 	0 	0 	0 	0 	0 	0 	0 	80
9 	1 	0 	0 	1 	1 	0 	0 	0 	98
*/
Posted By: Michael
Last Edit: 07 Nov 2009 @ 10:07 PM

EmailPermalink
Tags
Categories: Uncategorized


 

Responses to this post » (8 Total)

 
  1. am0r says:

    can i have a copy of the schematic diagram of this code?

    thank you….=)

  2. am0r says:

    can i have a copy of the schematic diagram of this code?

    what are the other components needed on this project?

    thank y0u…=)

  3. admin says:

    there is no diagram or flowchart sorry

  4. Hey man, I was just browsing through your website and wanted to add your RSS feed, however it isn’t working with my webbrowser (I am viewing it with Opera) any possible way to fix this?

  5. bizz_box says:

    other specifications??
    how it works?
    parts order information?

    thanks.

  6. bizz_box says:

    any other information?
    features?
    how it works?

    thanks.

  7. admin says:

    not sure about that … im swamped with work right now

  8. admin says:

    um .. it was a ‘877 some transistors for the driving of the common on the 7segs … and something to read the temperature lm?? also the basic pic circuitry. Sorry its not really a full article i no longer have the device (teacher does)

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Change Theme...
  • Users » 5
  • Posts/Pages » 71
  • Comments » 62
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Contact Me



    No Child Pages.

Front



    No Child Pages.