Current location - Education and Training Encyclopedia - Graduation thesis - Rlc network paper
Rlc network paper
Several Problems in the Design of C5 1 Language Application Program

Pick? Want it? Introduction to Franklin? The characteristics of C5 1 cross compiler, the basic skills of C5 1 language programming, its mixed programming with assembly language programs, interrupt handling and other practical problems are discussed in detail, and the corresponding processing programs are given.

Key words? FranklinC5 1 Compiler Assembly Language Structured Design Module Interrupt

-

Assembly language is a commonly used software tool when developing single chip microcomputer application system. The hardware can be directly operated, and the instruction execution speed is fast. However, the inherent format of its instruction system is greatly limited by the hardware structure, and it is difficult to write and debug, and its portability is also poor. With the improvement of the hardware performance of single chip microcomputer, its working speed is getting faster and faster, so when writing the program of single chip microcomputer application system, more attention is paid to the programming efficiency of the program itself. Where's Franklin C5 1 cross compiler is an efficient C language compiler specially designed for 80C5 1 series single chip microcomputer. Using it can shorten the development cycle and reduce the development cost. In addition, the developed system is easy to maintain, high in reliability and good in portability. Even in the use efficiency of the code, it can be completely comparable to assembly language, so it has become a popular tool for developing 80C5 1 series single chip microcomputer.

1? Basic Skills of Programming C5 1 Language

C language is a high-level programming language, which provides a very complete standardized process control structure. Therefore, when using C5 1 language to design the program of single-chip microcomputer application system, we should first adopt structured programming method as far as possible, which can make the whole application system program structure clear and easy to debug and maintain. For a larger program, the whole program can be divided into several modules according to the function, and different modules accomplish different functions. For different functional modules, the corresponding entry parameters and exit parameters are specified respectively, and some commonly used programs are compiled into functions better, which will not cause confusion in the whole program management, but also enhance readability and portability.

In the process of programming, we should make full use of the preprocessing command of C5 1 language. For some commonly used constants, such as TRUE, FALSE, PI and various special function registers, or some important constants in the program that can be changed according to external conditions, you can use the macro definition "# #define" or put them together in a header file, and then use the file inclusion command "# #include" to add them to the program. In this way, when a parameter needs to be modified, it is only necessary to modify the corresponding inclusion file or macro definition, and it is not necessary to modify every program file that uses them, which is beneficial to the maintenance and update of the file. Here are some examples:

Example 1? For different single crystal oscillators, the program adopts different delay time, and the length of delay time can be modified according to the changes of external conditions. For such a program, it can be realized by macro definition and conditional compilation. The process is as follows:

# Definition? Flag? 1?

#ifdef? flag== 1?

#definefosc6M?

Delay =10; ?

#elif? Flag? =? =? 0?

# Definition? fosc8M?

Delay =12; ?

# Others?

#definefosc? 12M?

Delay = 20; ?

#endif?

main()?

{?

for(I = 0; I < delay; i++); ?

}?

In this way, the source program can be applied to single chip microcomputer systems with different clock frequencies without any modification, and different delay values can be taken according to different situations to accomplish different purposes.

2? Mixed Programming of C5 1 Language and Assembly Language Program

C5 1 compiler can efficiently compile C language source programs and generate efficient and concise codes. In most cases, programming in C language can achieve the expected purpose. But sometimes in order to program intuitively or deal with some special addresses, it is necessary to use some assembly language to program. On other occasions, for a certain purpose, assembly language can also call C language. In this mixed programming, the key is the transfer of parameters and the return value of functions. They must have a complete agreement, otherwise the exchange of data may be wrong. We take 10 bit serial A/D converter TLC 1549 of Liyuan Company as an example. Give an example to illustrate the call of C language program and assembly language program. ?

Figure 1? TLC 1549 pin diagram

The pin diagram and timing diagram of 1549 are shown in Figure 1 and Figure 2, respectively. Suppose the data? OUT connects P 1.0, P 1. 1, and CLOCK connects P 1.2.

Please refer to relevant materials for the specific functions of 1549.

