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)
(+) 0005 new PIC 33 instruction set - (macros)
(+) 0006 Binary multiply methods
(+) 0007 8x8 - (multiply)
(+) 0008 8x16 - (multiply)
(+) 0011 Bi color LED driving
(+) 0012 One pin dual LED and button detect
(+) 0013 Input only multi button detect
(+) 001a One pin controls motor Fwd off Reverse
(+) 001c One pin controls 3 relays
(+) 0020 I2C bit banging
(+) 0021 I2C code
(-) 0021 Serial link - (9600 baud)
9600 baud serial transmission Serial transmission (at 9600 baud) When using a PIC with only 4 or 6 i/o pins, even using I2C comms is an 'extravagance'. However, a single pin can be allocated to 'serial transmit'. Further, if 'open collector' mode is used, the 'transmit' line can be shared by other units. Many low-end PIC's come with an internal 4MHz OSC which gives a CPU CLK of 1MHz = 1uS The serial 9600 baud has a 'bit time' of 1/9600 = 104.166r uS. If we use 104 CLK's per bit, the error, over 10 bits, will be less than 2%. Pseudo code The byte transmit routine is called with the 8 bit value to be sent in rTxd The TRIS setting is saved to rTris (the TRIS latch is write only) Bit0 of portA is used as the serial output pin (the value will be set to '0' as the TRIS latch is used as the 'data output' control) In RS232, the frame starts with the 'start bit' (0), then 8 data bits are sent (bit0 is transmitted first) and the frame ends with (at least) one 'stop' bit (1) .. Typically the receiver will 're-sync' on each start bit, so the time between bytes is irrelevant (so long as there is at least 1 stop bit) The transmit sub-routine should make no assumptions about what is happening elsewhere. This means it starts by setting bit0 TRIS Hi (tri-state) then sets PortA b0 Lo (in reediness for the start bit) TRIS Lo (start bit), Prepare Txd b0, wait '104' TRIS b0, Prepare Txd b1, wait '104' TRIS b1, Prepare Txd b1, wait '104' TRIS b2, Prepare Txd b1, wait '104' TRIS b3, Prepare Txd b1, wait '104' TRIS b4, Prepare Txd b1, wait '104' TRIS b5, Prepare Txd b1, wait '104' TRIS b6, Prepare Txd b1, wait '104' TRIS b7, wait '104' TRIS Hi (stop bit), wait '104' Return
This note last modified: 3rd Jun 2017 05:06.