; ;********************************************************************************************************************** ;task3.asm by James Walmsley (C)2006 [worm.me.uk] ;********************************************************************************************************************** ; ; ;********************************************************************************************************************** ;SET-UP Assembler for PIC, and CHANGE PIC SETTINGS ;********************************************************************************************************************** ; include”P16F877.INC” ;include the pic 16f877 assembly definitions TIMREG EQU H’0020' ;Create a register called TIMREG at register address Hex 0020 TIMREG1 EQU H’0021' ;Create a register called TIMREG1 @ register address Hex 0021 delval EQU H’00FF’ ;Create a variable called delval with the Hex value of 00FF (255) delval1 EQU H’00FF’ ;Create a variable called delval with the Hex value of 00FF (255) banksel TRISD ;Change selected bank to TRISD clrf PORTD ;Set PORTD to be an output banksel PORTD ;Change selected bank to PORTD ; ;********************************************************************************************************************** ;START OF MAIN PROGRAM ;********************************************************************************************************************** ; start movlw 0 ;Move literal value of 0 into the working register (W-Register) movwf PORTD ;Move Value of W-Register to PORTD (in this case turning all LEDs off) loop incf PORTD,f ;Define a loop, update the LEDs by incrementing PORTD call delay ;Call up a sub-routine called delay (Found below) nop ;Use the no-operation instruction to waste 1 clock cycle ;The program counter is therefore increased by 1 instruction count goto loop ;Return to the start of loop (as labelled) ; ;********************************************************************************************************************** ;END OF MAIN PROGRAM & Start of Sub-routines, and Break-points ;********************************************************************************************************************** ; delay movlw delval ;Start of delay sub-routine, load w-register with value in delval variable movwf TIMREG ;Move the delval (from the w-register) value into TIMREG time call delay1 ;Create breakpoint called time & call next delay(1) routine decfsz TIMREG,f ;Subtract 1 from TIMREG or skip over next instruction if 0 goto time ;Return to the time label return ;Finish the delay sub-routine and return to main code delay1 movlw delval1 ;Start of delay1 sub-routine, load w-register with value in delval1 variable movwf TIMREG1 ;Move the delval1 (from the w-register) value into TIMREG1 time1 decfsz TIMREG1,f ;Subtract 1 from TIMREG or skip over next instruction if 0 goto time1 ;Return to the time1 label return end ;End of Program (leaving 1 more line after this)