Figure 2? TLC 1549 timing chart

Example 2? C language program and assembly language program call, its subprograms are as follows:

Public? AD? ; Entrance address?

SEG_AD? Segment? Code; Program clips?

RSEG? SEG_AD?

Use? 0?

Advertisement: MOV? R6, 00?

MOV? R7,#00?

SETB? P 1. 1?

Call? Delay?

CLR? P 1. 1?

Call? Delay?

MOV? R0,# 10?

RR0:? SETB? P 1.2?

NOP?

CLR? P 1.2?

DJNZ? R0,RR0?

Call? Delay?

MOV? 30H,R6? ; Is A/D conversion high?

; Two are stored in R6?

Call? CIR?

MOV? R6,30H?

SETB? P 1.2?

NOP?

CLR? P 1.2?

MOV? 30H,R6?

Call? CIR?

MOV? R6,30H?

MOV? R0,#8? ; Is the A/D conversion low?

; Store 8 bits in R7?

RR2:? SETB? P 1.2?

NOP?

CLR? P 1.2?

MOV? 30H,R7?

Call? CIR?

MOV? R7,30H?

DJNZ? R0,RR2?

RET?

CIR:? CLR? c?

MOV? c,P 1.0?

MOV? a,30H?

RLC? Answer?

MOV? 30H,A?

RET?

End?

In the above program, the return value of the function is an unsigned integer. According to the calling rules, the high order of the return value must be R6 and the low order must be R7, so as to ensure that the data transmission is error-free. In addition, during the call, be sure to pay attention to the register stack. In this way, when using A/D conversion in the future, you can call the assembly language subroutine AD () in C language.

3? C5 1 Interrupt Processing

C5 1 compiler supports the direct development of interrupt program in C source program, which reduces the tedious work of using assembly language and improves the development efficiency. The complete syntax of the interrupt service function is as follows:

Void function name (void)[ mode]

[Reentry]] Interrupt? n? [use? r]

Where n (0 ~ 3 1) represents the number of interrupts. The C5 1 compiler allows 32 interrupts, and which interrupt to use is determined by the 80C5 1 series chips. R (0 ~ 3) stands for r groups of registers. When calling an interrupt function, it is required that the functions called by the interrupt program must use the same register group. "Reentry" is used to indicate whether the interrupt handler has "Reentry" capability. The C5 1 compiler and its extension to the C language allow programmers to control all aspects of interrupts and use register groups. This support enables programmers to create efficient interrupt service programs, and users only need to care about interrupts in C language and necessary register group switching operations.

Example 3? To set the fosc= 12MHz of the single chip microcomputer, it is required to program 1 in the form of T0, and output a square wave with a period of 2ms at the pin P 1.0.

The interrupt service program written in C language is as follows:

# Contains? & ltreg 5 1 . h & gt; ?

sbit? p 1_0=p 1^0; ?

Invalid? Timer 0 (invalid) interrupt? 1? Use? 1? {?

/*T0 interrupt service program entry */?

P 1_0=! p 1 _ 0; ?

TH0 =-( 1000/256); /* Reload the initial count value */?

TL0 =-( 1000% 256); ?

}?

Invalid? main(void)?

{?

TMOD = 0x 0 1; ? /*T0 works in timer mode 1*/?

p 1 _ 0 = 0; ?

TH0 =-( 1000/256); ? /* Default initial count value */?

TL0 =-( 1000% 256); ?

EA = 1; /* CPU when interrupted */?

ET0 = 1; ? /*T0 open interrupt */?

TR0 = 1; ? /* Start T0*/?

do { } while( 1); ?

}?

When writing an interrupt service program, be sure not to pass parameters and return values.

4? conclusion

C5 1 compiler can not only shorten the development cycle of single chip microcomputer control system, but also be easy to debug and maintain. In addition, C5 1 language has many powerful functions, such as providing rich library functions for users to call directly, and complete compilation control instructions to provide necessary symbolic information for program debugging. In a word, C5 1 language is a powerful tool for the majority of single chip microcomputer developers.