Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

EE Design > In Technical
| Home | Contact |

Title: Software delay in PIC Microcontrollers
Author: Vincent Wong
Date: 29th March 2005


Below shows the millisecond and microsecond subroutines. You can call the DELAY_1_MS function for a 1ms delay and DELAY_1_2MS routine for a 1.2ms delay. Other timing can be easily implemented by loading the appropriate values to the working register before calling the MICROSEC or MSEC subroutines.


    
    MICROSEC:
    	BCF	STATUS,RP0					    
    	MOVWF	MSEC_REG2
    	MOVLW	0XFF
    	MOVWF	MSEC_REG
    	MOVF	MSEC_REG2,W
    MICROSEC2:	
    	ADDWF	MSEC_REG,W
    	BTFSS	STATUS,Z
    	GOTO	MICROSEC2
    	NOP
    	NOP
    	NOP
    	NOP
    	RETURN
    		
    
    MSEC:	MOVWF	MSEC_CTR
    MSECLOOP:
    	MOVLW	0XF8
    	CALL	MICROSEC
    	NOP
    	NOP
    	DECFSZ	MSEC_CTR,F
    	GOTO	MSECLOOP
    	RETURN
    		
     
    DELAY_1_MS:
    	MOVLW	0XF8		;1MS
    	CALL	MICROSEC
    	RETURN
    		
    
    DELAY_1_2MS:
    	MOVLW	D'47'		;200US
    	CALL	MICROSEC
    	MOVLW	0XF8		;1MS
    	CALL	MICROSEC
    	RETURN
    
    



| Home | Top Page | Contact |


Copyright Notice: This article, including all text, documents and schematic diagrams, are the intellectual property of Vincent Wong, and is Copyright (c) 2005. Reproduction or re-publication by any means whatsoever, whether it is electrical & electronic, mechanical or electro-mechanical, is strictly prohibited under International Copyright laws. The author (Vincent Wong) grants the reader the right to use this information for personal use only. Commercial use is prohibited without express written authorisation from Vincent Wong.

Copyright of Vincent Wong. All Rights Reserved.