If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.
Special Thanks To:
Aaron Holmes
Aaron Wheeler
Adam Horden
Alan Scrimgeour
Andre
Andrew Haynes
Anonymous000
asabase
Austin Weil
barney
Barry
Bert Hickman
Bill Kukowski
Blitzorn
Brandon Paradelas
Bruce Bowling
BubeeMike
Byong Park
Cesiumsponge
Chris F.
Chris Hooper
Corey Worthington
Derek Woodroffe
Dalus
Dan Strother
Daniel Davis
Daniel Uhrenholt
datasheetarchive
Dave Billington
Dave Marshall
David F.
Dennis Rogers
drelectrix
Dr. John Gudenas
Dr. Spark
E.TexasTesla
eastvoltresearch
Eirik Taylor
Erik Dyakov
Erlend^SE
Finn Hammer
Firebug24k
GalliumMan
Gary Peterson
George Slade
GhostNull
Gordon Mcknight
Graham Armitage
Grant
GreySoul
Henry H
IamSmooth
In memory of Leo Powning
Jacob Cash
James Howells
James Pawson
Jeff Greenfield
Jeff Thomas
Jesse Frost
Jim Mitchell
jlr134
Joe Mastroianni
John Forcina
John Oberg
John Willcutt
Jon Newcomb
klugesmith
Leslie Wright
Lutz Hoffman
Mads Barnkob
Martin King
Mats Karlsson
Matt Gibson
Matthew Guidry
mbd
Michael D'Angelo
Mikkel
mileswaldron
mister_rf
Neil Foster
Nick de Smith
Nick Soroka
nicklenorp
Nik
Norman Stanley
Patrick Coleman
Paul Brodie
Paul Jordan
Paul Montgomery
Ped
Peter Krogen
Peter Terren
PhilGood
Richard Feldman
Robert Bush
Royce Bailey
Scott Fusare
Scott Newman
smiffy
Stella
Steven Busic
Steve Conner
Steve Jones
Steve Ward
Sulaiman
Thomas Coyle
Thomas A. Wallace
Thomas W
Timo
Torch
Ulf Jonsson
vasil
Vaxian
vladi mazzilli
wastehl
Weston
William Kim
William N.
William Stehl
Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Registered Member #61
Joined: Thu Feb 09 2006, 05:50AM
Location: Mountain View, CA
Posts: 43
From time to time, you come across useful routines that do all that you need to set up some weird part of the microcontroller (or common part!) that you reference in all of your code. I'm sure they'd be useful to the rest of us; post them in this thread.
This is a fairly standard skeleton, but always helpful to have a pasteable source:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
isr_save_ram UDATA
ISR_STAT RES 01
ISR_BSR RES 01
ISR_W RES 01
reset_vec CODE 0x00
GOTO start
inth_vec CODE 0x08
GOTO isr
intl_vec CODE 0x18
GOTO isr
main CODE
start:
...
isr:
MOVWF ISR_W
MOVFF STATUS, ISR_STAT
MOVFF BSR, ISR_BSR
MOVFF ISR_BSR, BSR
MOVF ISR_W, W
MOVFF ISR_STAT, STATUS
RETFIE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Registered Member #61
Joined: Thu Feb 09 2006, 05:50AM
Location: Mountain View, CA
Posts: 43
Carbon_Rod wrote ...
The microchip forum is the place to start as they have seen it all:
I have been there more than a few times (like when some errata fails to be sent with the app-notes)
I took a look there once, but mostly dismissed it. I'll have to look again.
wrote ...
The problem with ASM is it does not like to port, the code will differ for the P16c, DSPIC, and PIC18LFxxxx.
Many PICs have similar startup sequences if they have the same type of peripheral -- they pretty much just glue the same logic blocks onto the bus, just in different permutations.
wrote ...
Note microchip's "Application Maestro" is free and has good lib docs (even for the ASM auto-code.)
I took a look into that. I have it on one of the machines that I've installed mplab on, and it seems to be horribly out of date and lacking in samples for lots of the parts. Or should I be downloading modules for it separately?
wrote ...
What chip(s) do you use?
When I sample, I usually go after the 18F2550s (FS-USB PICs) since they tend to have just about the right combination of stuff for me.
Registered Member #30
Joined: Fri Feb 03 2006, 10:52AM
Location: Glasgow, Scotland
Posts: 6706
I'm a 16F877 man, myself. I think the code joshua posted is for an 18 series since it uses the TBLRD instruction. It also mentions a "puts" macro which would need to be defined elsewhere.
I do a bunch of PIC programming as part of my job, and I do indeed have a bunch of standard skeleton routines, for things like initialisation, keypad scanning, LCD drivers, and quadrature encoders, that I copy and paste around as needed. I can't post any code here though since it's commercially sensitive.
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
Here is my 8x8 bit multiplication for PIC16xxx, it is only 11 instructions, uses no temporary variables and takes a constant 67 cycles. It is pretty optimal for low resource use, one cycle and one memory location can be saved if mulcnd is contained in W on entry. The basic method can be found in the Microchip application notes, but their implementation is not very optimal.
Registered Member #30
Joined: Fri Feb 03 2006, 10:52AM
Location: Glasgow, Scotland
Posts: 6706
Cool, I always used the Microchip multiply routine that takes 77 cycles or whatever it is. Just one question, what is "movfw", is it a macro you defined somewhere else, or did you mean to type movwf?
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
"movfw file" is what Microchip calls a "special instruction mnemonic" it is identical to "movf file,W" and is accepted by any MPASM compatible assembler.
I try to not specify the destination of an operation with ",W" or ",F" in cases that are obvious then I can easily spot the non obvious cases in the source code and I have less chance of mixing it up.
I find the Microchip assembly language a bit peculiar, but after I made my own system that I find logical I have no problems.
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.