Read “Monolithic integrated circuit And Embedded system Application” in 2005 the 10th issue of magazine “Experience Exchange” a column article “Keil C5l after Identical Port’s Continual Read Method” (original text), the author thought that this article has not carried on the thorough accurate analysis on this question. In the article mentioned two solutions are not direct and are simple. The author thought that this is by no means in Keil C51 cannot process to a port carries on the continual read-write the question, but is not very familiar to the Keil C51 use and the design insufficiently careful question, therefore composes this article especially.
In this article the question which mentioned to the original text, proposed three kinds are different with the original text solution. Each method the method which mentioned the original text in is more direct than and is simpler than, the design is also standarder. (has no intention to criticize, invites original text author excuse me)
1 question review and analysis
In the original text mentioned: Meets in the practical work to the identical port reads continuously repeatedly, Keil the C5l translation has not achieved the anticipated result. The original text author the assembly program which translates to C carries on the analysis discovery, has not been translated to the identical port’s second read sentence. But was a pity that the original text author analysis not the reason which translates, but was uses some not too standard method to experiment two solutions hurriedly.
To this question, glances through Keil C51 the handbook to be very easy to discover: The KellC51 compiler has an optimized establishment, the different optimized establishment, will have the different translation result. The ordinary circumstances default translation optimization establishment is 8 levels optimizes by the hypothesis, is actually highest may establish is 9 levels of optimizations:
①Dead code elimination.
②Data overlaymg.
③Peephole optimization.
④Register variables.
⑤Common subexpression elimination.
⑥Loop rotation.
⑦Extended Index Access 0ptimizing.
⑧Reuse Common. Entry Code.
⑨Common Block Subroutines.
But the above question, is precisely because KeiI the C5l translation optimization produces. Because in original text procedure peripheral device address directly according to the following definition:
unsigned char xdata MAXl97_at_Ox8000;
Uses _at_ to define variable MAXl97 exterior expands RAM to assign address Ox8OOO. Therefore, Keil the C51 optimization translation thought naturally retakes courses the second time is again does not have usefully, with the result which first time read may directly, therefore the compiler has jumped over the second read sentence. Hence, the question was clear at a glance.
2 solutions
Is very easy by the above analysis to be able to propose the very good solution.
2.1 simple most direct means
A procedure spot does not use the revision, the Keil C5l translation optimization choice establishment was 0 (optimization) may not.
Chooses project window Target, then opens “Options forTarget” the establishment dialog box, the choice “C5l” the option card, “Code Optimiztaion” “Level” the choice will be “0:Costant folding”. Translates after once more, everybody will discover that the translation result will be:
CLR MAXHBEN
MOV DPTR,#M.AXl97
MOVX A,@DPTR
MOV R7.A
MOV down8. R7
SETB MAXHBEN
MOV DPTR,#MAXl97
MOVX A,@DPTR
MOV R7.A
MOV uD4.R7
Two read operations are translated.
2.2 best methods
Tells Keil C51, this address is not general expansion RAM, but is the connection equipment, has “the volatility” the characteristic, each time reads is meaningful.
May revise the variable definition, increases “volatile” the key words to explain its characteristic:
unsigned char volatile xdata MAXl97_at_Ox8000;
May also contain a system document in the procedure: “#incIude<ab-sacc.h>”, then revises the variable in the procedure, defines for the one-level address:
#defme MAXl97 XBYTE[Ox8000]
Thus. The Keil C51 establishment still might retain the high-level optimization, and in the translation result, two reads will not be optimized similarly the jump.
2.3 hardware solution
In original text MAXl97 data direct connection data bus, but has not used for the address bus, uses a port line selecting operation height byte. The very simple revision method is uses an address wire selecting operation height byte then. For instance: P2.0(A8) connects original P1.O the connection the HBEN foot (the MAXl97 5 feet), defines the height byte separately in the procedure the operation address:
unsigned char volatile xdata MAXl97_L_aI_Ox8000;
unsigned char volatile xdata MAXl97 H at 0.x8100;
Original procedure:
MAXHBEN=O; // reads low 8
down8=MAXl97:
MAXHBEN=1; // reads high 4
up4=MAXl97:
Changes following two then:
down8=MAXl97_L; // reads low 8
up4=MAXl97_H; // reads high 4
3 subtotals
Keil C51 passes through tests and the improvement as well as the massive development personnel’s actual use for a long time, had already overcome the overwhelming majority question, and its translation efficiency is also high. Regarding the general use, very difficult to discover any question again. The author had studied Keil sketchily the C51 optimization translation result, admires Keil the C51 designer’s wisdom, some C program compiling produces assembly code, even also wants the common programmer with the assembly compilation’s code to be more outstanding than and to be succinct directly. Through reads the assembly code which the KeilC51 translation produces, to enhances the assembly language write program the level has the help very much.
May see by this article in question: Meets the question when the design, certainly do not hoodwink by the superficial phenomenon, do not solve eagerly. Should analyze earnestly, discovers the question the reason, like this can fundamentally thorough settlement the problem. On will not present the nonessential disturbance, has prevented the data not unanimous occurrence.