Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Compares and Delays'
2003\03\28@182123
by
Robert O'Robberson
|
Piecing together a small app to test my PICs (PIC16F876)
The first thing I noticed is that the architecture does not
support branch by compare in favor of a skip type instruction.
Similar to:
movlw 'Z' ; ASCII compare value
movwf B ; load b with "compare to" value
movlw A ; move test (A) to w for work
sublw B ; sub B compare value from w
btfsc STATUS, Z ; if not zero, skip goto
goto ZeroIsSet
Is there a way to do these compares in less instructions if one knows what
value will be compared against ahead of time? Just comparing to a set of
three single character ASCII values in upper case. Sort of like a case
statement, but can just flow over into other cases sequentially.
Secondly I wanted to insert a delay into the bit of code below in lieu
of external stimulus to make sure my PIC is functional. The goal would be to
get a blinking delay around a second. I know this is relatively simple but
examples I have found are in picbasic so delay structure is done with a
single command. Still trying to wrap my brain around the instruction set as
it differs wildly from the M8k and HC-11. Running at 4Mhz and any sort of
"hello world" style program will do.
Thanks!
P.S. Incidentally, anyone living in the Northern VA area around Warrenton or
such........there is a Radio Shack going out of business on Route 17 near
Bealeton and all components are 50-75% off including transformers and
motors.
Code Below:
//==========================================
org 0
nop
bsf PORTB, 0 ; Set PORTB.0 low
bsf STATUS, RP0
bcf TRISB ^ 0x080, 0 ; PORTB.0 set as output
bcf STATUS, RP0
Loop
movf PORTA, w ; xfer PORTA.0 to PORTB.0
movwf PORTB
goto Loop
end
_________________________________________________________________
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
2003\03\28@191602
by
Steve Smith
|
Branch_true
movlw .3 ; get test value
subwf fcn_set,w ; test register
leaving result in w (w is trashed)
btfsc STATUS,Z ; see if true
goto next_segment ; then branch to new
location
And the next bit delays
movlw .xx ; delay value
call short ; or long or extra_long
for 8,16,24 bit periods
I keep the following code in a section called "Timer.inc" and call this
at the top of a program the Delay xx requires processor speed to be
defined "CLOCK_RATE EQU 4000000 ; CRYSTAL IS 4.00 MHZ"
to calculate corect delays I believe this macro was by origanally Robin
Abbot (it was in EPE about three years ago).
Regards Steve...
;------------------ DELAY ROUTINE: UNERVISAL ------------
DELAY2 NOP ; PACKING SPACES FOR EXACT
DELAYS
DELAY1 NOP ;
SHORT ; THE TIMER MODULE
IF DEBUG == 1 ; TEST DEBUG FLAG AND WRITE
AROUND
RETLW 0 ; QUICK EXIT IF DEBUG
ELSE ;
MOVWF TIMER ; LOAD WITH CONTENTS OF
W REG
DECFSZ TIMER,F ; DEC TIMER
GOTO $-1 ; IF CONTENTS OF TIMER
IS NOT 0, GO BACK 1 LINE
ENDIF ; PUT IN TIMER
DELAY4 RETLW 0 ; RETURN
LONG
IF DEBUG == 1 ; TEST DEBUG FLAG AND WRITE
AROUND
RETLW 0 ; QUICK EXIT IF DEBUG
ELSE ;
MOVWF GP1 ; SUPLEMENTRY COUNTER
MOVLW 0XF0 ; VALUE FOR SHORT
CALL SHORT ; DO SHORT AS WELL
DECFSZ GP1,F ; DECREASE SUPLEMENTRY COUNTER
GOTO $-3 ; AGAIN TIL FINISHED
RETLW 0 ; EXIT
ENDIF ; PUT IN TIMER
EXTRA_LONG
IF DEBUG == 1 ; TEST DEBUG FLAG AND WRITE
AROUND
RETLW 0 ; QUICK EXIT IF DEBUG
ELSE
MOVWF GP2 ; SECOND ORDER COUNTER
EXLNG_1 MOVLW .255 ; VALUE FOR LONG
CALL LONG ; DO IT
DECFSZ GP2,F ; REDUCE SECOND ORDER COUNTER
GOTO EXLNG_1 ; DO MORE
RETLW 0
ENDIF
;-----------THIS MACRO MAKES EXACT DELAYS FROM 0 TO 186420
INSTRUCTIONS------
DELAY macro Cyc
LOCAL Nx
SmallCyc=Cyc
IF (SmallCyc<8)
IF (SmallCyc&1)
NOP
SmallCyc-=1
ENDIF
WHILE (SmallCyc>=4)
CALL DELAY4
SmallCyc-=4
ENDW
IF (SmallCyc==2)
GOTO NX
NX:
SmallCyc-=2
ENDIF
ENDIF
IF Cyc>.775
BIGCyc=(Cyc-.730)
LoopDelay=BIGCYC/.728
MOVLW LOOPDELAY+1
CALL LONG
SMALLCYC=CYC-(.730+LoopDelay*.728+3)
ENDIF
IF(SmallCyc)
LoopDelay=(SmallCyc-3)-5
MOVLW LoopDelay/3+1
CALL SHORT-LoopDelay%3
ENDIF
ENDM
Notes:
Debug equ .0 ; or .1 if the delay is
not required
Timer is a memory location
GP1 is another memory location
GP2 is another memory location
{Original Message removed}
2003\03\28@195510
by
Andrew Warren
|
Robert O'Robberson <spam_OUTPICLISTTakeThisOuT
mitvma.mit.edu> wrote:
> movlw 'Z' ; ASCII compare value
> movwf B ; load b with "compare to" value
> movlw A ; move test (A) to w for work
> sublw B ; sub B compare value from w
> btfsc STATUS, Z ; if not zero, skip goto
> goto ZeroIsSet
>
> Is there a way to do these compares in less instructions if one
> knows what value will be compared against ahead of time? Just
> comparing to a set of three single character ASCII values in upper
> case. Sort of like a case statement, but can just flow over into
> other cases sequentially.
Robert:
MOVF A,W ;W HOLDS THE CHARACTER.
XORWF 'X',W ;CHARACTER = "X"?
BZ ITISX ;IF SO, JUMP.
XORWF 'Y'^'X',W ;OTHERWISE, CHARACTER = "Y"?
BZ ITISY ;IF SO, JUMP.
XORWF 'Z'^'Y',W ;OTHERWISE, CHARACTER = "Z"?
BZ ITISZ ;IF SO, JUMP.
GOTO DEFAULT ;OTHERWISE, IT'S NONE OF THE ABOVE.
Before you ask, "BZ" is a pseudo-op that means "Branch if
Zero"; it's documented in the MPASM User's Manual. "BZ LABEL"
assembles to "BTFSC STATUS,Z / GOTO LABEL".
> Secondly I wanted to insert a delay into the bit of code below in
> lieu of external stimulus to make sure my PIC is functional. The
> goal would be to get a blinking delay around a second. .... Running
> at 4Mhz and any sort of "hello world" style program will do.
MSTMR EQU [ANY REGISTER]
MSTMR2 EQU [ANOTHER REGISTER]
....
MOVLW 250
CALL WAITMS
MOVLW 250
CALL WAITMS
MOVLW 250
CALL WAITMS
MOVLW 250
CALL WAITMS
....
; DELAY APPROXIMATELY X MILLISECONDS (4MHZ CLOCK). ENTER WITH
; NUMBER OF MILLISECONDS IN W (0 = 256).
WAITMS:
MOVWF MSTMR ;1-MSTMR = # OF MILLISECONDS.
WAITMS1:
MOVLW 248 ;2-SETUP TO WAIT 1 MILLISECOND.
MOVWF MSTMR2 ;
WAITMS2:
NOP ;248-WASTE A CYCLE. THIS COULD
; ALSO BE A "CLRWDT".
DECFSZ MSTMR2 ;743-
GOTO WAITMS2 ;
DECFSZ MSTMR ;3*MSTMR-1 -HAVE WE WAITED LONG
; ENOUGH?
GOTO WAITMS1 ; IF NOT, LOOP BACK.
RETLW 0 ;2-OTHERWISE, RETURN.
-Andy
=== Andrew Warren -- .....aiwKILLspam
@spam@cypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
2003\03\29@161907
by
Olin Lathrop
> The first thing I noticed is that the architecture does not
> support branch by compare in favor of a skip type instruction.
> Similar to:
>
> movlw 'Z' ; ASCII compare value
> movwf B ; load b with "compare to" value
> movlw A ; move test (A) to w for work
> sublw B ; sub B compare value from w
> btfsc STATUS, Z ; if not zero, skip goto
> goto ZeroIsSet
True, there are no conditional branch instructions, but this is a
cumbersome way to test whether the value at A is "Z". A more reasonable
method is:
movf a, w ;get the value to check
sublw 'z' ;compare to "z"
skip_z ;is it "z"
goto not_z ;no
;
; The value in A is "z".
;
SKIP_Z is one of my macros that just expands to BTFSS STATUS, Z on the 16
family. I have several SKIP_xxx macros because they make the code easier
to read and avoid the need to think about which way the carry flag gets
set on a subtract and the fact that W is subtracted from the file register
or literal instead of the other way around. The SKIP_WLE (skip if W was
less than or equal to) and SKIP_WGT (skip if W was greater than) macros in
particular save a lot of figuring it out all over again each time. These
and other macros are available in STD.INS.ASPIC at
http://www.embedinc.com/pic.
Note that the PIC 18 family does have some conditional branch
instructions.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2003\03\31@021123
by
hael Rigby-Jones
|
> -----Original Message-----
> From: Olin Lathrop [SMTP:olin_piclist
KILLspamEMBEDINC.COM]
> Sent: Saturday, March 29, 2003 9:18 PM
> To: .....PICLISTKILLspam
.....MITVMA.MIT.EDU
> Subject: Re: [PIC]: Compares and Delays
>
>
> SKIP_Z is one of my macros that just expands to BTFSS STATUS, Z on the 16
> family.
>
>
Not wishing to be rude, but MPASM already has skpz and skpnz macro's. Why
not use the macro's that come with the tool? (i.e. the ones that other
people will already be using).
Regards
Mike
=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to EraseMEpostmasterspam_OUT
TakeThisOuTbookham.com.
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listserv
spam_OUTmitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@022953
by
Reinaldo Alvares
By the way, Do you know why MPLAB 6 shows "skpz" and "skpnz" in red meaning
BAD?
They compile properly and simulate properly too, but the red color makes me
feel uncomfortable!
Regards
RA
----- Original Message -----
From: "Michael Rigby-Jones" <@spam@Michael.Rigby-JonesKILLspam
BOOKHAM.COM>
To: <KILLspamPICLISTKILLspam
MITVMA.MIT.EDU>
Sent: Monday, March 31, 2003 9:09 AM
Subject: Re: [PIC]: Compares and Delays
> > {Original Message removed}
2003\03\31@023615
by
hael Rigby-Jones
|
> -----Original Message-----
> From: Reinaldo Alvares [SMTP:RemoveMEreinaldoalvaresTakeThisOuT
TELIA.COM]
> Sent: Monday, March 31, 2003 8:30 AM
> To: spamBeGonePICLISTspamBeGone
MITVMA.MIT.EDU
> Subject: Re: [PIC]: Compares and Delays
>
> By the way, Do you know why MPLAB 6 shows "skpz" and "skpnz" in red
> meaning
> BAD?
> They compile properly and simulate properly too, but the red color makes
> me
> feel uncomfortable!
> Regards
> RA
>
What version are you using? 6.13 seems to colour all the standard macro
instructions properly.
Regards
Mike
=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to TakeThisOuTpostmasterEraseME
spam_OUTbookham.com.
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistserv
TakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@025237
by
Reinaldo Alvares
Version 6.10, I haven't had any magic cookies or something like that. That's
why I haven't upgrade, but I'll try the 6.13 version. Thanks
Regards
RA
----- Original Message -----
From: "Michael Rigby-Jones" <Michael.Rigby-JonesEraseME
.....BOOKHAM.COM>
To: <EraseMEPICLIST
MITVMA.MIT.EDU>
Sent: Monday, March 31, 2003 9:34 AM
Subject: Re: [PIC]: Compares and Delays
> > {Original Message removed}
2003\03\31@025446
by
Jinx
> By the way, Do you know why MPLAB 6 shows "skpz" and "skpnz"
> in red meaning BAD?
You can change colours using Edit/Properties. Make BAD the
same as GOOD if you like
> They compile properly and simulate properly too, but the red color
> makes me feel uncomfortable!
> Regards
> RA
I think I'd trade a little discomfort for a successful compile. There
are times when maybe you'd want your attention drawn to a pseudo-
opcode like bnz that compiles to two instructions if space or timing
is important
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseME
EraseMEmitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@032159
by
Reinaldo Alvares
I downloaded version 6.13 and it displays the right colors. Thanks everyone
for your time.
Regards
RA
{Original Message removed}
2003\03\31@084647
by
Olin Lathrop
>> SKIP_Z is one of my macros that just expands to BTFSS STATUS, Z on the
>> 16
>> family.
>>
>>
> Not wishing to be rude, but MPASM already has skpz and skpnz macro's.
> Why
> not use the macro's that come with the tool? (i.e. the ones that other
> people will already be using).
I wrote mine before MPASM had these, or at least before I heard about
them. I know people have mentioned them here, but I still can't find any
reference to them in the latest "MPASM User's Guide with MPLINK and MPLIB"
(DS33014G). I feel uncomfortable using features that are not documented.
In any case, I've got way too much existing code to change now.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUT
KILLspammitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@101217
by
Scott Dattalo
|
On Mon, 31 Mar 2003, Olin Lathrop wrote:
> >> SKIP_Z is one of my macros that just expands to BTFSS STATUS, Z on the
> >> 16
> >> family.
> >>
> >>
> > Not wishing to be rude, but MPASM already has skpz and skpnz macro's.
> > Why
> > not use the macro's that come with the tool? (i.e. the ones that other
> > people will already be using).
>
> I wrote mine before MPASM had these, or at least before I heard about
> them. I know people have mentioned them here, but I still can't find any
> reference to them in the latest "MPASM User's Guide with MPLINK and MPLIB"
> (DS33014G). I feel uncomfortable using features that are not documented.
> In any case, I've got way too much existing code to change now.
When comparing hex files for MPASM and gpasm I was surprised to discover
that the SKPXX macros were not supported for 18F family in the versions of
MPASM distributed with pre 6.0 MPLAB. In the pass, I've seen the macros
defined in two places: the "MPASM and MPLINK PICmicro Quick Reference
Guide" (DS30400E) and in the MPASM help under MPLAB. In the reference
guide, the macros are described in the section titled "12-bit/14-bit Core
Special Instruction Mnemonics". Conspicuously absent is '16-bit'. AFAICT,
the macros are intentionally not defined for the 16-bit cores. I doubt
this fact is mentioned in the 14-bit to 16-bit transition guide.
When it's important for me to have source that can be assembled by gpasm
and MPASM, I added this to my Makefile:
# gpasm programs
ASM = gpasm --define GPASM=1
Later on I have this:
$(PROJECT).cod: $(SOURCES)
$(ASM) $(PROJECT).asm
In the source, I have this:
ifndef GPASM
MESSG "defining standard macros for MPASM"
include "mpasm.inc"
endif
The mpasm.inc file looks like this:
==================================================================
;sigh... What was microchip thinking. Mpasm for the 18f parts no
;longer includes the common macros:
CLRC macro
BCF STATUS,C
endm
SKPNC macro
BTFSC STATUS,C
endm
SKPC macro
BTFSS STATUS,C
endm
SETZ macro
BSF STATUS,Z
endm
CLRZ macro
BCF STATUS,Z
endm
SKPZ macro
BTFSS STATUS,Z
endm
SKPNZ macro
BTFSC STATUS,Z
endm
SKPDC macro
BTFSS STATUS,DC
endm
SKPNDC macro
BTFSC STATUS,DC
endm
==================================================================
Scott
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuT
spammitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@153549
by
Andrew Warren
|
Olin Lathrop <EraseMEPICLISTspam
spamBeGonemitvma.mit.edu> wrote:
> > Not wishing to be rude, but MPASM already has skpz and skpnz
> > macro's. Why not use the macro's that come with the tool? (i.e.
> > the ones that other people will already be using).
>
> I wrote mine before MPASM had these, or at least before I heard
> about them.
They've been in the Microchip assembler since long before it was
even called MPASM.
> I know people have mentioned them here, but I still can't find any
> reference to them in the latest "MPASM User's Guide with MPLINK and
> MPLIB" (DS33014G).
Look harder. They're documented in Table B.11, on page 185.
They're also documented in the MPASM.HLP file; click Instruction
Sets, 12-Bit Core Instruction Set, 12-Bit/14-Bit Core Special
Instruction Mnemonics.
-Andy
=== Andrew Warren -- RemoveMEaiwKILLspam
cypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservSTOPspam
spam_OUTmitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@181221
by
Olin Lathrop
> Look harder. They're documented in Table B.11, on page 185.
Thanks, I never noticed that table before. I wasn't expecting new
information to be in a "Quick Reference" section. I've always used the
PIC data sheet for the instruction reference. It's also interesting to
note that LCALL and LGOTO are only listed but their description is
missing. It again doesn't make me feel comfortable about using them.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspam
EraseMEmitvma.mit.edu with SET PICList DIGEST in the body
2003\03\31@182428
by
Sean Alcorn - PIC Stuff
On Tuesday, Apr 1, 2003, at 09:11 Australia/Sydney, Olin Lathrop wrote:
>> Look harder. They're documented in Table B.11, on page 185.
>
> Thanks, I never noticed that table before. I wasn't expecting new
> information to be in a "Quick Reference" section. I've always used the
> PIC data sheet for the instruction reference. It's also interesting to
> note that LCALL and LGOTO are only listed but their description is
> missing. It again doesn't make me feel comfortable about using them.
You didn't learn something from the list did you Olin? :-)
Just curious, as it is April 1st down here after all!
Sean - Running back down into my bunker!
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservspamBeGone
mitvma.mit.edu with SET PICList DIGEST in the body
'[PIC]: Compares and Delays'
2003\04\01@005031
by
Steve Smith
|
Careful u will b olinized..................................... (l@@k
loadz a periodz)
-----Original Message-----
From: pic microcontroller discussion list
[EraseMEPICLIST
EraseMEMITVMA.MIT.EDU] On Behalf Of Sean Alcorn - PIC Stuff
Sent: 01 April 2003 00:24
To: @spam@PICLIST@spam@
spam_OUTMITVMA.MIT.EDU
Subject: Re: [PIC]: Compares and Delays
On Tuesday, Apr 1, 2003, at 09:11 Australia/Sydney, Olin Lathrop wrote:
>> Look harder. They're documented in Table B.11, on page 185.
>
> Thanks, I never noticed that table before. I wasn't expecting new
> information to be in a "Quick Reference" section. I've always used
> the PIC data sheet for the instruction reference. It's also
> interesting to note that LCALL and LGOTO are only listed but their
> description is missing. It again doesn't make me feel comfortable
> about using them.
You didn't learn something from the list did you Olin? :-)
Just curious, as it is April 1st down here after all!
Sean - Running back down into my bunker!
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us! email
spamBeGonelistserv
KILLspammitvma.mit.edu with SET PICList DIGEST in the body
--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestspam_OUT
mitvma.mit.edu
>
More... (looser matching)
- Last day of these posts
- In 2003
, 2004 only
- Today
- New search...