PDA

View Full Version : newbie question



Lcj100
- 13th January 2009, 17:44
I'm a final year student of BEE course.Currently I'm having problem with my final year project.How to interface temperature sensor lm35 with PIC16f876 to two seven segment display.I would like to get the schematic diagram and the source code about how to display the temperature value in seven segment display.I'm using CCS c compiler for my project........Anyone can help me?I need it urgently!!!!! thanks.

Archangel
- 13th January 2009, 18:53
Hello Lcj100,
Where do I start?
1. This forum is about 99 percent Basic from M E Labs, there are people here who write in C as well.
2. Most here do not do homework or school projects, because we want <b>YOU</b> to learn by doing it yourself.
3. If you want help, post the code you are struggling with, and you may well get HELP, not prewritten code, but help.
4. As for a schematic . . . You as the designer of your project will determine that, because it is your decision as to which port you drive the 7 segment display from, which port you use for inputs etc . . . Unless your professor gave you a P/C board or instructions to use a certain port . . .
Oh, that other 1% . . assembly, embedded into the basic code.

Alektric
- 19th January 2009, 14:46
This is the subroutine for 2 digit 7 segment display that I used to make a similar thing:

DIGIT:
B11 = B10 / 10
B12 = B10 // 10
LookUp B11, ( 119, 36, 107, 109, 60, 93, 95, 100, 127, 124 ), B13
LookUp B12, ( 119, 36, 107, 109, 60, 93, 95, 100, 127, 124 ), B14
Poke PORTC, B13
Poke PORTB, B14
Return

The idea is that the number you want to display is in variable B10 when you call DIGIT. It's then split in two and sent to port c and port b. This means that 7 pins from both port b and port c are used up but it's very simple to wire up and leaves you with RB7 to run the POT command on your thermistor.

I put this in comments:
' ---6
' ¦4 ¦5
' ---3
' ¦1 ¦2
' ---0
to remind me which pin goes to which segment. The numbers in the lookup command are calculated according to which pin is connected to which segment. If you change a pin - segment connection, you will have to calculate new values for the LOOKUP command.

Lcj100
- 2nd February 2009, 04:00
This is the subroutine for 2 digit 7 segment display that I used to make a similar thing:

DIGIT:
B11 = B10 / 10
B12 = B10 // 10
LookUp B11, ( 119, 36, 107, 109, 60, 93, 95, 100, 127, 124 ), B13
LookUp B12, ( 119, 36, 107, 109, 60, 93, 95, 100, 127, 124 ), B14
Poke PORTC, B13
Poke PORTB, B14
Return

The idea is that the number you want to display is in variable B10 when you call DIGIT. It's then split in two and sent to port c and port b. This means that 7 pins from both port b and port c are used up but it's very simple to wire up and leaves you with RB7 to run the POT command on your thermistor.

I put this in comments:
' ---6
' ¦4 ¦5
' ---3
' ¦1 ¦2
' ---0
to remind me which pin goes to which segment. The numbers in the lookup command are calculated according to which pin is connected to which segment. If you change a pin - segment connection, you will have to calculate new values for the LOOKUP command.

Thanks for ur idea.i would like to ask u some question.Can i know what is the meaning of Poke command?Can u show me the example how to calculate the numbers in lookup command?What is the meaning of B12 = B10 // 10?

Archangel
- 2nd February 2009, 04:59
Can u show me the example how to calculate the numbers in lookup command?What is the meaning of B12 = B10 // 10? You have to think binary to figure out the numbers in the lookup table, so here goes . . . take a port to drive displays, I pick PortB
connect the segments to the port, to make it easy on myself, I will select ports in numerical/alphabetical order, so PortB.0 is segment A, PortB.1 is segment b, PortB.2 is segment C . . . . Now to make zero you must illuminate the following segments: abcdef, which means portsB 012345 which translates to %00111111 or decimal 63 or hex 3F. The number 1 would be binary %00000110 or Dec. 6 or Hex 06 and so on and so forth.

mister_e
- 2nd February 2009, 05:05
Can i know what is the meaning of Poke command?
Poke is a PBC statement (still usable in PBP) who write to a specific register.

POKE PORTB, 10

will write 10 to PORTB

In PBP, you may reduce it to
PORTB=0
add a semicolon at the end of the line and it's in C :D

// is the modulus.

PBP performs 16x16 division. The '/' operator returns the 16-bit result. The '//' operator returns the remainder. This is sometimes referred to as the modulus of the number.

Example

W1 = W0 / 1000 ‘ Divide value in W0 by 1000 and place the result in W1
W2 = W0 // 1000 ‘ Divide value in W0 by 1000 and place the remainder in W2

Lcj100
- 2nd March 2009, 04:08
Thanks for ur explanation.This is the program that i write to display the temperature value in seven segment display once LM 35 sense the temperature.As a results from the source code,the seven segment only display the value 16 in seven segment display.Can i know what wrong with this source code?

#include<16f877.h>
#device adc=10
#use delay(clock=10000000)
#fuses hs, noprotect, nowdt, nolvp

#byte porta=5
#byte portb=6
#byte portd=8

int i;
int temp;

void main()
{
set_tris_d(0b00000000);
set_tris_b(0b00000000);
setup_port_a(RA0_analog);
setup_adc(adc_clock_internal);

do
{
set_adc_channel(0);
delay_ms(10);
temp=read_adc()/2;

if (temp=16)
{ portb=0b00000110;
portd=0b01111101; }

else if (temp=17)
{ portb=0b00000110;
portd=0b00000111; }

else if (temp=18)
{ portb=0b00000110;
portd=0b01111111; }

else if (temp=19)
{ portb=0b00000110;
portd=0b01101111; }

else if (temp=20)
{ portb=0b01011011;
portd=0b00111111; }

else if (temp=21)
{ portb=0b01011011;
portd=0b00000110; }

else if (temp=22)
{ portb=0b01011011;
portd=0b01011011; }

else if (temp=23)
{ portb=0b01011011;
portd=0b01001111; }

else if (temp=24)
{ portb=0b01011011;
portd=0b01100110; }

else if (temp=25)
{ portb=0b01011011;
portd=0b01101101; }

else if (temp=26)
{ portb=0b01011011;
portd=0b01111101; }

else if (temp=27)
{ portb=0b01011011;
portd=0b00000111; }

else if (temp=28)
{ portb=0b01011011;
portd=0b01111111; }

else if (temp=29)
{ portb=0b01011011;
portd=0b01101111; }

else if (temp=30)
{ portb=0b01001111;
portd=0b00111111; }

delay_ms(2000);

}while(1);

}

Bruce
- 2nd March 2009, 15:33
CCS has a forum here http://www.ccsinfo.com/forum/ for their C compilers. I think you'll get answers a lot faster if you post your questions there for CCS C code examples....;o}

thcwefh
- 12th October 2009, 09:57
Hi! i'm newbie! I'm trying to learn all in this forum! i'm not good at E. Can you tell me how can i begin to learn about code