Saturday, January 1, 2011

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

<br> class apart of this lesson a long period of time, these days many users received a letter from the support and encouragement to complete the remaining part as soon as possible. .People have to be away from home to work for the food, it seems that this has become my excuse for taking the time to play some of it later that night we can not repeat too long can also see some new things. .My notes may not be correct, but I try to make sure that each lesson will personally do a test, including hardware parts, have been seeking is not fraught. .<BR> With the steady increase in visits, the site has been enabled www.cdle.net the international domain, where I thank you for supporting the magnetic force studios have been friends, but also to appreciate the body has been quietly in the distance to support my girlfriend .. .<BR> <BR> Minghao 2003-7-14 night Oh, so the less the fee. .Two said on constants and variables, the first to add one to re-define the data type of statement it. .This statement is typedef, this is a good use of the statement, but I have not used it, I usually define the variable data type is a standard keyword, so that others can easily read your program. .If you are a programmer or programming enthusiasts DELPHI, you may be accustomed to the definition of variables DELPHI keywords, such as the int type Integer often defined with the keyword in the use of C51 back to this when you want to use it, you can .write: <BR> typedef int integer; <BR> integer a, b; <BR> <BR> these two at compile time, in fact, is to first integer is defined as int, met in a later statement on the use of integer .int permutation, integer equal to int, so a, b will be defined as int. . typedef can not be directly used to define the variables, it is only on the existing data type for a name on the replacement, not create a new data type. .The following example of two is a mistake: <BR> typedef int integer; <BR> integer = 100; <BR> <BR> typedef can easily use the transplant procedure and simplify the definition of a long data type. .Typedef structure can also be defined by the type of detailed explanation of this structure type in the back together again when the description. .The syntax is <BR> typedef typedef the data types have a new data type name <BR> <BR> operator is to complete a specific operation symbols. .Operator according to their expression and the relationship between operators can be divided into unary, binary operator, and three mesh operators. .Monocular refers to the need for a computation object, binocular requires two operands, the three projects will have three operands. .Expression by the operator and the operator is composed of the object's formula has a specific meaning. .C is an expression language, an expression followed by ";" was to constitute an expression statement. .<BR> For the assignment operator "=" sign you will not be strange, in C, its function is to assign values to variables, called the assignment operator. .It goes without saying we also understand the role, but the data is assigned to the variable. .Such as, x = 10; So use the assignment operator and an expression to a variable formula linking the expression for the assignment, followed by the expression ";" would constitute an assignment statement. .Use "=" assignment statement format is as follows: <BR> variable = expression; <BR> examples are as follows <BR> a = 0xFF; / / the constant hexadecimal FF assigns the variable a <BR> b = c .= 33; / / while assigned to the variable b, c <BR> d = e; / / assigns the value of the variable e variable d <BR> f = a + b; / / variable assigns the value of a + b .variable f <BR> <BR> can know from the above examples the meaning of assignment is to first calculate the "=" the right of the value of the expression, then the value will be assigned to the left of the variable. .And to the right of expression can be an assignment expression. .<BR> In some of my friends will appear in the "==" and "=" error confused the two symbols of the original code, and asked why the compilation error, is often wrong if (a = x) statement like ., wrongly "=" with the "=="。 ."==" Symbol is used for equality relational operators. .Arithmetic, a change in the amount of operator <BR> for a + b, a / b this expression we are familiar with the C language ,+,/, is the arithmetic operators. .The C51 has the following arithmetic operators, which take only take positive and negative operator is unary, the other operators are all eyes: <BR> + plus or taking positive operator <BR .> - down or be negative operator <BR> * multiply operator <BR> / inter operator <BR>% modulus operator in the form of arithmetic expressions <BR>: <BR> expression of expression 1 Arithmetic Operators .Type 2 <BR> <BR> such as: a + b * (10-a), (x +9) / (ya) <BR> <BR> division operator and general arithmetic rules differ, in the case of two .floating-point division, the result is floating-point, such as 10.0/20.0 from 0.5, and dividing two integers, the integer value is obtained, such as 7 / 3, is 2. .Other languages like C and operator precedence and associativity are also available in parentheses "()" to change the priority. .These and our child to learn math is almost the same, I do not have too many shows. .<BR>: (There are so many operators it! Stop for a moment and let us do an experiment before it. Learning operators, and other knowledge, we give our experimental board plus a serial interface it. .using computers to look at pieces of visual output of the microcontroller, then I will explain with some examples of simple microcontroller and a simple PC serial communications applications and programming. If you experiment with the finished board or emulator, then you can jump .over this period of the. <BR> in the production of circuit ago, we first look to use the MAX232, here we do not discuss it specifically, just know that it is TTL and RS232 level conversion chip and pin terminal basic functions .on the line. Usually, I would use two small power transistor circuit plus a small amount to replace MAX232, you can save a little, the effect is also good (If you are interested to see http://www.cdle.net site information). The next .Figure is a basic wiring diagram of MAX232. <BR> <BR> Figure 7-1 MAX232 <BR> in the last two courses on the basis of the circuit with MAX232 in Figure 7-3 on it. Take this hot day welding iron .welding, the heat really is to force people to Come: P with a DB9 serial port of the female seat, so that you can buy a PC with a serial port extension cable connected to the computer, or directly to your computer com port. <BR> .Figure 7-2 DB9 connector <BR> <BR> <BR> Figure 7-3 with the experimental circuit MAX232 <BR> ready, we will first go back to the first lesson of the "Hello World!" program, use it .come and say your computer Hello! burn the program on the chip, the serial port connected. hey, this time to open your serial debugging software, no one up to the web DOWN. You will use the super mid-Windows .also, but I do not have it. I http://emouze.com the comdebug, it is a good software, I like it because it functions well but also "line status" feature, which I make gadgets .useful. serial number, baud rate fine, open the serial port, single chip power to be in the receiving area to see the emerging "Hello World!". we must first open the software's serial port, then power microcontroller, .Otherwise, characters may not align and see garbled Oh. <BR> <BR> debugging results <BR> Figure 7-4.

No comments:

Post a Comment