You are on page 1of 6

LAB 5: DH PIC Training KIT-Blinking LED OBJECTIVE 1. To apply software of MPLAB into hardware implementation.

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

P=16F877A "P16F877A.INC" __CONFIG CBLOCK

;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

COUNT1 COUNTA COUNTB ENDC ORG 0X0000 0X07

;org sets the origin, 0x0000 for the 16F877a, ;this is where the program starts running

MOVLW MOVWF BSF

CMCON ;turn comparators off ;select bank 1

STATUS,RP0

MOVLW MOVWF MOVWF BCF LOOP MOVLW

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

;set all bits on

;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

;go back and do it again D'250' ;delay 250 ms (4 MHz clock)

DELAY MOVLW MOVWF D1 MOVWF MOVWF MOVLW MOVWF DELAY_0 DECFSZ COUNTA, F GOTO $+2 DECFSZ COUNTB, F GOTO DELAY_0

COUNT1 0XC7 COUNTA 0X01 COUNTB

DECFSZ COUNT1, F GOTO D1 RETLW 0X00 END

Listing 1

RESULT

Figure 1: The program is executed in MPLAB Editor.

Figure 2: Result obtained after downloaded into DH PIC Training Kit.

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

Set LED HIGH

Delay 250ms

Set LED LOW

Delay 250ms

END

Figure 3: Flowchart for listing 1.


CONCLUSION

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.

You might also like