ECET 410 Lab 3 Delay routines using both assembly and C programs Delay functions and subroutines are important function in real time programming. In this lab you will exercise both assembly and C programs to implement delays. In this lab we will use the assembler. In the next lab we will use the C compiler to demonstrate similar learning objectives. Lab Objectives: 1- Learn and understand how to use I/O port registers 2- Learn and understand how to use timer functions and the underlying mechanism for setting up real time counters. 3- Understand the basic idea of interrupts 4- Learn how to work in C environment 5- Learn how to compile and download C programs to the development board 6- Learn how to use functions in C programs. Pre-lab activities: 1. Scan the file reg9s12.h to get familiar with the assembly definitions of the HCS12 registers. 2. Read the I/O section relevant to the program from chapter 7 3. Examine the vector.h header file supplied with your textbook CD. 4. Provide a more detailed explanation of the program below before using it. Lab activities: 1. Assemble and down load the following program 2. Use the software interrupt instruction in the proper place in the program in order to get the > prompt back to the hyper terminal, so you can continue debugging your program. 3. Modify the program such that it runs continually or until you hit the abort or the reset button on the board. 4. Modify the program to create a chaser light ( where LED 1 is lighted first, 5 seconds later LED1 is turned off and LED2 is lighted for 5 second and so on) . 5. Change the delay in your program: one time use to use 10 seconds instead of 5 and repeat the program. A 5 seconds delay assembly program ; 5s_delay.asm 5 second delay timer for DRAGON12 Rev. E board ; (c)2002, EVBplus.com, written by Wayne Chu ; ; Function: 5 second delay routine using output comparator 6 ; The PB0 LED will be turned on immediately after running ; this program. It will be turned off after 5 second delay. ; Change the DELAY_TIME to 36000 will delay 3 minutes. PB0: equ DB6: equ ; TB1MS: ; 1 $40 ;DELAY_TIME: DELAY_TIME: REGBLK: #include org equ 24000 ; 1ms time base of 24,000 instruction cycles ; 24,000 x 1/24MHz = 1ms at 24 MHz bus speed equ equ 36000 ; 36000 X 5 ms= 180 sec = 3 min 5000 ; 5000 X 1 ms= 5 sec equ reg9s12.h $0 ; include register equates $1000 ; flag_5s: cnt_5s: rmb rmb 1 2 STACK: equ $2000 org $2000 lds ldx stx #STACK #timer6 $3E62 ; initialize the int vetctor ldx ldaa staa staa staa staa #REGBLK #$ff ddrb,x ddrp,x ptp,x ddrj,x ; make port B an output port ; make port P an output port ; turn off 7-segment LED display ; make port J an output port start: clr ptj,x ldaa staa ldaa staa staa #$80 tscr,x #DB6 tios,x tmsk1,x ; make PJ1 low to enable LEDs ; enable timer ; select t6 as an output compare cli bset portb,x PB0 ; turn on LED PB0 jsr delay_5s bclr portb,x PB0 ; turn off LED PB0 stp: jmp delay_5s: clr clr clr delay: ldaa beq rts stp cnt_5s cnt_5s+1 flag_5s flag_5s delay timer6: ldx inx stx cpx bne clr clr ldaa staa rti tmr6: ldx ldd addd std ldaa staa rti org cnt_5s cnt_5s #DELAY_TIME tmr6 cnt_5s cnt_5s+1 #1 flag_5s #REGBLK #TB1MS tc6,x tc6,x #DB6 tflg1,x $3E62 ; reload the count for 1 ms time base ; clear flag fdb end timer6 A simpler delay program This program is from your text chapter 2, it depends on the time an instruction takes to execute. The following sequence of instruction takes 10 seconds to execute. If you have hard time with above program, you can start with this delay routine to get your lab completed on time. In the mean time work on understanding the mechanics behind the timer interrupt driven program above. ldab #100 out_loop ldx in_loop psha pula psha pula psha pula psha pula psha pula psha pula psha pula nop nop dbne dbne #20000 ; 2 E cycles ; 3 E cycles x,in_loop b,out_loop ; 1 E cycle ; 1 E cycle ; 3 E cycles ; 3 E cycles