logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Using the PIC for everything

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)

(+) 0028 RS422 RS485 drive with one PIC pin

(+) 0030 D to A conversion - (R2R DAC)

(+) 0031 Ternary DAC - (R3R)

(+) 0032 Hybrid ternary bit conversion - (code)

(+) 0035 Pulse Width Modulation - (PWM)

(+) 0040 Gearing axis sensor

(+) 005a TYC50 AC motor details



(-) 0061 16F54 2char month map - (VTI)


The 16F54 2 character font

There is insufficient space available in the 16F54 for a full 3 character month font, even if we 'substitute' 1 for l and 0 for O.

However, a 2 character month can still be understood and requires only 16 characters be defined:-

Ja, Fe, Mr, Ap, My, Jn, Jy, Ag, Sp, Oc, No, De

a A c D e F g J M n N o O r S y = 16 char maps (112 Table entries)

Adding the 10 numeric maps, we need a total look-up-table of 26x7 = 182 (leaving 74 to do the look-ups, plus an extra 7 if we use 0 for O))


Using 'all caps', we can further reduce the count :-

JA, FE, MR, AP, MA, JN, JY, AG, SE, OC, NO, DE

A C D E F G J M N O R S Y = 13 char maps (91 Table entries)

Looking up the bit maps

To go from the Month number to a Month character string 'codes' requires another table, however so long as we keep the charter 'count' to 16 (or less) this requires only 12 entries (since looking up the month number returns 2 characters in a single byte at 4 bits per character).

Note that, the shape pixels required are those for the 'current' scan line. To avoid a 'multiply' during shape look-up, the Table is held in 'scan line' order.

This means that the 'scan line' register will hold the look-up-table base address (rather than a simple 0-6 count) - at the end of each scan line we 'add' the offset to the next table base to the current 'scan line' (base address) register (rather than just 'incrementing' it)

We will need to 'detect' the end of the 'insert' sequence. The 'easy' way to do this is to reorganise the tables so the 'top' scan line is held at the highest location and thus uses the 'top' offset. As each scan line os output, we SUBtract an offset from the ScanLine register. After outputting 6 lines, on the 7th the ScanLine register will reach zero and on the '8th' it will underflow allowing us to use CY to detect the 'end of the insertion' sequence

Of course this means the shapes are split into 7 look-up-tables, one for each scan line (i.e. 'top lines for all chars', then '2nd lines for all' and so on, rather than 'char0 all lines', 'char1 all lines')

To do the shape look-up, we load the character code to the Acc and CALL the look-up-table. This adds the ScanLine (offset to table base address) to the Acc and then adds the result to PCL, so a jump is performed into the look-up-table (where a RET with shape pixels in Acc is performed).


getMchar: ; Call here to look up a shape for the current scan line and return the bit map in m10s / m1s registers ; NOTE, this routime loads the first char into m10s, but the main line code has to perform a 'COPY Acc,m1s' ;   (to save the second char pixels) ; Mreg = a date count register, holding the month number as a binary value (0-11) ; ScanLineBase is the base address offset into the table for the current scan line ; ; start by getting the char code for the current month CALL getMcode ;get 2 number value for month characters COPY Acc,m1s ;use m1s as a temp reg AND 0x0F,Acc ; mask off hi bits (= second char) CALL getMpixels ; get map for this char COPY Acc,m10s ; save the map ; now do the second char NIBswap m1s,Acc ; get the hi value into the lo bits AND 0x0F,Acc ; mask off hi bits JUMP getMpixels ; exit via the table look-up ; NOTE, on return, the main line code has to perform a 'COPY Acc,m1s' to save the pixels ; getMcode; ; LUT to get code for current Month ; note the codes are held 'backwards' because the 'low nibble' will be processed first Copy Mreg,Acc ; ADD Acc,PCL ; RET 'aJ' RET 'eF' RET 'rM' RET 'pA' RET 'yM' RET 'nJ' RET 'yJ' RET 'gA' RET 'pS' RET 'cO' RET 'oN' RET 'eD' ; ; getMpixels: ; LUT containing the character pixel maps in scanline order ADD ScanLineBase,Acc ;add the scan line (table base) ADD Acc,PLC ; jump into pixel table RET (top scan line, char a ) RET (top scan line, char b (or whatever)) ... RET (2nd scan line, char a ) .. RET (last scan line, char a )
Total low address instructions required :-
getMchar = 8
getMcode = 14
getMpixels = 2 + (16 x 7) = 114
Total 136

The numeric look up will be about 90, so we have (256 - 136 - 90) = only 30 'spare' locations


The 0-O substitution

By combining the character and numeric bit-map Tables, and overlapping the end of character with start of the numeric table it should be possible to save at least 8 low space locations (we save 7 from not needing to store 'O', and another 2 for not having a separate Table, but it 'costs' at least one instruction to 'offset' the numeric look-up into the combined Table)

This note last modified: 8th Mar 2016 10:29.

[top]

(+) 0062 DDmmmYYYY character map - (VTI)

(+) 1000 PIC16F684 tips and tricks

(+) 2000 18Fx tips and tricks

(+) 6500 18Fxx data Table output - (max rate)

(+) 6501 18Fxx Return with value LUT - (max rate)

(+) 6502 18Fxx extended instruction data output - (max rate)

(+) 6530 simple data transmission

(+) 6540 Using RS485

Next subject :- index

[top]