Page 331 - Programming Microcontrollers in C
P. 331
316 Chapter 6 Large Microcontrollers
convert_bcd( ). putch( ) is straightforward. This routine
waits until the transmit data register is empty and then stores the
character to be transmitted into the serial communications data reg
ister. The routine send_out( ) takes the character parameter passed
to it and causes it to be converted from integer format to two binary-
coded decimal BCD characters. These two characters are then
converted to ASCII characters by the addition of the character ‘0’ to
each and then sent to the output. (Recall that convert_bcd( )
was shown in Chapter 4 in Listing 4-8.) Another version of this func
tion is shown in Listing 4-7. This alternate version has been tried in
the program above and it works as well as the function used above.
With the functions putch( ) and send_out( ) available, it
is a simple matter to write the code that will output the time to the
center of the top line of the screen. It is assumed that the cursor is on
the top line when the program begins to run. The last remaining
modification is the interrupt service routine PIT_Isr( ). Within
this function, the been_here flag is set, and the value in sec is
incremented. Since the applications portion of the program will pro
cess sec and reset it whenever it reaches a value of 60, there is no
need for other code in this isr. For interest, listed below is the out
put from the compiler for both OC3_Isr( ) and PIT_Isr( ).
;150 @port void OC3_Isr( void) /* the PWM isr */
;151 {
.even
_OC3_Isr:
pshm k,z,y,x,d,e
tskb
tbek
tbxk
tbyk
tbzk
; 152 TFLG1.OC1F=OFF; /* reset OC1 interrupt flag */
ldy #0
bclr -1758,y,#8
;153 if(OC1D.OC1D3==ON)
brclr -1783,y,#8,L102
;154 OC1D.OC1D3=OFF;
bclr -1783,y,#8