![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
I'm just starting to ween myself away from the Parallax assembler.
But I do miss many of the shortcuts. Example in the Parallax assembler the mov instrutiction was simplified. Although not as versitile as Microchips movlw & movwf commands it did have the advantage of making a listing both shorter and more readable (IMHO) Code:
movlf macro x,y ;move literal to file register W = literal
movlw x
movwf y
endm
Any suggestions, do you have a favorite PIC macro?
__________________
Bill Home of the Firefly PIC Tutor Inchworm ICD2 http://www.blueroomelectronics.com |
|
|
|
|
|
|
(permalink) |
|
Most macros that I use are the built in ones (banksel). But I do have made few myself. One can use:
Code:
@TABLE macro const @MOVLF TBLPTRL, LOW const @MOVLF TBLPTRH, HIGH const @MOVLF TBLPTRU, UPPER const endm PS: I use the '@' sign for all macros, to remind me it is not a function name. Sometimed I accidentally may place a 'CALL macro_name' instead just 'macro_name' leading to erratic (understandable) behaviour. Such error is sometimes hard to track as MPLAB doeasn't issue an error/warning.
__________________
"I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! |
|
|
|
|
|
|
(permalink) |
|
What is IF? ... else ...endif ? as it pertains to PIC assembly?
sorry for the look of the code its impossible to copy and paste from a .lst file without getting the line numbers ect.. i got this from DS00594B from microchip. although there were were comments in the rest of the code , there were none for the If else endif statements. ps i understand the use of( if else and endif) , but did not know it could be used in PIC programming.. Code:
00000001 00040 PICMaster EQU TRUE ; A Debugging Flag
00000001 00041 Debug EQU TRUE ; A Debugging Flag
00000001 00042 Debug_PU EQU TRUE ; A Debugging Flag
T1OVFL
BCF PIR1, TMR1IF ; Clear T1 Overflow Interrupt Flag
if (PICMaster )
MOVF DUMMY_PD, W ;
else
MOVF PORTD, W ;
endif MOVWF DC_HI ;
if (PICMaster )
MOVF DUMMY_PE, W ;
else
MOVF PORTE, W ;
endif
MOVWF DC_LO ;
if (PICMaster )
MOVF DUMMY_PB, W ;
else
MOVF PORTB, W ;
endif
|
|
|
|
|
|
|
(permalink) |
|
Those are just Assembler commands (Conditional assembly).
For example: Code:
Fosc equ 20 ;This would be in a header file of our project if Fosc == 20 ;This could be in the Delay file for example ;20Mhz code here endif if Fosc == 8 ;8Mhz code here endif More info on this is in the MPLAB help.
__________________
"I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Bill Home of the Firefly PIC Tutor Inchworm ICD2 http://www.blueroomelectronics.com |
||
|
|
|
|
|
(permalink) | |
|
Quote:
Here's what it looks like when you use it; Code:
;
Print " Menu items\n\n\r"
Print " 1 - Set default power-up azimuth\n\r"
Print " 2 - Set default power-up elevation\n\r"
Print " X - Exit, return\n\r"
;
Code:
;
; Print macro - print in-line character string
;
Print macro str ;
local String, P
movlw low String ;
movwf PTRL ;
movlw high String ;
movwf PTRH ;
goto P ;
String dt str,0
P call PutString ; print string
endm
Code:
;******************************************************************
;
; PutString sends a character string through the RS232 port
;
; Entry: setup PTRL and PTRH to string address before entry
; string must be terminated with a 00 byte
;
PutString
call GetTable ; get a table character |B0
andlw b'11111111' ; |B0
skpnz ; 00 byte, last character? |B0
return ; yes, return, else |B0
call Put232 ; output character |B0
incfsz PTRL,F ; increment pointer |B0
goto PutString ; |B0
incf PTRH,F ; |B0
goto PutString ; |B0
;
GetTable
movf PTRH,W ; |B0
movwf PCLATH ; |B0
movf PTRL,W ; |B0
movwf PCL ; |B0
|
||
|
|
|
|
|
(permalink) |
|
Mike, that is a nice Macro
Fortunatelly, with PIC18 there are no problems with paging, so putting strings in ROM is much easier. William, well, I chose '@', I am sure there are more. Just make a few macros and functions and put some special signs at the beginning of their name and just try if compiler whines...
__________________
"I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Yes, strings are much easier on the PIC18 and two characters fit nicely in each table entry 'word'. The PIC18 version macro simply uses a call instruction followed immediately by the in-line string; Code:
;
; _Print macro
;
_Print MACRO str ; print in-line string macro
call PutString ;
db str,0
ENDM
;
Code:
;******************************************************************
;
; PutString - print in-line string via Stack and TBLPTR
;
; string must be terminated with a 00 byte and does not need
; to be word aligned
;
PutString
movff TOSH,TBLPTRH ; copy return address to TBLPTR
movff TOSL,TBLPTRL ;
clrf TBLPTRU ; assume PIC with < 64-KB
PutNext
tblrd *+ ; get in-line string character
movf TABLAT,W ; last character (00)?
bz PutExit ; yes, exit, else
rcall Put232 ; print character
bra PutNext ; and do another
PutExit
btfsc TBLPTRL,0 ; odd address?
tblrd *+ ; yes, make it even (fix PC)
movf TBLPTRH,W ; setup new return address
movwf TOSH ;
movf TBLPTRL,W ;
movwf TOSL ;
return ;
;
Last edited by Mike, K8LH; 23rd September 2006 at 07:08 AM. |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| SIMPLE ADC PROBLEM | neelam29 | Micro Controllers | 2 | 9th March 2006 08:46 AM |