## Sunday, April 3, 2011

### 【School】 SCM weak c language tutorial --- Lesson: operators and expressions (2)】.

<br> relational operators <BR> for the relational operators, as we are no stranger. .There are six C relational operators, these guys are also learning in a child when learning arithmetic had: <BR>> than <BR> <less <BR>> = greater than or equal <BR> <= less than or equal .<BR> == equal <BR>! .= Equal to <BR> or you are non-C programmer, then the first four must be familiar and simple. .The "==" or PASCAL, etc. in VB is used "=","!=" is used "not". .Because of my job I'm going to use several programming languages, so wrong sometimes dizziness. .Old slightly: P <BR> elementary school math class taught operators to have priority, the computer language is nothing but an extension of human language, where the operator has the same priority level. .The first four have the same priority, the latter two also have the same priority, but the first four priority than 2 months after the. .<BR> When the two expressions connected with the relational operators, the time is the relational expression. .Relational expression is usually used to determine whether a condition met. .Note that with the relational operator evaluates to 0 and 1, only two, which is the logical true and false, if the specified conditions are met the result is 1, not satisfied, the result is 0. .<BR> Expression 1 expression 2 <BR> relational operators such as: I <J,I==J,(I=4)> (J = 3), J + I> J <BR> <BR> .With a good job in the previous lesson we learned the circuit and the related operations. .We do a related instance of relational operator procedures. .To increase the learning fun and lively, may wish to assume that we will do the arithmetic to make a robot, of course, the dialogue will really thinking machine, I think I usually do not come, here is the procedure used to study relationships .operator of the basic application. .# Include <AT89X51.H> <BR> # include <stdio.h> void main (void) <BR> {<BR> int x, y; SCON = 0x50; / / serial port mode 1, allowing the receiver <BR .> TMOD = 0x20; / / Timer 1 Timer mode 2 <BR> TH1 = 0xE8; / / 11.0592MHz 1200 baud <BR> TL1 = 0xE8; <BR> TI = 1; <BR> TR1 = 1; / ./ start timer <BR> <BR> while (1) <BR> {<BR> printf ("Hello! My name is Robot! I was a robot will do the arithmetic! \ n"); / / show < .BR> printf ("Please enter two int, X and Y \ n"); / / display <BR> scanf ("% d% d", & x, & y); / / input <BR> .if (x <y) <BR> printf ("X <Y \ n"); / / Y when X is less than when the <BR> else / / if X is not less than Y again when the judge <BR> {< .BR> if (x == y) <BR> printf ("X = Y \ n"); / / if X equals Y when <BR> else <BR> printf ("X> Y \ n"); / / .When X is greater than Y when <BR>} <BR>} <BR>} Note that, in connection PC serial port for debugging. .Send figures, even after sending the one number to send a carriage return to make sure there is data input function scanf. .Printf, scanf function of the specific usage, and other related functions will be concentrated in the C51 function www.cdle.net Detailed in, please everyone pay attention. .<BR> Logical relational operators can reflect the size between the two expressions equal relationship, it is logical operators are used to find the value of conditional logic, using logical operators or logical expression of the relationship .volume is the logical expression of the link. .Maybe you will Why? Quot; logical operators to link the relational expression is the logical expression of "a description which places in doubt. In fact, said before" should be noted that with the relational operators of the operation result is only 0 .and a two, that is the true and false logic ", in other wordsthe amount that is logical, and logical operators to the amount of operations for the expression of logic. As for the amount of complex logic and I know very little about the algorithms, .To understand the friends can see the textbook of digital circuits, logic or math book, and the only talk about simple and commonly used in several. logical expression of the general form: <BR> logic: conditional 1 & .& 2 <BR> logic or conditional: Conditional 1 | | 2 <BR> conditional logic of non-:! conditional 2 <BR> <BR> <BR> Figure 7-5 shows the results of logic, it means .When the conditional 1 "and" conditional 2 are true is true (non 0 value), otherwise false (0 value). That operation will first be judged on a conditional, if true (non 0 .value), then continue to judge the condition of type 2, when the result is true, the result of logic operation is true (value 1), if the result is not true, the logical result of the operation is false (0 value). If .determine the conditional 1 is true is not to determine the conditions no longer type 2, while the direct result of the operation is false is given. <BR> logic or, as long as the two operations is a condition is true, the operation .The result is true not only when the conditional is true, the logical result of it is false. <BR> logic of non-logical result is the negated value, that type of operation if the two conditions is true ., then the logical outcome after non-operation becomes false, the conditional expression is false is true when the logical result of the final. <BR> logical operators have the same priority level,! (logical not) → & & (logical AND) .→ | | (logical or), the logic of non-highest priority. <BR> if! True | | False & & True <BR> priority logical operations to analyze the obtained (True representative of true, False Representative .false) <BR>! True | | False & & True <BR> False | | False & & True / /! Ture first operation was False <BR> False | | False / / False & & True .operation may False <BR> False / / end False | | False False <BR> let's get with the program language to have expressed, as follows: <BR> # include <AT89X51.H> <BR> # include <stdio .. h> void main (void) <BR> {<BR> unsigned char True = 1; / / define <BR> unsigned char False = 0; SCON = 0x50; / / serial port mode 1, to allow reception of <BR> TMOD = .0x20; / / Timer 1 Timer mode 2 <BR> TH1 = 0xE8; / / 11.0592MHz 1200 baud <BR> TL1 = 0xE8; <BR> TI = 1; <BR> TR1 = 1; / / start timer .device <BR> <BR> if (! True | | False & & True) <BR> printf ("True \ n"); / / When the result is true <BR> else <BR> printf ("False .\ n "); / / result is false <BR>} we can use the previous method of learning or burn the film with the use keil serial debugging. you can change"! True | | False & & True "the conditional .to test a combination of different algorithms to master the use of logical operators. <BR>.