Links to all my PIC tips, tricks and 'mini-project' notes
Whilst the mid-range PIC's can tackle many complex and otherwise almost impossible applications with ease, the challenge is to minimise cost by using the cheapest baseline PIC 'whenever possible'. Baseline PIC's can be had for less than 50p each = I purchased many 16F5x chips for between 40 and 50p each (mainly from CPC as 'remaindered' stock in their 'Bargain bin' section).
The even cheaper to use 12F675 (it has an internal OSC) can be found for as little as 20p (in Qty 10pcs, eBay), as can many other PIC's for less than £1 each. These PIC's are so cheap that you will soon start using them 'for everything' (especially as the PIC can often be used in place of a higher cost 'single function' digital chip - such as divider, ADC, PWM generator etc.) !
Buying the PIC in a 'TSOP' package is (sometimes) cheaper than the DIL/DIP package version = and whilst this costs you 10-20p extra for a mini-PCB TSOP-DIP 'converter', if you use a 'bigger' PCB than the PIC TSOP really needs you can mount other devices (resistors, caps, even osc. crystals) on the same board - and make use of the extra 'pin holes' to wire this up to the rest of your circuit
Below is a mix of programming tips and tricks, common circuit tricks and all the 'mini-projects' I've used the PIC for
I hope these details proves as useful to you as it does to me !
Below, click on the '+' to expand 'in place' (includes diagrams/images) or click the title URL (to view/download the text only version).
(-) 0004 Multi byte ADD - (24bit)
3 byte (24bit) ADD
;The PIC ADD instruction adds a register to Accumerlator and stores the result either back in the register or in the Accumerlator. ; Cy and Z flags are set on the result, however the PIC has no 'add with Carry' instruction, which makes multi-byte addition more difficult than it should be. ; ;So, adding 2 values, a and b, in registers, hi,mid,lo bytes, source 'a', destination 'b' ; (using INDF pointers takes longer as we have to INC to aim at each next byte) ADD24 ;subroutine ; 'a' 3 bytes in aRegHi,Mid,Lo are added into destination 'b' 3 bytes (so b=a+b) ; Acc is lost, Cy if last byte add overflows, a is preserved, b is the result COPY aRegLo,Acc ADD Acc,bRegLo ;first add, sets Cy if b overflow Skip nCy ;skip if no carry INCFSZ bRegMid ;CY, inc Bmid - if that results in 'zero' then bMid overflowed DEC bRegHi ;OK, here on nCy or if inc bRegMid did NOT overflow = pre-DEC bHi INC bRegHi ;here on bMid overflow (so overflow == INC, without pre-DEC), but if Hi overflows, too bad ; OK now add the mid bytes COPY aRegMid,Acc ADD Acc,bRegMid ;as before, could Cy Skip nCy INC bRegHi ;inc B Hi, if Hi overflows too bad ; finally ADD hi bytes COPY aRegHi,Acc ADD Acc,bRegHi ;add final byte (overflow exits with Cy) RETURN ; ; Cy is set if the Hi byte ADD overflows, but not if the Hi byte overflows as a result of Cy out of Mid (or Lo) ... ; Total 13 instructions, 14 CLK's (includes 2 Return) ; ; Can you find a quicker way ? ;
This note last modified: 11th Aug 2017 10:54.