; ; Misc Macros. Karl Grabe, Cork, Ireland. ; 0 Apr 95: Intitial ; 5 Jun 95: Remove '?' from labels (changed to _Q) ; Do becomes CallW ; MOV becomes MOVFF ; 13 Jun 95 Write W Nybble to file nybble (MovWhFh etc) ; 16 Jun 95 djnz macro removed from other macros with local labels ; (bug in Mpasm 1.10.35?) NOLIST ;******************************************************************** ; Nybble Macros ;******************************************************************** ; Move Hi nybble of W to Hi nybble of File. MovWhFh MACRO File andlw h'F0' ; Clear lower nybble bcf File, 7 ; Clear higher file nybble bcf File, 6 ; Clear higher file nybble bcf File, 5 ; Clear higher file nybble bcf File, 4 ; Clear higher file nybble iorwf File, W ; Combine nybbles - save in w... movwf File ; (...Required if it's a port) ENDM ; Move Lo nybble of W to Lo nybble of File. MovWlFl MACRO File andlw h'0F' ; Clear higher nybble bcf File, 3 ; Clear lower file nybble bcf File, 2 ; Clear lower file nybble bcf File, 1 ; Clear lower file nybble bcf File, 0 ; Clear lower file nybble iorwf File, W ; Combine nybbles - save in w... movwf File ; (...Required if it's a port) ENDM ; Move hi nybble of W to Lo nybble of File, ; File is an i/o port ; TempReg is a tempory scratch register MovpWhFl MACRO thePort, TempReg andlw h'F0' ; Clear low nybble movwf TempReg ; Save W bcf thePort, 3 ; Clear lower file nybble bcf thePort, 2 ; Clear lower file nybble bcf thePort, 1 ; Clear lower file nybble bcf thePort, 0 ; Clear lower file nybble swapf TempReg, w ; Retrieve Hi nybble of w, move to lo iorwf thePort, W ; Combine nybbles - save in w... movwf thePort ; (...Required if it's a port) ENDM ; Move hi nybble of W to Lo nybble of File (no temporary register) ; File can be any ram register, but not a port MovWhFl MACRO File andlw h'F0' ; Clear low nybble bcf File, 3 ; Clear lower file nybble bcf File, 2 ; Clear lower file nybble bcf File, 1 ; Clear lower file nybble bcf File, 0 ; Clear lower file nybble swapf File, f ; Temporarily swap nybbles to combine iorwf File, f ; Combine nybbles swapf File, f ; Swap back nybbles ENDM ; Call function if carry is set CALLC MACRO Function skpnc call Function endm ; Call function if no carry CALLNC MACRO Function skpc call Function endm ; ; Load w with literal and call function ; CallW MACRO Function, W MOVLW W CALL Function endm ; Move a literal to file MOVLF MACRO File, Literal MOVLW Literal MOVWF File ENDM ; Move Destfile <- SourceFile MOVFF macro DestFile, SourceFile movf SourceFile, w movwf DestFile endm ; Move Sourcefile -> DestinationFile MOVSD macro SourceF, DestinationF movf SourceF, w movwf DestinationF endm ; Move 16 bit files to 16 Destination file ; i.e. 2 file move. Source and Dest are the low bytes MOVSD16 macro Source16File, Dest16File movf Source16File, w movwf Dest16File movf Source16File + 1, w movwf Dest16File +1 endm ; Move a 16 bit literal to a file MOVLF16 MACRO File, Literal MOVLF File, low Literal MOVLF File +1 ,high Literal endm ; Decrement file and jump to label if non zero djnz macro file, label decfsz file, f goto label endm ; ;Following macros application specific ; ; Check that Bit of Port is hi and stays hi for delay times ; If so Set carry ; Uses counter as register Is_Set_Q macro thePort, theBit, theCnt, Delay, Times local Nxt_Cnt, No_Set MOVLF theCnt, Times Nxt_Cnt btfss thePort, theBit ; Still Set? goto No_Set ; Not set any more CallW Wait10ms, Delay decfsz theCnt, f goto Nxt_Cnt setc ; Bit is still set, carry is true goto $+2 ; Skip nxt instruction No_Set clrc endm ; Check that Bit of thePort is lo and stays lo for delay times ; If so clear carry ; Uses counter as register, Is_Clr_Q macro thePort, theBit, theCnt, Delay, Times local Nxt_Cnt, Is_Set, theEnd MOVLF theCnt, Times Nxt_Cnt btfsc thePort, theBit ; Still clear? GOTO Is_Set ; Set get out CallW Wait10ms, Delay ; decfsz theCnt, f goto Nxt_Cnt clrc ; bit is still clear goto $+2 ; Skip next instruction Is_Set SETC ; Failed to stay lo all the time. endm ; ; Play tone with freq dependant on 'Frequency'and ; for 'Duration' *10ms Tone macro Frequency, Duration MOVLF Freq, Frequency ; Frequecy to use BSF Snd_On ; Start playing sound CallW Wait10ms, Duration BCF Snd_On ; Stop Playing BCF SpeakerPos ; Speaker o/p off to save power endm ; ; Play tone with freq dependant on 'Frequency'and ; for 'Duration' seconds ToneS macro Frequency, Duration MOVLF Freq, Frequency ; Frequecy to use BSF Snd_On ; Start playing sound CallW Wait_S , Duration BCF Snd_On ; Stop Playing endm ; Following Macros are just tests test macro count variable i i = 0 while i < count movlw i i += 1 endm list