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

comparison of char variable and if How to use

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



Joined: 05 Sep 2011
Posts: 8

View user's profile Send private message Send e-mail

comparison of char variable and if How to use
PostPosted: Sun Sep 25, 2011 3:59 am     Reply with quote

i have array char variable

Code:
char Code[]{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};


suppose
i want stop program at Code[4]
How to use if for char variable because do not int variable

if(Code[]=4)
{stop program}

if(Code=4)
{stop program}



ู^
^
^
ERROR all What have any way

if(??????????)
{stop program}

Crying or Very sad Crying or Very sad Crying or Very sad Crying or Very sad
I did not expert C language and english language
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 25, 2011 5:20 am     Reply with quote

CCS kindly provides a folder FULL of great examples of programming their C compiler as well as a huge onscreen help file(press F11 to open).
It sounds like you need a 'C programming for dummies' book. I have one though not a huge help in programming on a PIC. There are several books on the subject though I've never bought any as just push F11 when needed.
What you need to know is there and you can always 'google' for more
help. I do understand the language problem as I have used some 27 different computer languages in the 30+ years of doing this.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Sep 25, 2011 8:05 am     Reply with quote

You don't need to be an "expert" but you do need to know the
fundamentals of C programming. Unfortunately, this forum is not here to
teach C programming, you will need to learn that elsewhere.

To get you started, below are a few pointers.

First , to use an array you must learn how to address the elements. In
your example what element of the Code array are you trying to address?
Code:
if(Code[]=4)
{stop program}

Second you need to learn the difference between assignment and
comparison. Do some research on the difference between one (=) and two
(==) equals signs.

How array comparisons should look:
if (Code[0]==0x3f) (also, remember array numbering starts at zero not 1)

Third, keep in mind when comparing a value, it must precisely MATCH
what is desired:
(examples: 0x66 is NOT the same as 66, '7' is NOT the same as 7).

Fourth, you need to learn how to structure an array definition:
Code[]{0x11,0x12,0x13 etc } is NOT correct. (Read the C and CCS manuals)
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 25, 2011 4:40 pm     Reply with quote

The basic thing is we don't want to teach C on this forum. You're
expected to learn the C language outside the forum.


Here are tutorials on the CCS compiler:
http://harfordhackerspace.org/2010/02/programming-pic-microcontrollers-in-c/

http://www.swarthmore.edu/NatSci/echeeve1/Ref/C%20for%20PIC/C_Intro.html

------------------------
Here is a tutorial on pointers and arrays:
http://home.netcom.com/~tjensen/ptr/pointers.htm

------------------------
Here are tutorials on the C language:
http://www.learn-c.com/
http://phy.ntnu.edu.tw/~cchen/ctutor.pdf
http://publications.gbdirect.co.uk/c_book/
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html

------------------------
Tutorials about using PIC hardware:

Microchip tutorial on the PIC ADC:
http://ww1.microchip.com/downloads/en/devicedoc/adc.pdf

ADC setup for CCS:
http://seng.ulster.ac.uk/eme/sidk/eee305/Miniproject/ADC%20port%20CCS%20compiler.pdf

Timer2 tutorial:
http://www.microcontrollerboard.com/pic-timer2-tutorial.html

Newguy's timer tutorial:
http://www.ccsinfo.com/forum/viewtopic.php?t=22467

Microchip -- Timers Tutorial
http://ww1.microchip.com/downloads/en/DeviceDoc/51682A.pdf

Microchip -- Timers: Timer0 Tutorial (Part 2)
http://ww1.microchip.com/downloads/en/DeviceDoc/51702A.pdf


I'm sure there are many more on the net.
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