Wednesday, December 29, 2010

【 Weak current College 】 C51 language application programming problems 】


Summary overview of Franklin C51 cross-compiler feature in more detail the C51 language programming on basic skills and assembly language programs of hybrid programming, interrupt processing, and other practical problems, and provides the appropriate handler. Franklin C51 compiler language keywords structured design module interrupt
In the development of single-chip applications, assembly language is a commonly used software tools. It can directly manipulate hardware instruction execution speed. But the instruction set of intrinsic format by hardware structure of limit is large and difficult to write and debug, portability is also poor. With single-chip hardware performance increases, their work at an increasing rate, therefore writing the microcontroller program, more focused on the preparation of the program itself. And Franklin C51 cross-compiler is designed for 80C51 series single-chip design of an efficient C language compiler, use it to shorten the development cycle and reduce development costs, and developed the system easy to maintain, high reliability, portability, even if the efficiency of your code and you can compare and assembly language, so now it has become a popular 80C51 series SCM tool. 1 C51 language programming basic skills in C language is a high-level programming language, it provides very comprehensive standardization process control structure. Therefore adopt C51 language design microcontroller program, first, to the extent possible, use structured programming, this would make the entire application system program structure is clear and easy to debug and maintain. For a larger program, you can use the entire program by function into several modules, different modules to complete different functions. For different functional modules, specify the appropriate import parameters and export parameters, while frequently used programs best into function, this will not cause the entire program management of chaos, also enhances readability and portability. In the program design process, in order to take advantage of the preprocessing commands C51 language. For some of the commonly used constants, such as TRUE, FALSE, PI, and various special function register, or in some important basis outside conditions variable constants, use the macro definitions "# define" or together in one defined in the header file, and then uses the file containing the command "# include" add it to the program. So when you need to modify a parameter, you only need to modify the include file or macro definitions, without having to use each program files have been modified, thus it¡¯s helpful for maintaining and updating the file. The following are examples: example 1 for different chip oscillator, procedures for different delay times, and according to external conditions change to modify the length of the delay time. For such a program, macro definitions and conditional compilation. Procedures are as follows:
# define flag flag = 1 # ifdef = 1 # define fosc 6M delay = 10; # elif flag = = 0 # define fosc 8M delay = 12; # else # define fosc 12M delay = 20; # endifmain () {for (I = 0; I < delay; I ++);}
this source not to make any changes that may be applicable to different clock frequency-chip system, and may act according to the circumstances of different from different delay values to complete the different purposes. 2 C51 language and assembly language programs for C51 compiler can mixed programming on C language source code efficiently compile, build efficient and concise code, in the vast majority of occasions using C language programming to complete the intended purposes. But sometimes to programming visual or certain special address processing, shall be in a certain amount of Assembly language programming. In other occasions, for some purposes, assembly language can also be called the c language. In this mixed programming, the key is to pass parameters and function return value. They must have the full agreed between the data exchange is possible. Here's to power the company's 10-bit serial A/D Converter: description TLC1549 C language programs and assembly language program call. Figure 1 map of 1549 TLC1549 PIN pin diagrams and sequence diagrams are shown in Figure 1 and Figure 2 below, assumes that DATA OUT, receiving P1.0, CLOCK add P1.2 P1.1.
The specific characteristics of 1549, access to such information. Figure 2 C-series legend 2 TLC1549 language programs and assembly language program calls, its procedures are as follows:
PUBLIC AD; import address SEG_AD SEGMENT CODE; program segment RSEG SEG_ADUSING 0 AD: MOV R6, # 00MOV R7, # 00SETB P1.1ACALL DELAYCLR P1.1ACALL DELAYMOV R0, # 10 RR0: SETB P1.2NOPCLR P1.2DJNZ R0, RR0ACALL DELAYMOV 30H, R6; A/D conversion of high; two saves in R6 R6, in the ACALL CIRMOV 30HSETB P1.2NOPCLR P1.2MOV 30H, R6ACALL CIRMOV R6, 30HMOV R0, # 8; A/D conversion of 8-bit low; saved in R7 SETB P1.2NOPCLR in RR2: P1.2MOV 30H, R7ACALL CIRMOV R0, R7, 30HDJNZ RR2RET CIR: CLR CMOV P1.0MOV A, C,
30HRLC AMOV 30H, ARETEND in the above program, the function's return value is an unsigned integer, depending on the call, the return value must be high in R6, R7 low in, in order to ensure that data transfer is not an error. Additionally, the calling process, care must be taken to register into the stack. This later by using the A/D conversion, in c-language subroutines called AD (). 3 C51 interrupt processing C51 compiler support in the C source program directly develop disruptive process, so reduced the use of Assembly language cumbersome work improves development efficiency. Interrupt service functions of the full syntax is as follows: void function-name (void) [mode]
[Reentry] to interrupt n [using r] n which (0-31), speaking on behalf of the interrupt number. C51 compiler allows 32 interrupt, which breaking chip by 80C51 series. R (0-3) r on behalf of the Group of registers. The call interrupt function requires interrupt procedure call functions that use register groups must be the same. "Re-entry" used to describe interrupt handling functions have no "reentry" capabilities. C51 compiler and its extension to the C programming language allows for the interrupt all aspects of control and register groups. This support enables programming to create efficient interrupt service program, the user need only concern in C language is interrupted and the necessary registers group switch operation. Case study 3 set f microcomputer osc = 12MHz, asking for the way T0 1 programming, in output cycle-P1.0 feet square wave 2ms. Use C language service interruption
procedures are as follows: # include <reg51.h> sbit P1_0 = P1 ^ 0; void interrupt timer0 (void) 1 using 1 {/* T0 the interrupt service program entry * P1_0;/P1_0 =! TH0 =-(1000/256); /* Count of initial reload */TL0 =-(1000% 256);} void main(void){TMOD=0x01; /* T0 work in timer mode 1 */P1_0 = 0; TH0 =-(1000/256); /* Initial * preset count/TL0 =-(1000% 256); EA = 1; /* Break * CPU open/ET0 = 1; /* Break * T0 open/TR0 = 1; /* Start the T0 */do {} while (1)
;} In the preparation of the interrupt service program must be careful not to carry out parameter, you cannot have a return value. C51 compiler 4 conclusions not only can shorten the microprocessor control system of the development cycle, and easy to debug and maintain. In addition, there are many powerful C51 language features, such as delivering a rich library functions to be called directly by user, the full compiled control directive in order to provide the necessary program debugging symbol information and so on. In short, is the majority language C51-chip Developer's powerful tool.

No comments:

Post a Comment