Thursday, December 23, 2010

【School】 SCM weak c language tutorial --- Lesson: constant】..

<br> the previous section we learned KEIL C51 compiler supports the data types.. And how is the data type of constants and variables used in the definition of it?. What should pay attention to it?. Here's a look.. Halo .!. District could not tell you what is constant and what is variable.. Constants in the program is running can not change the amount of value, while the variable is in the program is running constantly changing content.. Variable definitions can use all the .C51 compiler supports the data types, and constant data type has only integer, floating-point type, character, string and bit scalar.. In this section we study the constant definition and usage, while the next section the study variable.. < .BR> Constant data type that is the case <BR> 1.. Can be expressed as a decimal integer constant such as 123,0, -89 and so on.. Zeyi 0x at the beginning, such as hexadecimal 0x34,-0x3B .and so on.. Long integer numbers followed by letters in L, such as 104L, 034L, 0xF340 and so on.. <BR> 2.. Floating point constants can be divided into decimal and exponential notation.. Decimal numbers and decimal .form, such as 0.888,3345.345,0.0 etc., integer or fractional part of 0, can be omitted but there must be a decimal point.. Index representation for the [±] digital [. Digital] e [±] numbers, [ .] content is optional, depending on the circumstances in which the content is optional, but the rest must have, such as 125e3, 7e9, - .3.0 e-3.. <BR> 3.. Character constants are characters within single quotes ., such as the 'a', 'd', etc., can not display the control characters, the characters can be preceded by a backslash "\" form-specific escape characters.. Escape characters commonly used in the table shown .in Table 5-1.. <BR> 4.. Constants from the string of characters within double quotes, such as the "test", "OK" and so on.. When the quotation marks with no characters, an .empty string.. In the use of special characters also have to use escape characters such as double quotation marks.. In C, as a string constant is to deal with an array of character type, the system will store the string in the string end .with \ o escape character as the string terminator.. String constant "A" and the character constant 'A' is different, the former is stored in a multi-byte characters occupy a room.. <BR> 5.. Bit .scalar, its value is a binary.. <BR> Escaped characters <? XML: NAMESPACE PREFIX = O /> <O:P> </ O: P> meaning <O:P> </ .O: P> ASCII code (16/10 decimal) <O .: P> </ O: P> \ o <O:P> </ O: P> empty string (NULL) <O: .P> </ O: P> 00H / 0 <O:P> </ O:. P> \ n <O:P> </ O: P> newline (LF) <O:P> .; </ O: P> 0AH/10 <O:P> </ O: P> \ r <O: .P> </ O: P> carriage return (CR) <O:P> .; </ O: P> 0DH/13 <O:P> </ O: P> \ t <O:P> </ O:. P> horizontal tab (HT) <O:P> .; </ O: P> 09H / 9 <O:P> </ O: P> \ b <O:P> </ O: P> backspace. (BS) <O:P> .</ O: P> 08H / 8 <O:P> </ O: P> \ f <O:P> </ O: P> feed character (FF) <O: .P> .</ O: P> 0CH/12 <O:P> </ O: P> \ '<O:P> </ O: P> single quote <O:P> </ O .: P> 27H / .39 <O:P> </ O: P> \ "<O:P> </ O: P> double quotes <O:P> </ O: P> .; 22H/34 <O:P> </ O:. P> \ \ <O:P> </ O: P> backslash <O:P> </ O: P> 5CH/92 .<O:P> </ O: P> Table 5-1 Common escape. <BR> constants used in the character table values do not change the situation, such as fixed data tables, fonts and so on. constants defined .in several ways, to be described below. <BR> # difine False 0x0; / / use predefined. statement can define constants <BR> # difine True 0x1; / / False is defined here as 0, True to 1 < .BR> / / False in the program used to automatically compile replaced with 0, replaced by 1 <BR> True empathy. unsigned int code a = 100; / / This is a definition with a code to a program memory and the assignment < .; BR> const unsigned int c = 100; / / defined with const unsigned int c as constant and more than two assignments <BR>. sentence, their values are stored in program memory, and program memory in the operation is not allowed to .be modified, so if used in the back of these two similar a = 110, a + + such assignment, compile-time error occurs.. <BR> that a pass might as well write a program to test about it. or what .the procedure is? Marquee! Yes, to write this easy to understand it, the Ye Hao shows a typical constant use. Let's look at the schematic it .. It is our last lesson of the experimental circuit based on an increase six LED components, .that is, the mouth with all the pins P1 drive a LED, the circuit shown in Figure 5-1. <BR> a new RunLED. project, the main program as follows: <BR> # include <AT89X51.H> .; / / pre-file which defines the name of the special registers such as the P1 port is defined as P1 <BR> void main (void) <BR> {<BR .> / / definition of pattern data < .; BR> cons tunsigned char design [32] = {0xFF, 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F, <BR> 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB., 0xFD, 0xFE ., 0xFF, <BR> 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x0, <BR> 0xE7, 0xDB, 0xBD, 0x7E, 0xFF}; <BR> unsigned int a; /. ./ define loop variable with <BR> unsigned char b; / / programming in C51 as a result of the limited attention to the variable type of memory used <BR> / / low byte as the type used in popular use in large- .scale program. <BR> do {<BR> for (b = 0; b <32; b + +) <BR> {<BR> for (a = 0; a <30000; a + .+); / / delay time <BR> P1 .= design [b]; / / read data in a defined pattern and write data to the P1 port pattern <BR>} <BR>} while (1); .<BR>} <BR> program to go from the pattern data can be. definitions, because here we have to AT89C51 the P1 LED pin low will light up, so we would like to write P1 pin data port O of the corresponding .LED will be illuminated connection, P1 port of the eight. Port P1 pin is just a special register corresponding to the eight binary, such as the P1 port of the Data 0xFE, converted into binary is 11111110, where the lowest bit D0 = 0 P1 ..0 pin low, LED1 is lit. so. By analogy, we want to do is not difficult to calculate their effects. we look at the programming compiled the results came out, showing the speed you can delay a need to adjust the value of .the variable type of range do not exceed the line is very .. Oh, you do not test board? then how can know the results of running it? Oh, Do not worry, this is that the software simulation with KEIL uVision2 to debug IO .port output and input procedures. <BR> <BR> map .5-1 Eight Circuit Marquee compile and run the above program <BR>, and then press the external device menu Peripherals-I / O Ports-Port1 Port1 to .open the debug window, and 2 in Figure 5-3. then run., but we can not debug window in the Port1 will see what effect, then we can left-click with the mouse 1 in Figure 5-3 bar next to the .green side, there is a little red box tap in the tap. and no, the Na Yiju statement before a small box when running a stop to that, is to set debugging breakpoints, as in Figure 5-2 1 is the same function, .namely, to add / remove a breakpoint, move. In addition to all breakpoints, enable / disable breakpoints, disable all breakpoints, the menu also has the same function, there are additional menu to open the Breakpoints Breakpoints window to set it more powerful, .but we do not have it here first. We? quot.; P1 = design [b]; "This is a time to run to set a breakpoint here and stopped, and then look at Port1 debug window, and then 5-2 .in Figure 2, the operation key, the program has run into. place breakpoint stopped, then the state of Port1 debug window are different.. Port1 debug window that simulates the level of P1 port status check is high, no check was low, the .window in the status register P1 to P1, Pins for the pin state, attention is. read pin value if the corresponding register must be set to 1 pin can be read correctly.. Figure 5-2 {2}-like next to the buttons .into a single, step more, step out and perform to the current line.. Figure 3 is shown in the next sentence statement to be executed.. Figure 3 is 5-3 in the Watches window to view the current value of the variables, .arrays, and strings is to show an address of its head, as in this case, the design is stored in the code array of the first memory address D: 0x08,. Figure 4 Memory in the Memory View window, enter the address in the .Address D: 0x08 can view the design of the data and store address.. UVision2 if you do not show these windows can be opened in the View menu in Figure 5-2 in column 3, the view behind the bar to open the window fast ... <BR> <BR> Figure 5-2 <BR> shortcut menu bar for debugging the debug window in Figure 5-3..

No comments:

Post a Comment