6.2 Macros used in programs Examples given in the following sections of this chapter often use macros WAIT, WAITX and PRINT, so they will be explained in more detail. Macros WAIT, WAITX File Wait.inc contains two macros WAIT and WAITX. Through these macros it is possible to assign time delays in different intervals. Both macros use the overflow of counter TMR0 as a basic interval. By changing the prescaler we can change the length of the overflow interval of the counter TMR0. If we use the oscillator (resonator) of 4MHz, for prescaler values 0, 1 and 7 that divide the basic clock of the oscillator, the interval followed by an overflow of timer TMR0 will be 0.512, 1.02 and 65.3 mS. Practically, that means that the biggest delay that can result would be 256x65.3mS which is equal to 16.72 seconds. In order to use macros in the main program it is necessary do declare variables wcycle and prescWAIT as has been done in examples which follow in this chapter. Macro WAIT has one argument. The standard value assigned to prescaler of this macro is 1 (1.02mS), and it can not be changed. WAIT timeconst_1 timeconst_1 is number from 0 to 255. By multiplying that number with the overflow time period we get the total amount of the delay: TIME=timeconst_1 x 1.02mS. Example: WAIT .100 Example shows how to make a delay of 100x1.02mS, or total of 102mS. Unlike macro WAIT, macro WAITX has one more argument that can assign prescaler value. Macro WAITX has two arguments: Timeconst_2 is number from 0 to 255. By multiplying that number with the overflow time period we get the total amount of the delay: TIME=timeconst_1 x 1.02mS x PRESCext PRESCext is number from 0 to 7 which sets up the relationship between a clock and timer TMR0. Example: WAITX .100,7 Example shows how to make a delay of 100x65.3 mS, or total of 653mS. Macro PRINT Macro PRINT is found in Print.inc file. It makes it easy to send a series of data on one of the output devices such as : LCD, RS232, matrix printer...etc. The easiest way to form a series is by using a dt (define table) directive. This instruction stores a series of data into program memory as a group of retlw instructions whose operand is data from the series. How one such sequence is formed by using dt instruction is shown in the following example: org 0x00 goto Main Series movwf PCL Series1 dt "this is 'ASCII' series" Series2 dt "Second series" End Main movlw .5 call Series : First instruction after label Main writes the position of a member of the sequence in w register. We jump with instruction call onto label series where position of a member of the sequence is added to the value of the program counter: PCL=PCL+W. Next we will have in the program counter an address of retlw instruction with the desired member of the sequence. When this instruction is executed, member of the sequence will be in w register, and address of the instruction that executed after the call instruction will be in the program counter. End label is an elegant way to mark the address at which the series ends. Macro PRINT has five arguments: PRINT macro Addr, Start, End, Var, Out Addr is an address where one or more sequences (which follow one after another) begin. Start is an address of the first member of the sequence End is an address where the sequence ends Var is the variable which has a role of showing (pointing ) the members of the sequence Out is an argument we use to send the address of existing subprograms in working with output devices such as : LCD, RS-232 etc. Macro PRINT writes out a series of ASCII signs for 'MikroElektronika' on LCD display. The sequence takes up one part of program memory beginning at address 0x03.