Professional Documents
Culture Documents
PROCEDURE 1. The program is wrote in MPLAB Editor. This program will show blinking LED array on the 8-bits LEDs. 2. The program then downloaded into DH PIC Training Kit. 3. A flowchart is drawn. The result obtained in step 2 is discussed. 4. The clock operation is defined and the delay of the program is calculated. 5. What will happen if the delay and delay_0 are removed from the program is discussed.
LIST INCLUDE
;tell assembler what chip we are using ;include the defaults for the chip
0X3D1A ;sets the configuration settings (oscillator type etc.) 0X20 ;start of general purpose registers ;used in delay routine ;used in delay routine ;used in delay routine
;org sets the origin, 0x0000 for the 16F877a, ;this is where the program starts running
STATUS,RP0
B'00000000' ;set PortB all outputs TRISB TRISA ;set PortA all outputs ;select bank 0
STATUS,RP0
0XFF
MOVWF MOVWF NOP NOP CALL CALL CALL DELAY DELAY DELAY MOVLW MOVWF MOVWF CALL GOTO LOOP DELAY
PORTA PORTB
;the nop's make up the time taken by the goto ;giving a square wave output ;this waits for a while! ;this waits for a while! ;this waits for a while! 0X00 PORTA PORTB ;set all bits off
DELAY MOVLW MOVWF D1 MOVWF MOVWF MOVLW MOVWF DELAY_0 DECFSZ COUNTA, F GOTO $+2 DECFSZ COUNTB, F GOTO DELAY_0
Listing 1
RESULT
DISCUSSION The program is executed in MPLAB Editor as shown in Figure 1. After the program is built successfully, it is then downloaded into DH PIC Training Kit. First three line used as instruction to assembler. Next, CMCON is a register in 16F877A that is used to select the operation of the comparator. The direction is set, select bank 1 by using bsf and select bank 0 by using bcf. For loop instruction that is used to return the program and keep it loop around. Next, nop instruction (No operation) which take 1s to execute to do nothing. The important part is for the delay instruction. The call delay is used to call subroutine. It will be execute and returns back to where it was called from. The delay program is told at the next line Delay where it used d250 which means a delay take 250ms. Here, we used three time call delay. Thus, it will delay for 750ms or 0.75s, first call delay tell it to leaving the LED on for 1/2 a second, and another call delay is to the 'off time' the LED will stay off for 1/2 a second, it repeat as the call delay is added but it will flash once per second for every call delay. Beside, retlw is used that means return form subroutine with Literal in W. It used to returns the subroutine to where it called from. So, the result for hardware implementation is show in Figure 2. The LED (red) will turn on and off due to the delay operation. So, when the delay and delay_0 are removed. The LED will turn on without flashing since there is no time delay.
START
Initiate entity
Delay 250ms
Delay 250ms
END
For this task we are exposed to the hardware implementation. So, we are using the DH PIC Training Kit to download the MPLAB code and see the result of the implementation. From, this task we also introduced to some function delay which is use to give some delay operation of a program.