CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Programming problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Lcj100



Joined: 29 Nov 2008
Posts: 3

View user's profile Send private message

Programming problem
PostPosted: Mon Mar 02, 2009 10:34 am     Reply with quote

I'm a final year student of BEE engineering. I'm having problems with my C programming. My purpose of this source code is to display the temperature in seven segment display once the temperature sensor LM35 detect the room temperature. I'm using CCS C compiler. Anyone familiar with this compiler? As a results when i burn this source code into PIC16f877. The seven segment will only display number 16 in seven segment display. Can i know what's wrong with this source code?

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);

}

Smile
Ttelmah
Guest







PostPosted: Mon Mar 02, 2009 11:16 am     Reply with quote

Start, by telling us how the 7segment is wired. At present, we can't tell what route the code is taking, since we don't know what pattern on D, gives '16'...

Correct some obvious errors:
Read the data sheet. Work out why you should not use ADC_CLOCK_INTERNAL.

What is the C command for _testing_equality, rather than setting a value. Are you using this?.

The last one is probably what is causing the problem.....


Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 02, 2009 11:34 am     Reply with quote

Quote:
if (temp=16)

Look at this page about common beginner problems in C:
http://drpaulcarter.com/cs/common-c-errors.php


Quote:
int temp;

In CCS, an 'int' is an 8-bit unsigned variable. For a 16-bit unsigned
variable, declare it as 'int16'.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Mar 03, 2009 3:12 am     Reply with quote

You could improve the code no end by storing those bit patterns in an array.

something like

Code:

int const num[10] = {
  0b00111111,   // 0
  0b00000110,   // 1
  0b01001111,   // 3
  0b01011011,   // 2
  0b01100110,   // 4
  0b01101101,   // 5
  0b01111101,   // 6
  0b00000111,   // 7
  0b01111111,   // 8
  0b01101111}; // 9

portb = num[temp / 10];
portd = num[temp % 10];
Lcj100



Joined: 29 Nov 2008
Posts: 3

View user's profile Send private message

PostPosted: Tue Mar 03, 2009 1:40 pm     Reply with quote

Ttelmah wrote:
Start, by telling us how the 7segment is wired. At present, we can't tell what route the code is taking, since we don't know what pattern on D, gives '16'...

Correct some obvious errors:
Read the data sheet. Work out why you should not use ADC_CLOCK_INTERNAL.

What is the C command for _testing_equality, rather than setting a value. Are you using this?.

The last one is probably what is causing the problem.....


Best Wishes


I'm using two seven segments display. One of the seven segment will be connected to port b0-b6 along with 390 ohm resistor for each port. The other seven segment will be connected to port d0-d6 along with 390 ohm resistor for each port. Both of the seven segments common cathode pin will be grounded. If i want to display 16 in seven segment. The port b pattern will display "1" which is 00000110 means b7b6b5b4b3b2b1b0 while the port d will display "6" which is 01111101 means d7d6d5d4d3d2d1d0. Can i know what do u mean by testing equality in this case?
Guest








PostPosted: Tue Mar 03, 2009 2:03 pm     Reply with quote

oh, good grief Sad How can you possibly be a "final year student"??

You need to do this:

Code:

if (temp==16)


Instead of this:

Code:

if (temp=16)


Part of being an engineer is NOT expecting to be spoon fed everything....

The CodeWarrior
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group