Home

DB038 - Van Ooijen Technische Informatica

image

Contents

1. FL S Loa riz o PTIBAL A ow ue ner p G is gt gt n Lan a a EL mo PLC T2 Ansa ut x d E y a2 0000000 Lic 0000000 APCOCCCCO REcccccee 1234567 301234564 101234567 81234567 RP A LA The central component is of course a PIC 16F887 chip This is the target chip that can be programmed by the user and this chip controls all peripherals The default clock source for the PIC is a 20 MHz resonator but the PCB can instead accommodate a crystal and its two accompanying capacitors the capacitors are not fitted when a resonator is used c Van Ooijen Technische Informatica Wouter van Ooijen page 6 of 74 DB038 A PIC experiments board version 2 00 The PICs reset circuit contains a reset switch and a few resistors that prevent damage when the reset switch would be activated while the chip is being programmed The reset switch is located above the PIC at the right edge of the LCD connector Resistor R50 pulls the MCLR line high This is not needed for a 16F887 which has an internal MCLR pull up but it is needed for some other PIC chips The RB6 and RB7 I O pins are used to program the chip The peripherals and connectors are separated from these two lines of the PIC and the programming circuit by 1kO series resistors to guarantee the programming function The RB4 and RB5 pins are pulled down by the resistor network of the video interface p 29 to prevent enabling of the LVP function which could cause
2. This function displays the specified pattern on the LEDs for the specified time Each bit in the leds parameter corresponds to one LED the LSB corresponds to the rightmost LEDS A LED is on when the corresponding bit is high void display show unsigned char n unsigned char d unsigned char milliseconds This function shows pattern d on the seven segment display n 0 3 O is the rightmost display for the specified time The pattern d can be composed by OR ing or ADD ing values from SEGMENT A SEGMENT DP or by calling the function seven see below void displays leds show unsigned char d0 unsigned char dl unsigned char d2 unsigned char d3 unsigned char leds unsigned char milliseconds This function shows the specified patterns on the four displays and the LEDs for the specified time unsigned char seven from nibble unsigned char x This function returns the seven segment pattern corresponding to the value of the lower 4 bits of the parameter x c Van Ooijen Technische Informatica Wouter van Ooijen page 56 of 74 DB038 A PIC experiments board version 2 00 void display hexadecimal show unsigned int value unsigned char points unsigned char leds unsigned char milliseconds This function shows the specified integer value on the seven segment displays in hexadecimal format and the pattern leds on the LEDs for the specified time The lower 4 bits of the parameter points specifies whi
3. version 2 00 n Depending on the value of REO RE2 various on board peripherals can drive pin RAO RA1 and RA2 Better not use these three pins externally Read keypad column 3 RAZ REO RED 0b110 H6 0b111 H7 Not used RA3 Output RA5 Output E line of the LCD The LCD might show garbage otherwise OK A A A A RA7 RBO Pins RBO RB7 default to analog RB2 Composite video output also serves as weak pull RB5 Output down to prevent inadvertent activation of LVP c Van Ooijen Technische Informatica Wouter van Ooijen For chips with LVP function the LVP pin must not be driven high during reset these pins have a page 8 of 74 DB038 A PIC experiments board version 2 00 RB6 Output HVP Programming interface pins will be driven by RB7 Output the on board programmer during programming 1k series resistors between the pins and the I O connectors to ensure programmability Tweak pull downas pull down as part of the composite video circuit otherwise OK Will be driven by the on board programmer during programming otherwise OK Output __ Motordriver_ The motor driver RCI Output J might be activated no RC2 Output problem if the motor RC4 Output RS output 0 0 00 0 Ros output Asynchronous serial output to FT232RL second USB Input Asynchronous serial input from FT232RL sec
4. ea Ra a RD m a AE dei RD Bop A RD z IR ES a Teia dur C CI 23 unnn 00000 E TA i AS 0000 de FITTO PIJ 01234567 20123 45674401 C The multiplexer outputs HO H5 are connected to an ULN2981 high side driver When an input of this driver is made high the corresponding output will be high too The reverse is not true if the input is low the output will not be low it will effectively be disconnected An ULN2981 can only source current not sink One output of the ULN2981 drives an IR LED The other outputs drive the common sides of four seven segment displays and a set of 8 LEDs The low side of these displays and LEDs are via 220 series resistors driven directly by the 16887 output pins RDO RD7 The contrast of the seven segment displays can be improved by putting a yellow sheet of semi transparent plastic on top of them 2 9 2 Software interface IR LED The IR LED is activated by making pin RA2 an output and high pins REO RE2 outputs and the value on these pins 0b011 Once this value has been set on pins REO RE2 the IR LED can be turned off and on by making pin RA2 low LED off and high LED on c Van Ooijen Technische Informatica Wouter van Ooijen page 20 of 74 DB038 A PIC experiments board version 2 00 RA2 High gt LED on Low gt LED off REO RE2 0b101 2 9 3 Software interface Eight LEDs The eight LEDs are activated by making pin RA2 an output and high pins REO RE2
5. 3 3 Arithmetic and logic instructions The monadic one operand instructions operate on the content of a memory location specified in the instruction The result can be stored either in the memory location or in W These instructions include increment decrement rotate left rotate right swap nibbles and move INCF a W INCF a F DECF a W DECF a F Note the rather peculiar instruction MOVF a F This instruction copies the content of a memory location to that same memory location Its only useable effect 1s that it sets or clears the Z flag depending on whether the content is zero or not The dyadic two operand arithmetic instructions have two forms The first form 1s like the monadic instructions It operates on a memory location specified in the instruction uses the W register as second operand and can store the result either in the memory location or in W The second form operates on an 8 bit constant uses the W register as second operand and stores the result in the W register The arithmetic operations that can be done in both forms are add subtract and or and xor Note that W is the second operand not the first This makes a difference for subtraction only but has confused many people Add and subtract affect all three flags Rotate involves the carry bit The others affect only the zero flag except swap nibbles which affects no flag at all For subtracting the carry flag 1s set when no carry occurs and clea
6. D SIE S R 1 3 i da 1 3 allo EN S EW o Lart Irt lla a aa sal RDA DI 4 e e e BAT54 na CONTRA 1x16 GND GND R72 2k2 R70 R71 2k2 R69 2k2 2k2 A 64 65 G n T GND GND GND GND a SIN gt N Eh LO 5 N 5 N DA SIN gt N T T 3 3 9 9 Us alls a w of fy a RJ 6 6 PCB x v al lo lo al lo za ars 100 Ma L OL x w n 2 OUT H6 aTa x ATA QqQ TO ATA e 3 m Oo o 1H am a E do B nuo s zn ds cres Fs Lo pg F7 CE o Es j i ie x5 rc U IR NOD per CON21 E 33 E DSxxxx GND 2u2 Go an 1C8 IC11 1C15 LM335 TL 431 lu TSOP 1737 GND SLA sale ES pa ade A GND GND GND GND GND GND varlous peripherals c Van Ooijen Technische Informatica Wouter van Ooijen page 72 of 74 DB038 A PIC experiments board version 2 00 8 7 H bridges and external power PF1 polyfuse 2A 1N4004 1N4004 external pover 9 18U DC external power GND CON4 pin 1440000 V MOT dual motor driver 41030 C19 C20 470u 100n 100n 00 YO LU IA O Il L Oo oO X 63 GND 6 8 Audio interfaces gt N in e T o ga Rod CON22 e e OO fx sil Lx 10k I E E gt 220 k ack PCB uw E EE R64 audio jac O ga R53 LM358 SMD ae LSP SMD e Es 2 R30 5 IC96 2
7. on mini lH g 5 IC9G 2 qa Ra iI SE c He o f LSP1 Ei RI LM358 bo m c R63 L1 220k GND A small loudspeaker is located to the left of the PIC 16F887 The lowest connector at the left side is an audio output jack connector When a jack is inserted into the audio output connector the on board loudspeaker will be disabled note the silkscreen on boards 1 05 erroneously identified this connector as Mic The multiplexer output G2 is filtered by a simple RC filter and fed to the audio out connector When a sufficiently high PWM frequency is used the RC will filter it out the 3dB frequency is 16 kHz Alternatively the PIC s output can be toggled within the audio frequency range to produce a square wave directly When the audio output connector is not used the output of the RC filter is connected to the OpAmp half of an LM358 dual OpAmp its output fed to a small on board speaker 2 14 1 Software interface LSP The Loudspeaker receiver is addressed by making pins REO RE2 outputs and the value on these pins 06010 and pin RAl a digital output RA1 Digital output The LSP signal follows this pins after being filtered with a 16 kHz cutoff frequency REO RE2 0b010 c Van Ooijen Technische Informatica Wouter van Ooijen page 27 of 74 DB038 A PIC experiments board version 2 00 2 15 Audio input connector DAN E LO e e d gt alle ale E ATA eT
8. CD4051 SMD 201 N ol s BAT54 omron omron omron omron Y TN pna SH pr SH2 pa SUI pr SHa 1 3 1 3 1 3 1 3 e D5 2 A 2 A 2 2 RDA DI GND BATS4 R72 2k2 R70 R24 00 2k2 R69 2k2 2k2 a 64 65 G6 G7 o Cc GND GND GND GND a Gr J y S 4 f gt UT2 B tti s J sue c gt The 16F887 pins RDO RD3 can via the diodes D5 D8 drive one row of the left side of the keypad matrix high The multiplexer outputs G4 G7 can be read to determine whether a switch on that row is pressed The common side of the G multiplexer has a weak pull down to make sure that a 0 will be read when no key is pressed Connector CONS can be used to connect an external 4 x 4 keypad parallel to the on board keypad 2 18 1 Software interface keypad A single row of the 4 x 4 keypad is activated by making one of the 16F887 pins RDO RD3 output and high and the other three low or input Pin RDO corresponds to the lowest row 0 8 D etc A column is selected by making pin RA1 a digital input and pins REO RE2 outputs and the value on these pins 0b100 for the leftmost column 0b101 for the next column etc Pin RA1 will read Ob1 when the switch at the selected row and column is pressed ObO when it is not The pull down provided by R65 220kQ is weak Hence a small delay must be observed between setting the REO RE2 and RDO RD3 outputs and reading the RA1 input A delay of 10 us should be s
9. When the F or W is omitted the assembler uses a default always forget what it is if you don t consider that a reader of your software probably will so it is advised always to specify the target explicitly MPASM the Microchip assembler can be used in two modes absolute or relocatable Absolute mode translates a single assembly source file which can use textual include include to include other library files Relocatable mode can use multiple source files and uses a linker script to determine to direct the c Van Ooijen Technische Informatica Wouter van Ooijen page 35 of 74 DB038 A PIC experiments board version 2 00 placement of code and data in the PIC address ranges The presence of a linker script in the list of project files selects relocatable mode the absence selects absolute mode 3 2 Data load and store There MOVLW instruction loads the W register with a literal The MOVWF instruction saves the W register to a memory location These instructions do not affect the flags The MOVFW instruction that loads the W register from a memory location 1s technically an arithmetic instruction it affects the zero flag and its destination can be either the W registers or the memory location The CLRW instructions clears the W register the CLRF instruction clears a memory location Both set the zero flag VW e MOVWF a FE MOVE a W m Note that the assembler accepts MOVFW a as synonym for MOVF a W
10. LS CON23 220k seen o C xa 5 to SS R64 SS C H R59 2 LM358 SMD M Ca me IS 2 10k audio Jack PCB 3 1k 1c96 1 R60 Ed 10k oye jd B do M A PE Sus g Sie Sus T4 ir e gt 33 E C 9 NASA E X d y T H ULP M DC gt Dan E The second connector counting up from the bottom left side is a microphone input jack note the silkscreen on boards lt 1 05 erroneously identified this connector as Lsp The microphone signal is amplified 22 times by the OpAmp second half of the LM358 The OpAmp output is connected to the multiplexer pin F2 A 10kQ resistor provides power to the audio input as required by an electret microphone 2 15 1 Software interface audio input The Loudspeaker receiver is addressed by making pins REO RE2 outputs and the value on these pins 0b010 and pin RAO an analog input Analog input This pin follows the amplified analog input REO RE2 Outputs 0b010 c Van Ooijen Technische Informatica Wouter van Ooijen page 28 of 74 DB038 A PIC experiments board version 2 00 2 16 Composite video output connector DAN 3 RE T4 9 a sii TT es GF ius 2 DOLO 22k mco a ami 0 0 0 Cl a _ SR pei iis RB4 zm il ZZ R48 ol s Oe ae M CD S o S sd LO CY Exe e 0 Zz U The middle connector at the left side of the board is a composite video output connector The PIC16
11. PSA SD o o 3 ob c o 4 6 ET A A S E E 5 2 Lod E 2 JAE 0000 ODO 234567 4 aa n a B 5 gt o Outputs of two multiplexers are used as PS 2 lines 47 Q series resistors provide a minimal protection against hardware and software errors and help to damp ringing when longer lines are used 2 2 kQ pull up resistors are provided as required by a PS 2 interface male ESL 6 reserved _ The PS 2 connector accepts a standard miniature DIN PS 2 keyboard or mouse The connector has pins for ground 5V serial data and serial clock The PS 2 connector is physically and logically equivalent to the I2C connector so it could be used as second I2C connector or vice versa Note that PS 2 as used here means the mini din plug as first used by the IBM PS 2 personal computers for keyboard and mouse It has nothing to do with the PlayStation 2 often abbreviated as PS2 2 10 1 Software interface PS 2 The PS 2 interface is activated by making pins RAO and RA1 inputs and pins REO RE2 outputs and the value on these pins 0b000 The PS 2 protocol must be implemented in software Make these pins digital inputs before the selector REO RE2 is set to 0b000 Set the c Van Ooijen Technische Informatica Wouter van Ooijen page 22 of 74 DB038 A PIC experiments board version 2 00 output value of RAO and RA1 to O but the pins are still inputs Now the PS 2 protocol can be implemented in softwar
12. When the MPLAB simulator 1s used to simulate a program a warning can be issued Most high level language compilers will analyze a program and give a warning or error when it could overflow the stack But assembler programmers are on their own Note that there are no conditional jump instructions as found in most other processors Instead the conditional execution instructions can be combined with a GOTO to create a conditional jump But because all instructions can be executed conditionally GOTO s can often be avoided The RETLW instruction 1s mainly used to create tables of constant data on PICs that cannot read their code memory or to be compatible with such PICs This technique is not discussed here 3 6 Control conditional execution The bit test and skip instructions skip the next instruction when a single bit in a memory location 1s either clear or set A strange omission 1s that the W register is not memory mapped so testing a bit in the W register is more complicated than testing a bit somewhere in memory The status register is memory mapped and mapped into all banks so the bit test and skip instructions can use the status flags Like for the bit set and clear instructions both the address and the bit are constants encoded in the instruction 77 skip next instruction when a b is set BIFSS a b skip next instruction when a b is clear BTFSC a b Skip instructions are often used to skip an instruction depending o
13. e an IR emitter LED e an TCN75 or TCN75A temperature sensor I2C interface compatible with the popular LM75 e room for a DS18S20 temperature sensor Dallas one wire interface but this sensors is not populated e anLM335 temperature sensor analog input e a TL431 2 5 Volt voltage reference analog input e asecond USB interface uses an FT232RL chip to connect to the UART pins of the PIC 16F887 e an LDR analog input e atrim potentiometer analog input e a Dallas one wire interface connector RJ 6 6 connector e a PS 2 connector for connection of a PS 2 mouse or keyboard e anl2C connector e an EEPROM chip I2C interface e a very simple composite video output cinch connector e asmallloudspeaker and a connector for an external PC speaker e amicrophone connector analog input e four Dwarf Bus ML10 connectors with parallel wire cups for the data and power lines except RA4 This wide selection of on board peripherals and interfaces provides a challenge for each programmer novice and guru alike The Introduction section p 6 contains detailed descriptions of each on board peripheral and interface PCLinux software is available from third parties but has not been tested with this board c Van Ooijen Technische Informatica Wouter van Ooijen page 4 of 74 DB038 A PIC experiments board version 2 00 A DB038 board can be programmed from a Windows XP PC using the stand alone PICkit2 programming utility version 1 20
14. potentiometer To read the on board 1kC trim potentiometer pin RAO must be configured as an analog input and pins REO RE2 must be outputs and the value on these pins must be 0b100 The voltage provided by the potentiometer is radiometric it is a percentage of the 5V power supply so when it is measured by the 16F887 using the power supply as reference the actual value of the power supply cancels out c Van Ooijen Technische Informatica Wouter van Ooijen page 17 of 74 DB038 A PIC experiments board version 2 00 Analog value 0 5 Volt nominal proportional to the setting of the trim potentiometer and the 5V power radiometric Do Oj ar gt w 2 8 2 Software interface LM335 analog temperature sensor The on board LM335 analog temperature sensor can be used to provide an analog value to the 16F887 pin RAO that is proportional to the absolute value 10 mV per degree Kelvin To use this function pin RAO must be configured as an input and as an analog input and pins REO RE2 must be outputs and the value on these pins must be 0b110 The analog voltage is absolute it does not depend on the 5V power supply so when itis measured by the 16F887 using the power supply as reference the accuracy of this 5V power supply 596 has a large influence on the measured value To compensate for this the LM431 voltage reference can be read and a compensated temperature can be calculated in software LR A V Ss ES zm IT
15. when you use ASCII values for instance always explicitly specify signed char c Van Ooijen Technische Informatica Wouter van Ooijen page 49 of 74 DB038 A PIC experiments board version 2 00 or unsigned char The size of a double variable is by default 24 bits but a compiler command line option can switch to 32 bits would not feel comfortable if my code depended on this setting because it is not visible in the source Types Size signed or unsigned char 8 bits 1 byte signed or unsigned short int 16 bits 2 bytes signed or unsigned int 16 bits 2 bytes signed or unsigned short long int 24 bits 3 bytes signed or unsigned long int 32 bits 4 bytes GG Float 24 bits 3 bytes Double 24 bits 3 bytes or 32 bits 4 bytes The PIC special function registers are directly available as global C variables You can check the header file at C Program Files HI TECH Software PICC PRO 9 65 include pic16f887 h for the names Bank switching and code pages are handled by the compiler Variables with a const designation are stored in code memory flash There is much more flash in most PICs than RAM so use const whenever you can Variables are automatically placed in all RAM banks but a variable cannot be spread over more than one bank Bit manipulation can be done using the normal C method of or ing or and ing amp with a constant that has only one bit set or cleared as shown for TRISA and PORT
16. 9000 0 0 0 0 Input Analog value of 10 mV per Analog degree Kelvin absolute 2 8 3 Software interface TL431 voltage reference The on board TL431 voltage reference chip can be used to provide a stable and accurate 1 2 500 Volt to the 16F887 pin RAO To use this function pin RAO must be configured as an input and as an analog input and pins REO RE2 must be outputs and the value on these pins must be 0b101 The A D converter of the PIC uses its 5V power as reference for the conversion It is my experience that the 5V as provided by an USB connector can vary quite a bit even within let s say one second Hence when the TL431 is used as a reference to correct an A D measurement to an absolute value both measurements must be done in quick succession c Van Ooijen Technische Informatica Wouter van Ooijen page 18 of 74 DB038 A PIC experiments board NN II UM E A ln NEUE gt 0 2 mr O J x W t PL in ALIS o EA orr E rvu Prao 89 AA Y lo Mee REO RE2 e TN a 9 o x L E gt x a gt f A Ai f A z M C os Y M Li C E M a E 3 o gt 2m Ap ap Ar ALAS a 3 i C n o d s M di jx x5 3 L TM E a0 a LIEU 5 o m E D gt o o gt gt gt al oz p 3 Lng E Op 1 i r4 tw x w A a gt o F z a gt 900000099 11234567 Lo lo 2 8 4 Software interface LDR version 2 00 Input Analog level
17. E dc H 7 2d HO 8 08 10 CC U TU TU TU TU TU TU TU UDN2981 U wo wo wo wo K i L FUN L EUN L L E LO LO LO LO LO LO LO LO Q C3 Ca C3 C Ca C3 C Lu Lul Lul Lu Lul Lul Lul Lul BE 1 1 1 1 y LED11 LED 5mm IR f 4 e a O AP Ni Ni AVA n 1 1 y EN C O a a lt NV x NV NV a Lul ca a SS AS GO LO CO Y RDA M Rte RD gt ps A se LI RD 7 1 pag LU SE ee O ees p RD si 2 EE OOOO a a RD pog 2 E UE i iM l A RD _ po El ME NEEMEMEMMMggae is RD lt A gt o iau RD z i 220 Diodes IR diode 7 segment displays 8 6 Miscellaneous interfaces omr on omron omron omron I3 SW13 71 FTA SW14 2 rm Su15 3 mm SW16 A 1 3 1 3 1 3 1 3 we DATE 3 t 3 d 3 de x RD3 DI 2 4 BAT54 omron omron omron omron BC850 K mm SW9 4 FTA sua LIE su1i d FTA Su12 B 22 i r9 i i i k 1 3 1 1 1 3 RBS r 07 Xt t 3 o aa x oo a RD2 E e BAT54 omron omron omron omron DB4 2k2 oF R Fri SW5 P FF SW6 8 Fri SW7 9 rm SW8 C Bag o 5 2 R 13 1 da 1 23 allo OD R o IT Tte ate at n int RDI Le D ALB 20201 a C R BAT54 omron omron omron omron di o x ma SW1 k ai SW2 0 mai SW3 7 Fai SW4
18. MNM lc pih x File Device Family Programmer Tools Help PIC18F Device Configuration Configuration Word D ee MESSA CC3F 1E3F 0700 00E1 User ID s OxFFFFFFFF COOF EDOF 400F CheckSum Ox44F0 0 ERA OEOF 6EC1 6ACO OEDEMSEB4 9094 808B 0100 0E2C 6F60 DE6C 4 0ES6 6F62 2F62 EF 4 FF FF FF 028 FF FF FF FF FF FF FF FF Y MICROCHIP Programmer USB interface The power enable jumper isin When the power enable jumper is is selected as power the active position left two not active this checkbox must be source pins enabled to let the programmer hardware supply power to the rest of the board The pin header directly below the small red LED allows the user to select the main power source for the board In normal use program development mode this will most likely be the USB programming connection to the PC jumper in the rightmost position When the USB programming connection is used to power the board the programmer will initially disable the power to the target circuit The pickit2 PC application must be used to enable the target power Other power options are the second left USB connector USB virtual serial port or an external Wall Wart or battery The programming signals are fed to the target 16F887 chip but are also available on an RJ connector This makes it possible to use the DB038 to program an external chip This requires that the on board target chip is removed The pinout of the RJ connector is compatible with th
19. TU CE IO INS sintistcsnsdeututeer teat OE sumaaaane in fuod bue eoo aut EO ME TU LU nU ut LO SEAMOS NOE t EUN EET TREES 6 Background information 6 1 7 1 7 2 7 3 7 4 439 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 Dit qmatipulatiOTEs s ee E Control Jump and SubEOULITIG S cuoio annientare Control conditional execution eese eese enne SLEEP the watchdog interrupts NOP n Code memory and code addressing Data memory and data addressing ii 3 10 Instruction timing 3 11 Using I O pins 3 12 Configuration fuses 3 13 The 12 bit core instruction set 3 14 Reflections on the PIC architecture 4 PIC hardware notes and tips 5 Using Hi Tech Lite free C compiler c Van Ooijen Technische Informatica Wouter van Ooijen version 2 00 The RCS infra red remote control protocol 8 Test application 7 Suggested lessons assignments and projectS enne nennen nennen nnne sensns A short course in PIC assembler eee SIMPLES AMES las Intermediate Projecto ui Advanced Projects sa e aa Other suggestions not DB038 SpecifiC rr S Eee Ledo ro anelli NT PIC 16F887 ML10 connectors wire cups een USB PropramMm Mer ae USB SeErakint er deos d isse A TE AE M ltiblexors PS 2 2 Emi AAA A EA ATA LEDs and seven segment displays Miscel
20. band for which the received is designed Hence there are different receivers for 36 kHz signals for instance the TSOP1736 and 38 kHz signals TSOP1738 The figure below shows the 1 0 0 8 ponsitivity 96 0 6 Attenuation as a function of the frequency deviation for a TSOP receiver 0 4 e E Rel Res 0 2 e min f fot5 Af 3 dB fp 10 E 0 0 For optimal performance a receiver of the correct frequency must be used but in practice the band filters in the receivers will accept a nearby frequency with some attenuation The figure below show that a TSOP1736 receiver module will attenuate a 38 kHz signal 38 36 1 06 by 40 the relative responsitivity is 60 so the maximum distance is 77 V0 6 compared to a 36 kHz signal not much to worry about The pictures below show a typical IR receiver module and its internal block diagram Circuit Band Demodu Pass lator c Van Ooijen Technische Informatica Wouter van Ooijen page 60 of 74 DB038 A PIC experiments board version 2 00 The IR receiver module contains an AGC Automatic Gain Control unit that will amplify the incoming signal to a fixed level This works best when the signal is present roughly 50 of the time When the signal present more than 50 of the time or even constant the AGC will recognize is as too strong and turn down the amplification until it seems to be pre
21. battery powered remote control bill i bit bit3 1 bit4 bit5 i bit bit bit bit ibitlD bitl E bit12 bic bitl4 RC5 message format 1 E q gr E g g 1 E g q q q E j 1 j E 1 The black blobs are the 7 IMSB SPIMSB E modulated IR signal D agi T i4 _Adress _4__ommand__ Start bits always 1 An RC5 message consists of a two start bits always 0 a toggle bit a five bit address and a six bit command both MSB Most Significant Bit first The address identifies the type of device TV set CD player etc The command identifies the button 1 2 volume up etc The message is sent repeatedly as long as the corresponding button on the remote is hold down The toggle bit is inverted every time a button is pressed so it allows the receiver to distinguish between a button being pressed rapidly or hold down continuously The table shows the RC5 codes for some common devices and commands buttons An internet search will give you more 0 TV1 16 Audio 1 preamp 1 TV2 17 Tuner Videotext Analog cassette c Van Ooijen Technische Informatica Wouter van Ooijen page 61 of 74 DB038 A PIC experiments board version 2 00 Laser Vision player Adio 2 preamp 25 a 6 8 sam 9 VCRextension 13 Reserved 25 CDwriteable 19 Brightness 24 Treble Balance right Balance left The RCS code has only 5 bits to identity the device An extend
22. datasheet chapter DATA EEPROM and Flash program Memory Control On most recent PICs including the 16F887 the processor can also write to the code memory but such a write halts the processor for a considerable time so 1t 1s not very useful for a normal application This self writing feature is what makes a boot loader possible a program that communicates often with a PC to receive an application program that 1s stored in the remaining code memory so no programmer is needed to load new code This is often used to allow a field service to update the application code 3 9 Data memory and data addressing The PIC documentation calls the data space file registers You could interpret this as stating that the data RAM file and special purpose hardware registers are mapped in the same address space Just like the code space the data space of recent PIC chips is larger than can be specified in an instruction The same trick as for the code space 1s used some bits of the effective address are taken from a fixed location and the programmer must make sure that those bits are set appropriately but in this case the mechanism 1s called register file banking The table below shows how the effective data address 1s constructed effective direct instruction specified address 3 bits from STATUS 7 bits from instruction effective indirect FSR address 1 bits from STATUS 8 bits from FSR Indirect addressing 1s used when an add
23. in your project as needed db038 h Configuration fuses busy waiting I O port shadowing nibble to char db038 c db038 adc c db038 dallas c db038 i2c c db038 keypad c db038 lcd h HD44780 character LCD initialization clear cursor position control char print db038 lcd c string print custom character definition db038 leds h Show values on the seven segment displays and the LEDs db038 leds c db038 string h Character and string functions db038 string c db038 uart h UART initialization character send and receive string send db038 uart c 5 4 1 Basic stuff Header file db038 h Code file db038 c The header file includes the Hi Tech PIC specific include file The C file sets the configuration fuses The C file must always be present in your application The header file is included by the other header files so you can probably don t need to include it explicitly void wait ms unsigned int x This function waits x milliseconds Note that the parameter is an unsigned int 16 bits so the maximum delay is 65 seconds WAIT US x This macro it is not a function waits x microseconds x must be a constant c Van Ooijen Technische Informatica Wouter van Ooijen page 51 of 74 DB038 A PIC experiments board version 2 00 unsigned char PORTA SHADOW void PORTA FLUSH void To avoid read modify write problems all changes to PORTA must be made by first making the change to PORTA_SHADOW after which the ma
24. interface can only be powered by the external battery wall wart connector because its current and voltage requirements exceed what is commonly available from a USB port Main power can be provided by the first USB port programming interface the second USB port serial communication interface or from a wall wart or a batter A battery or wall wart must be 9 18V DC 2 5mm plug centre is positive 200mA for the board itself plus current for any peripherals When the USB programmer is not connected power from the serial USB interface or from the wall wart battery connector as selected by the jumper will be available for the board However when the USB programmer connector is connected the programmer will at startup disable the power to the board until power is re enabled using the PC application c Van Ooijen Technische Informatica Wouter van Ooijen page 14 of 74 DB038 A PIC experiments board version 2 00 2 6 External power U MOT PF1 polyfuse 2A D3 1N4004 ES DI ni KI 1N4004 D4 OE IC10 external power 8 18U DC SLE 7805 I OUT U WW C external pouer F3 i MX C31 C28 SM m e 478u 220 z T RIE TA p H qe sy www 35 Py 4C01 3 LU DOLUS p 1 BET mo 5u13 T4 7 Cox ox ex FOR Or gt BY H w suie s PUT sye LJ o VVS Hn a di 5 D Li EM L 3 ti sa n n LAS The Wall Wart battery power circuit provides power to the board
25. is not even present on the ML10 and wire cups A 4 7 kO pull up resistor is provided Optionally a DS18B20 temperature sensor can be fitted on the board B Not connected 3 Onewiredata Ground 6543 2 1 Not connected Pin numbers looking into a female RJ11 6 Notconnected RJ12 connector as present on the PCB A note on the name RJ11 RJ12 these names refer to two particular uses of the pins of a 6 position 6 connection modular jack Hence both names refer to the same physical plug but both are strictly speaking used erroneously here because the one wire use of this plug is not what either RJ11 or RJ12 describes But the names RJ11 RJ12 are what everyone seems to calls these connectors and plugs so that is how they are called here 2 12 1 Software interface Dallas 1 wire The Dallas 1 wire bus and the optional on board DS18B20 are connected to the PIC pin RA4 This pin is dedicated to the 1 Wire bus it has no other function on the DB 37 board On all Plcs know this pin is an open drain output which is exactly what you need for a 1 Wire bus c Van Ooijen Technische Informatica Wouter van Ooijen page 25 of 74 DB038 A PIC experiments board version 2 00 2 13 IRreceiver 2T EN LE PNE M Li ee eaka ora hahaka n A 2 x SS La M jd b PS apko tt ES oH a 1 allo Lio te a gia fs 7 ETA CTS B ICI s e 25 3 H6 OUT LASA di U IR C27 IC15 u er TSOP 1
26. of 2 5 Volt Analog absolute The on board LDR Light Dependent Resistor visible light sensor can be used to provide an analog value to the 16F887 pin RAO This level will be higher in darkness and lower when the LDR is illuminated To use this function pin RAO must be configured as an input and as an analog input and pins REO RE2 must be outputs and the value on these pins must be 0b101 This analog voltage is radiometric it is a percentage of the 5V power supply so when it is measured by the 16F887 using the power supply as reference the actual value of the power supply cancels out JN LE ery one TA Wim aon Re SL lu NEUES L si Kap S C i ji o LI m Ll Ll 1522 1 A AS UNUN a in em Eu LI a M a os LO suie s oo 411 6 Te mig vesti tg 7 9 c Van Ooijen Technische Informatica Wouter van Ooijen RAO REO RE2 Input Analog value lower with Analog more ambient light page 19 of 74 DB038 A PIC experiments board version 2 00 2 9 Seven segment displays and LEDs 2 9 1 Circuit 5U TTITTTTT N N C OO NI A O1 5 G2 N2 p UDN2981 Ei 220 LED 5mm red LED 5mm red LED x c RR LED6 L LEDS X A A LED 5mm red LED 5mm red LED14 LED 5mm IR ED3 RR LED Smm red oou O lt LED LED2 LED 5mm red L LED1 GND R15 RDA M p Re RD gt x AE ME RD 7
27. only later version do not work or have not been tested A similar program for Linux exists but has not been tested The following additional items might be useful when working with a DB038 board a 12 volt wall wart 200mA for the board more when you use motors type depends on the mains voltage and sockets in your country and or a 12 volt battery a PC loudspeaker set or headphone a PC microphone two standard USB cables A B a cinch to SCART or other suitable cable to make a connection to your TV set and the TV set itself a PC mouse or keyboard only one can be connected at a time an IR remote control 36 or 38 kHz IR frequency most remotes use one of these frequencies a television set that can be controlled by IR two small DC motors DS18S20 and or other Dallas one wire peripherals I2C peripherals A 4x4 matrix keypad In this document the notation Ob is used to prefix a binary value Ox is used to prefix a hexadecimal value Values without are prefix are decimal c Van Ooijen Technische Informatica Wouter van Ooijen page 5 of 74 DB038 A PIC experiments board version 2 00 2 Circuit description and interfacing The DB038 circuit is rather complex so it is discussed piece by piece The full diagrams can be found in the section Circuit diagrams P 69 Part of this complexity is caused by the fact that the 40 pins PIC chip does not have enough pins to dedicate separate pins to each peripheral so only the peripher
28. page 70 of 74 DB038 A PIC experiments board 84 Multiplexors PS 2 I2C version 2 00 33k R o NO LTD IC6 GO 0 RAG 3 RAI 3 G1 RAZ 3 1 G2 2 G3 3 6 6 G4 6 REZ 1 REG 11 G5 REQ 1 5 REA Q REA 10 G6 RE1 a 6 RE2 9 RE2 9 G7 RE2 9 7 DT CD4051 SMD 2 O o e CON28 1 GND GND GND DAN gt IN LO LO 9 9 0 G1 gt I2C 9C AG 0 vo I2C connector o alla PS 2 connector El R5 RE GINGTN GIN T 47 res De 12C SCI i scl PS2 SCI y a PS2 SC vce j 47 GND R7 res Fa I PS2 SDA 12C SDA SDA ps2 sDA 4 47 CON24 xe I2C and PS 2 termination and safety GND GND gt MN LO 100n I2C SDA O 12C SC au E selectors I2C PS 2 M Q Z CO c Van Ooijen Technische Informatica Wouter van Ooijen page 71 of 74 DB038 A PIC experiments board version 2 00 8 5 LEDs and seven segment displays 5U IC14 t 01 2 02 H 3 Ds H4 04 H 5 H
29. pins The seven segment display shows the motor current on the two right side displays raw A D value in hexadecimal After three cycles the test terminates A IR RECEIVE The IR receiver is polled When a signal is received this is shown on the LEDs The two left side seven segment displays count up in hexadecimal mode B KDB UART When a key is pressed its value is shown on the LCD and on the rightmost seven segment display and its transmitted by the UART at 4800 N 1 Each character sent from the PC to the board is echoed to the PC along with its hexadecimal value This test mode can be left by typing a Q at the PC s terminal program or by a reset of the PIC C MIC The microphone input is read and the value is shown on the LEDs in a more or less logarithmic form and on the two right side seven segment displays The normal background noise should light on the rightmost four LEDs Speaking directly into the microphone should light more LEDs Note that on the B01 01 boards the silkscreen marks Mic and Lsp are wrong the microphone connector is next to the cinch video connector D IR REFLEX The IR transmit LED sends an IR signal and the IR receiver is polled When a signal is received the LEDs are lighted Without any IR shielding this will cause the LEDs to always light up use an 8 cm black shrink tube over the send LED to block direct IR light from the LED to the receiver Now when put my hand or another object at 20 cm d
30. the W register The result is either left in the W register or left in the data memory location The processor maintains a status register that reflects the zero carry and digit carry status of the last calculation The digit carry flag 1s useful only for calculations on BCD coded data and is not discussed in this summary The 14 bit PIC instruction set was designed for a maximum of 2048 instructions and 128 data addresses This was sufficient for the first 14 bit core chips but recent chips contain more code and data The 16F887 for instance has 8192 instructions and 512 data locations Code pages and memory banks are used to increase the addressing range of the basic instruction set which complicates the use of the PIC instruction set considerably The datasheet of each PIC chip contains a short description of the instructions set A more in depth description can be found in the Midrange Reference Manual In the instruction tables a represents an address a the byte content of that address n a byte literal b a 3 bit literal a bit number 0 7 and X b represents bit b of X As stated most instructions that calculate a result can leave this result either the data location or in the W register This is indicated by F or W But actually F and W are just pre defined constants 1 and 0 so the assembler accepts strange things like INCF W W which is interpreted as INCF 0 W which is probably not what the programmer intended
31. the keypad which can pull a line high but not low The table below summarizes the functions that are accessed using the multiplexors Note that changing the value on the REO RE2 pins can produce unintended intermediate values Hence it is advised to have the RAO RA2 pins configured as inputs whenever the value on REO RE1 is changed PS 2 connector SCL PS 2 connector SDA High to enable digit 1 I2C connector SCL I2C connector SDA High to enable digit 2 Microphone input Loudspeaker output High to enable digit 3 Battery voltage Not used High to enable digit 4 Potentiometer Read keypad column 1 High to enable LEDs LDR Read keypad column 2 High to enable IR LED LM335 temperature sensor Read keypad column 3 TSOP IR receiver TL431 2 50V reference Read keypad column 4 c Van Ooijen Technische Informatica Wouter van Ooijen Not used page 16 of 74 DB038 A PIC experiments board version 2 00 2 8 Simple analog inputs Potentiometer LDR LM335 and TL431 gt gt gt LO LO LO Fe Alla olla RAQ 3 F1 Tl a Ml x F2 x m CN m N FS 6 F4 Ho REQ A F5 OI 4 S 4 6 7 REA 10 F6 aa a RE2 9 F7 CD4051 SMD gi eae IC8 IC11 LM335 TL431 GND GND GND GND Multiplexer outputs F4 F7 are connected to four analog inputs e a potentiometer e anLDR e anLM335 linear temperature sensor e a L431
32. to limit the current in such a situation put all my chips in a turned chip socket to avoid breaking the chips flimsy legs Some people have reported that when such a combo is put in a breadboard or straight pin socket that board or socket can no longer reliably accept normal chips because the springs have been forced to open too wide c Van Ooijen Technische Informatica Wouter van Ooijen page 47 of 74 DB038 A PIC experiments board version 2 00 The radix base of a literal without an explicit radix specification is determined by an assembler option Hence the only way to make sure that someone else can assemble your program and get the same result is to specify an explicit radix for each and every literal To make sure that you have done so you could assemble with both hex and decimal defaults and check that the produced hex file are the same Some things that appear to be PIC assembler instructions are actually macro s that can generate a number of instructions not necessarily one Funny things will happen when you try to skip such a macro instruction when it has generated more than one instruction you will skip only the first when it has generated zero instructions you will skip the next instruction after the macro c Van Ooijen Technische Informatica Wouter van Ooijen page 48 of 74 DB038 A PIC experiments board version 2 00 5 Using Hi Tech Lite free C compiler 5 1 Introduction The MPLAB installati
33. trouble for the programming function on some PIC chips The green LED in the lower left corner of the board lights up when the target circuit is powered 2 1 2 16F887 pin usage The next table shows how the I O pins of the 16F887 chip are used on the board and the limitations for external use of these pins In general all pins of the 16F887 can be used externally provided that no on board peripherals or connectors are used The exception is RA4 which is not available on the Dwarf Board connectors or wire cups it is available on the Dallas 1 wire connector Beware that using the I O pins in your own way might cause the on board peripherals to act funny The pins RAO RA1 RA2 are multiplexed Their function is set by the value on the pins REO RE1 RE2 The jumper COM28 to the left of the seven segment displays can be removed to disable the multiplexers and hence free the RAO RAT RA2 pins for other uses RA4 connects to the on board socket and the RJ connector both for Dallas one wire chips RA5 connects to the E line of the LCD Pins RB6 and RB7 are connected to the on board programmer and the pins RB4 and RB5 are used to create a composite video output Port C connects to the two H bridge motor driver chips RCO RC5 and to the FT232RL USB to serial interface chip Port D serves three purposes e When RA2 and REO RE1 and RE2 enable the LEDs or one of the seven segment displays a low value on one of the RD pins enables the c
34. two right side seven segment displays and on the LEDs The value that is displayed depends both on the temperature and on the power supply voltage of the PIC At room temperature see values in the range 0x90 Ox9F Heating the LM335 temperature sensor tip of soldering iron should produce higher values for instance up to OxAO The two left side seven segment displays count up in hexadecimal mode 7 TL431 The 8 bit analog value read from the TL431 voltage reference is shown on the two right side seven segment displays and on the LEDs The value that is displayed depends both on the power supply voltage of the PIC A normal value would be 0x7D The two left side seven segment displays count up in hexadecimal mode 8 V EXT The 8 bit analog value read from the external power supply wall wart is shown on the two right side seven segment displays and on the LEDs The value that is displayed depends both on the c Van Ooijen Technische Informatica Wouter van Ooijen page 65 of 74 DB038 A PIC experiments board version 2 00 voltage provided by the external power supply For a 9V wall wart a normal value would be 0x51 for a 12V wall wart Ox7E The two left side seven segment displays count up in hexadecimal mode 9 MOTORS The two motors are driven first each motor separately in each direction then both motors together both in the same direction and in different directions The LEDs show the digital testing of the motor driver
35. voltage reference The potentiometer has a blue thumbwheel Turning the wheel clockwise increases the voltage The potentiometer also functions as a load to the 5V power guaranteeing a quick discharge when the power is removed this is important when an USB cable is removed and quickly reinserted The LDR light dependent resistor is located at the right edge of the board It is connected as voltage divider low light level high voltage high light level low voltage The LM335 temperature sensor is located at the right edge of the board immediately above the LDR It provides a voltage that is linear with the absolute temperature The voltage is 10 mV the temperature in degrees Kelvin or approximately 3 Volt at 25 degrees Celsius The resolution of the 10 bit A D converter with the 5V supply as reference is 5 mV so the temperature can be read with a resolution of 0 5 degree Note resolution not accuracy The inaccuracy of the 5V supply will give a large error Note that the board has another temperature sensor TCN75 or TCN75A that has a digital I2C rather than an analog interface The TL431 voltage reference provides a stable and accurate 196 maximum error 2 5 Volt reference It can be used to correct the inaccuracies of A D conversions caused by using the approximately 5V power as reference This chip is located in the centre of the board to the left of the potentiometer the blue thumbwheel 2 8 1 Software interface
36. when the power jumper is set for this source The connector is a 2 5mm plug centre pin positive The external power source should provide 9 18V DC at 200MA for the board itself plus current for any peripherals When motors are used these will likely require a specific voltage and dominate the current requirement The external power is provided directly to the motor driver circuit The external power source must match the voltage required by the motors and it must be able to provide the current required by the motors Polyfuse PF1 protects against potentially dangerous situations when for instance a high current battery is used and the motors draw excessive amounts of current Regulator IC10 provides a stable 5V power for most of the board Diode D3 protects the regulator when power is applied in reverse Diode D4 protects the regulator against reverse current when C28 is charged but no external power is present The resistor divider R55 R34 provides via a CD4051 multiplexer a fixed part of the external voltage to a 16F887 A D input Hence the chip can with some calculation determine the external voltage which might be convenient when the board is used as free roaming robot powered by a battery 2 6 1 Software interface external power voltage The voltage of the battery or wall wart depending on what is connected can be sensed by the 16F887 To use this function pin RAO must be configured as an input and as an analog input and pins RE
37. with an instruction set that 1s much easier for the assembler programmer for instance the Atmel AVR chips Apart from inertia PICs are popular so the next generation finds the internet full of PIC examples so they will use PICs too which will lead to even more internet coverage for these chips there are three reasons to choose Microchip s PIC chips 1 There is a very wide range of PIC chips too choose from from tiny and primitive 6 pin chips that are no larger than an SMD transistor to 100 pin chips with all sorts of peripherals like Ethernet CAN and USB 2 Microchip has a very good reputation for availability of its products For a manufacturer who designs a product now and hopes to sell 1t for the next 10 years this can be more important than any other argument including ease of use and even price 3 For an assembler programming course one might argue that after mastering the horribly complex 14 bit PIC architecture everything else will be easy Note that these arguments do not apply to all situations For someone who wants to build a one off project now none will matter and he will probably be better off with for instance an AVR or ARM microcontroller or even a PC c Van Ooijen Technische Informatica Wouter van Ooijen page 46 of 74 DB038 A PIC experiments board version 2 00 4 PIC hardware notes and tips The information about a PIC chip is spread over a number of documents e The data sheet of the chip or a rela
38. 1 pe E 47 10k 3 E LSP1 audio Jack PCB 1k 6 ICSG 1 R9 i LM358 SMD H R63 220k R60 L1 10k audio c Van Ooijen Technische Informatica Wouter van Ooijen page 73 of 74 DB038 A PIC experiments board version 2 00 9 External links Microchip website PIC 16F887 datasheet PIC 16F887 errata Pickit2 1 20 firmware Pickit2 1 20 application also contains the user manual MPLAB FT232RL datasheet FT232RL VCP driver CD4051 datasheet 24C01 EEPROM datasheet TCN75 datasheet UDN2981 datasheet DS18520 datasheet TSOP173x datasheet uA7805 datasheet L6202 datasheet LM358 datasheet http www microchip com http ww1 microchip com downloads en DeviceDoc 41291F pdf http ww1 microchip com downloads en DeviceDoc 80302E pdf http ww1 microchip com downloads en DeviceDoc PK2V012000 zi http ww1 microchip com downloads en DeviceDoc PICkit962029620V 1 2 09620Setup EXE http www microchip com stellent idcplg ldcServicezSS GET PAGE amp no deld 1406 amp dDocName en019469 amp part SW007002 http www ftdichip com Documents DataSheets DS FT232R V204 pdf http www ftdichip com Drivers VCP htm http www fairchildsemi com ds CD 2FCD4052BC pdf http www atmel com dyn resources prod documents doc0180 pdf http ww1 microchip com downloads en DeviceDoc 21490C pdf http www allegromicro com en Products Part Numbers 2981 2981 pdf http datasheets maxim ic com en ds DS18S20
39. 4 jaa S L5 AX gum Ll T2 nes T II E SI e dena GND BC850 002 E c24 M 470m m l J E a SR e l E j US C25 dL um a CON27 NI af R se T 20 GND R o R EE R GND R le a GND 5U i TS e Il BC860 RA R R10 o sg e ICSP B6 ks T3 o MCOLR e ICSP B7 vx Lo BC850 R v C ene nt R 47 g IR N Z e R Oo a y CY R45 R46 e 4k7 4k7 e A T4 al a S BC850 CON20 GND ala AZNC CY A ISP BZ Epp 4 GND GND_ GND F 9U oy Su MCLR EMI GND RJ 6 6 PCB external target ICSP connector GND andado andino FOR oad e OE SEUS s pa fieno 10an 18n 100n si ECTS pa a A A rr PE NODO 6 0 0 0 E wg oto 3 120 s EE s se gt PTULECILALEEd Men TITITIT 1 ERE SNAGU NaN w A ydh RARE DETTO R720 4e J ca tio P R68 4 J k er 3 Ed j 3 3 ic 22 em R55 om MIE R6ARSE 3 i j a 10k ik DAV Css eel Ree fi yo T con QU EDT 2 Fa dida Nardi MANE E ee 00 EST LJ n ber 3 60000000 a 6000000 over 01234567 501234567 ig TIE o ZN Suii 6 i IO O RR TIYA s 441171717 A w 141530417 1171 mig The on board programmer uses the second USB connector counted from the left Most of this circuit is on the bottom solder side of the PCB It is a simplified functional equivalent of the Microchip PICkit2 programmer The main simplification is that it does 5V operation only it d
40. 4 DB038 A PIC experiments board version 2 00 bit char in char c const char s This functions returns whether character c appears in string s bit string in const char p const char q This function returns whether the string p appears somewhere in string q 5 4 9 UART functions Header file db038 uart h Code file db038 uart c void uart init 1200 void void uart init 2400 void void uart init 4800 void void uart init 9600 void void uart init 19200 void void uart init 57600 void void uart init 115200 void void uart init 250000 void These functions initialize the UART at different baudrates bit uart char available void This function returns true when a character is available false otherwise char uart char receive void This function waits for a character to become available reads it and returns it Note that this function will not return until a character is available If you want to avoid such waiting use the function uart char available to check whether a character is available and call uart char receive only when one is available bit uart send idle void This returns true when the transmitter is idle void uart char send char c This function waits for the transmitter to become idle and then starts transmission of the character It does not wait for the transmission to complete void uart string send const char p This function uses uart char send to
41. 4 2 6 TEU OW Ot RE EET 15 2 6 1 Software interface external power voltage eene enne nnn nnns 15 Dil Analog multiplGXesumnmie e o IN A tod neututd e ct s D DM A 16 2 8 Simple analog inputs Potentiometer LDR LM335 and TL431 i 17 2 8 1 Software interface potentiometer enne nennen nnn nennen sese sensn nnns 17 2 8 2 Software interface LM335 analog temperature SEensor i 18 2 8 3 Software interface TL431 voltage reference enne enne nennen 18 2 8 4 Software Interface LD Rss tari diana aerea 19 29 Seven seement displays and LEDS tester t Cor od ped tuper d ee il 20 2 9 1 CEI ME TEUER 20 2 9 2 Sortwarednterrace IR LED oi a tas 20 2 9 3 SoftWare Interiace Ele nt bEDS3 uu os ei a blasi 21 2 9 4 Software interface Seven segment displaYS eese emen nnns 21 2 10 PSZ COltie CLOP ette ai 22 2 10 1 Software interface PS 2 ta asociadas 22 2 11 12C EEPROM optional TCN75A 12C CONNECtOF occccccnncccncnnoconaconacocinocnnonnonanonaronaronoconononanonos 23 ZIEL JSormnwareinterrace LES 24 2 12 Dallas one wire DS18S20 optional and connector ie 25 2 12 1 Software interface Dallas 1 wire ii 25 PPM i em 26 2 13 1 Software interface IR Receiver c csccsssssscoscsscnsestcescssscesreusscosensseccstessesseceseneseccecneecees 26 2 14 Aud
42. 737 DE sf y v S000000 60000000 AIIIN 9990005061 01234567 012345674 01234567 234567 Y j Poe A GND A TSOP1736 IR receiver the actual chip that is used can vary is located at the right edge of the board The output of the receiver is connected to the H6 multiplexer output This type of IR receiver is sensitive to an IR signal that is both modulated at a specific frequency and has silent periods when a continuous modulated signal is present the receiver will consider this background noise and attempt to filter it out It this case the peak sensitivity is at either 36 which provides a good reception of Philips 36 kHz RC5 etc and reasonable reception of the 38 kHz signals used by most other remote controls Sony etc The output is high when no signal is received low when an IR burst is received A matching IR LED is mounted just below the IR receiver This LED is discussed in the section Seven segment displays and LEDs p 20 2 13 1 Software interface IR Receiver The IR receiver is addressed by making pins RA2 input and pins REO RE2 outputs and the value on these pins 0b110 cs RA2 Digital input Low when an IR signal is received otherwise high REO RE2 0b110 c Van Ooijen Technische Informatica Wouter van Ooijen page 26 of 74 DB038 A PIC experiments board version 2 00 2 14 Audio output LSP and connector 62 RS Sie I MM M 10k NU m A m i vn ne ala Li aa
43. A PIC experiments board version 2 00 unsigned int adc 1m335 void unsigned int adc t1431 void unsigned int adc microphone void unsigned int adc battery void unsigned int adc current void These functions configure the analog multiplexers perform an A D conversion and return the 10 bit right adjusted result value O 1203 of the on board peripherals 5 4 3 Dallas one wire Header file db038 dallas h Code file db038 dallas c This library provides access to Dallas 1 wire peripherals bit dlw present void Check whether a one wire peripheral is present Calling this function can also be used to reset the one wire devices void dlw byte send unsigned char x Send one byte over the one wire bus unsigned char dlw byte receive void Receive one byte over the one wire bus unsigned char dlw family code read void Read the family code of the connected one wire device This function can be used only when only one one wire device is present on the bus void ds18s20 conversion start void Start conversion on any DS18S20 devices on the one wire bus unsigned int ds18s20 temperature read void Read the raw temperature data 16 bits from a connected DS18520 device This function can be used only when only one one wire device is present on the bus This function requires that a conversion has been started and completed 5 4 4 LC Header file db038 i2c h Code file db038 12c c This library pr
44. A_SHADOW in the example below This is an example of bit manipulation for real code using the macros in the DB038 C library is to be preferred Note that the bits in the TRIS register must be 0 for outputs hence the OxFF at the end A PIC does not have a stack for data only one for return values This stack is limited for a 16F887 it can hold 8 return addresses The compiler generates a warning when it detects an attempt to exceed this limit but doubt that it will always be able to detect this problem especially when function pointers are used Recursion is also a problem on a PIC The compiler seems to report this by the simple method of crashing c Van Ooijen Technische Informatica Wouter van Ooijen page 50 of 74 DB038 A PIC experiments board version 2 00 probably because it tries to find the number of stack entries used which is of course infinite The compiler seems to crash or enter an infinite loop in some other error situations too The compiler generates an Ist file It shows a lot of information have a look in it to see the sometimes horrible assembly code it generates from your C code 5 4 Clibrary The C library for the DB038 can be found at the DB038 homepage at www voti nl DB038 Its library files are summarized in the table below The example files are documented in the next section The library is provided as source files suggest that you copy everything to your project directory and include the files
45. DB038 A PIC experiments board version 2 00 Dwarf Boards DB038 A PIC experiments board c Van Ooijen Technische Informatica Wouter van Ooijen Version 2 00 last modified 20 apr 2010 for DB038 V1 05 PIC PICmicro MPLAB MPASM PICkit In Circuit Serial Programming and ICSP are registered trademarks of Microchip Technology Inc L620 Xeana 9414 457 s1 SINGAPORE v o 1 Mmm IN 3i ol T O E O le POT2 d manu A Hittin SA SMD oo VUMUYE VIC pe ING m D EN iw A 1 Ke iD vi a 93 DO GO A LOT 3 10 5 o 9 ML di PTIS Ak p y No F gt E ROA va 2 E RI th gan dg HI 22p 3 A Oo E 00000000 229900008 ISS TERES de rl Ven M pouer 61234567 0123 3456701234567 1234562 E The board is shown here without the character LCD Near the centre of the board is an empty place where an optional DS18S20 temperature sensor can be fitted c Van Ooijen Technische Informatica Wouter van Ooijen page 1 of 74 DB038 A PIC experiments board version 2 00 Table of content ifttoducioia sss sita 4 2 sCireuit descriptiorana Internacio 6 2 1 PICLOFSS targetchibaa oche 6 2 1 1 god mr CC ln 6 2 1 2 TOFS97 PINUS Sd ari RO 7 2 2 DwarfBus conn ctors aNoWIFecCUpsrissa nihil 10 2 3 IPIOSIAMIME lariana 11 2 4 USB to asynchronous serial interface i 13 2 5 Power source selection JUMPer al 1
46. F887 pins RB4 and RB5 are connected to a crude two resistor D A converter The resulting signal is buffered by the transistor and provided on the video connector The pins RB4 and RB5 are used only for this video output circuit The resistor network also serves to hold the RB4 and RB5 pins low during programming which prevents inadvertent activation of the LVP programming mode this is not needed on the 16F887 which does not supported this mode but it is needed on some other PIC chips 2 16 1 Software interface video output The RB4 and RB5 pins are dedicated to the video output RB4 RB5 Outputs 0b00 sync 0 0V 0b10 black 0 3V 0b11 white 1 0V c Van Ooijen Technische Informatica Wouter van Ooijen page 29 of 74 DB038 A PIC experiments board version 2 00 2 17 HD44780 character LCD connector AJ 70 VVV 100 Gb Ol DOMAIN CONTRA 1x16 Optionally an HD44780 compatible LCD can be fitted on the board It will cover the 16F887 chip so if you want to access the PIC chip you will have to temporarily remove the LCD The RD3 RD7 pins connect to the LCD s RS and D4 D8 lines The LCD s R W line is permanently tied to ground so the PIC can write to the LCD but not read A high value on pin RB3 enabled the LCD background light The RD3 RD7 lines serve many other functions on the board beside the LCD interface bu
47. KEYPAD S 0x0E define KEYPAD H OxOF define KEYPAD NONE OxFF These macros identify the keypad keys unsigned char keypad read void This function reads the keypad and returns the first key it finds pressed or KEYPAD NONE if no key is pressed bit key is pressed unsigned char key c Van Ooijen Technische Informatica Wouter van Ooijen page 54 of 74 DB038 A PIC experiments board version 2 00 This function returns true when the specified key is pressed otherwise it returns false char ascii from key unsigned char x This function returns the ASCII character corresponding to the key x 5 4 6 LCD functions Header file db038 lcd h Code file db038 lcd c void lcd init unsigned char x unsigned char y This function initializes the I O pins and the LCD itself x and y must be the number of characters in X and Y direction It is easy to swap x and y so better use one of the LCD INIT macro s instead LCD INIT 1 1 6 This macro calls Icd init to initialize a 1 line by 16 characters LCD void lcd command unsigned char x This function sends the command byte x to the LCD void lcd clear void This function clears the LCD and places the invisible cursor at the top left position void lcd line unsigned char n This function places the invisible cursor at the start of line n The top line is line O void lcd data unsigned char x This function sends the data byte x to the LCD void lcd char print
48. O RE2 must be outputs and the value on these pins must be 0b011 The voltage on RAO is provided by the voltage divider R33 R23 so it will be 2 2 12 2 18 of the actual battery or wall wart voltage Note that the A D measurement will use the PICs power as reference which can be a rather inaccurate 5V Using the TL431 voltage reference to correct the measurement will yield a much more accurate result RAO Input Analog Battery or Wall Wart voltage REO RE2 Outputs 0b011 c Van Ooijen Technische Informatica Wouter van Ooijen page 15 of 74 DB038 A PIC experiments board version 2 00 2 7 Analog multiplexers FO g RAO F1 RAI G1 RAZ 1 F2 G2 2 F3 63 3 F4 G4 4 REO F5 REO G5 REQ 5 RE1 F6 REI G6 RE1 6 RE2 F7 RE2 G7 REZ 7 CD4051 SMD 1 SMD Boi be L1 L1 E Tor rm TUER ni duarf 3 DB 38 801 05 Three CD4051 multiplexer chips connect the three 16F887 pins RAO RA1 and RA2 each to one of three sets of function lines FO F7 GO G7 and HO H7 The selection which is the same for all three multiplexers is determined by the 3 bit value set by the 16F887 on its pins REO RE1 and RE2 This allows the PIC to interface to 24 functions using only 6 of its I O pins On pin RA1 a weak pull down is provided by resistor R36 This makes it possible to read
49. On the PICs that have a code space that is larger than this number of bits can specify 2048 instructions for the 14 bit cores code paging is used This is a trick to specify the remaining higher bits those bits are taken from a fixed location the PCLATH register Before a GOTO or CALL you must make sure that these bits are set appropriately otherwise your instruction will lead your program to an unexpected location often referred to as never never land The table below shows how the target address is constructed The colons mean that the various bits are concatenated The RETURN and RETLW instructions are not mentioned here because the stack stores all bits of the return address new location after a GOTO or CALL 2 bits from PCLATH 11 bits from instruction new location after modification of PCL 5 bits from PCLATH 8 modified PCL bits The value of the PCLATH register after a reset is 0x00 so if you e do not write to the PCL and e your code is smaller than 2048 instructions 11 bit address you don t have to worry about code paging Turning this logic around when you have just added a small amount of code to a perfectly working program and it suddenly starts acting weird it might be a good idea to check whether the size of your code has crossed a magic border and you must start paying attention to code paging When the size of your code increases above the no worries limit a simple way to keep your program w
50. P instruction provides a one instruction delay A two instruction delay can be created with one instruction by a jump GOTO to the next instruction Even though the jump does not modify the program counter it still writes to it so the instruction still counts as two normal instructions for the instruction timing A four instruction delay can be created by a CALL to a subroutine that contains only a RETURN There will often be a RETURN instruction somewhere so in effect only the CALL needs to be added But note that this construct uses a stack entry If two stack entries are available an 8 instruction delay can be realized by the curious construction of calling a subroutine which consists of a CALL to its own RETURN immediately followed by that return instruction The same RETURN instruction serves both the initial subroutine call and the CALL inside the subroutine Note that this construct uses 2 stack entries This can easily be extended to provide 16 24 32 etc instructions delay 3 11 Using I O pins c Van Ooijen Technische Informatica Wouter van Ooijen page 42 of 74 DB038 A PIC experiments board version 2 00 On 14 bit core chips that have analog capabilities the pins that can have an analog function default to that analog function This is not a coincidence when a digital IO pin is tied to a voltage somewhere between high and low this can cause the internal circuits to drawn much more current than when IO pin levels are well defi
51. Two motors can be connected to the 4 position header The L6202 chips can theoretically handle a continuous current of 1 A at 12 48 V per chip The 7805 that regulates the 5V for the rest of the board has a maximum input voltage of 35V think a maximum of 500 mA at 12 24V is more realistic Note that the L6202 is not designed to work below 12 V 2 19 1 Software interface motor current The motor current causes a voltage across resistor R1 This voltage can be read by the 16F887 To use this function pin RA2 must be configured as an input and as an analog input and pins REO RE2 must be outputs and the value on these pins must be 0b011 The resistor will cause a voltage drop of 0 5mV per mA motor current c Van Ooijen Technische Informatica Wouter van Ooijen page 33 of 74 DB038 A PIC experiments board version 2 00 Input Analog Motor current 0 5mV per mA REO RE2 0b011 2 19 2 Software interface H bridges The pins RCO RC5 are dedicated to driving the H bridges Pins RC1 and RC2 connect to the PWM modules of the 16F887 so those can be used to control the motor speeds 00 Brake c Van Ooijen Technische Informatica Wouter van Ooijen page 34 of 74 DB038 A PIC experiments board version 2 00 3 PIC 14 bit architecture and instruction set summary 3 1 Introduction The 16F887 1s a PIC with a 14 bit core each instruction occupies 14 bits Other PICs have 12 16 24 or 32 bit cores Unless ano
52. acter Synchronous communication uses a separate clock line Bi phase or Manchester encoding as used in RC5 embeds clock information in the data stream allowing the receiver to re synchronize at each bit at the cost of one extra edge per bit cell Hard disks often use an encoding that a compromise between asynchronous communication and bi phase c Van Ooijen Technische Informatica Wouter van Ooijen page 64 of 74 DB038 A PIC experiments board version 2 00 8 Test application The DB038 test 102 hex file contains an application that can be used to test most of the hardware of a DB038 board This description applies to version 1 02 of this application The source of this test application is not available The tests show information on the LCD either a 1x8 or a 2x16 LCD can be used but can be used without the LCD Some tests use the UART but only the UART test itself requires that a PC is connected with a suitable terminal program running The serial settings are 4800 baud 8 data bits no parity Note that the virtual COM port number that created by Windows can vary depending for instance on the USB connector used You can use the device manager to find out which port is created and if you want you can change it The various tests are selected by pressing a switch of the on board keypad Except when noted otherwise the reset button must be pressed to end the test 1 BEEP Press key 1 Three beeps will be generated on the on board
53. als that need dedicated PIC pins are connected directly Other peripherals are interfaced via three CD4051 analog multiplexer chips Multiplexing is common in real world applications because the housing number of pins of a microcontroller is one of the important factors that determine its price The DB038 board has much more peripherals than most real world products hence it needs a lot of multiplexing The default target chip for the DB038 is the 16F887 because this is at the moment the cheapest of the 40 pin 8K instructions flash PICs in the 14 bit core series Other pin compatible PICs can be used as well but the programming details might be a bit different Examples of alternative chips from the 14 bit core series are the older but well know 16F877 16F877A and the 16F917 These are all 8K code chips The 16K instructions 16F1939 is an enhanced 14 bit core From the 16 bit core series the 18F4520 or the older 18F452 both 16K instructions or the newer 18F4620 32K instructions could be used 2 1 PIC16F887 target chip 2 1 1 Circuit ICSP overrides RB6 RB7 ICSP B7 ICSP B6 R24 ek RBS PIC connectors PS210 sp 4 Yt x o si 341 24 2 Ss dea mg YD oe si 3 M Je TUM Su ME 3 I SFr D Id ak vei A aa E serus p A 124 x 5 la aa Mtt g i ATTE iol ilit fossi
54. an Ooijen page 69 of 74 DB038 A PIC experiments board 8 2 USB Programmer version 2 00 i X U USB programmer PIN 2x3 jumper G jumper selects pover source X 470u A CON17 L1 USB PCB B C22 A 0 R L8 E a d rm 100r x y 2 A c SB4 D a S 5 3 p gt dla T2 use L4 silos GND 80850 13 R R49 e e E RCO HA Ok C25 87 _LEDI WS S18 R31 CON27 S o V 16 R le a GND R ls i a GND 50 T5 e i BC860 D D R ES Ba e 1CSP B6 i To MCLR B 47 EE ICSP B7 ul BC850 R 47 AE IAE o R se a i R45 R46 o ni 4k7 lt ud Il Il zai alle BC850 CON20 GND SIR N M ICSP B E si dle ICSP B7 og NI l GND GND rF ND gt tOV____ we 5U a CTS MCLR E GND RJ 6 6 PCB external target ICSP connector GND 6 3 USB serial interface L3 U FUSBZ SMD bead C26 IC UCCIO SS CON18 SC UCC USBDM USBDP NC USB PCB B RESET NC GND OSCI 3V30UT USB communication interface C23 FT232RLEIN ZO 100n GND c Van Ooijen Technische Informatica Wouter van Ooijen
55. an be simulated by a LED or connect an external lamp suing an SCS parameters can eb set from a PC log to a PC 7 5 Other suggestions not DB038 specific 1 4 Interface to a graphics LCD Interface to a matrix LED message display Traffic light system use external 74HC595 chips to interface to LEDs Simple two crossing roads Extra add pedestrians multiple lanes sensors for cars buttons for pedestrians emergency vehicles IR timing parameters adjustable from a PC Video overlay Add an LM1881 for detecting the sync signals c Van Ooijen Technische Informatica Wouter van Ooijen page 68 of 74 DB038 A PIC experiments board version 2 00 8 Circuit diagrams 6 1 PIC 16F887 ML10 connectors wire cups gt IC12 F sea LO RE2 ri E RE1 nee E REO D BO RDZ D DS RD5 pna RZ RD4 D D2 RD3 C10 n E RD2 D DO RD1 198n i oo e RDO E ac2 PS RC7 R D4 RCD ara E RC4 D 18 RC3 ICSP overrides RB6 RB7 oc2 LZ RC2 D L6 RC1 CSP B7 R 5 RCO CSP B6 297 a E ME E R E E Bee B D X1 B7 DB4 resonator 20 MHz Q B6 RB3 no C s with 3 leg resonator R Bo RB2 B4 RB1 14 D B3 RBO C2 C1 7 RAS R P RA4 22p 22p D 5 RAZ 31 R f RAZ 12 a p RAQ GND 16F 887 DIP PIC connectors CON16 G 22 22 22 22 ML 10 CONI CON2 CON3 GND 5U GND 5U pin 1x3 pin 1x3 pin 1x3 7A 222222222220 02 U A 22222 012 12 2222 22 c Van Ooijen Technische Informatica Wouter v
56. are e There 1s no RETURN instruction only RETLW e There are no interrupts so there is no RETFIE e There are no literal forms of add and subtract There is no RETURN instruction but unfortunately the assembler still accepts the RETURN mnemonic and translates it to a RETLW O which clears the W register This can be a very unpleasant surprise to a programmer who is used to a 14 bit core where the W register can be used to return a calculated value Code addressing on 12 bit cores is summarized in the next table Note one very strange detail one bit of the new code address after a call or modification of PCL but not after a GOTO is always 0 As a consequence only half the code space is accessible for these actions and the accessible and inaccessible regions alternate This complicates the use of jump tables and subroutine calls A solution to this problem it to put entry points for all subroutines at the start of your code An entry point uses a GOTO to jump to the subroutine proper new location after a GOTO 2 bits from PCLATH 9 bits from instruction new location after a CALL 2 bits from PCLATH 0 8 bits from instruction new location after modification of PCL 3 bits from PCLATH 0 8 modified PCL bits The stack on 12 bit core chips has only two levels This often requires some convoluted programming 3 14 Reflections on the PIC architecture The PIC instruction set can both be effective and powerful
57. ch point segments will light up the LSB corresponds to the rightmost point void display decimal show unsigned int value unsigned char points unsigned char leds unsigned char milliseconds This function shows the specified integer value on the seven segment displays in decimal format and the pattern leds on the LEDs for the specified time The lower 4 bits of the parameter points specifies which point segments will light up the LSB corresponds to the rightmost point Note that the specified value can be too large in which case only the lower four digits of the value will be shown 5 4 8 Character and string functions Header file db038 string h Code file db038 string c This file provides character and string functions char char from nibble unsigned char x This function returns the ASCII character 0 9 A F corresponding to the value of the lower 4 bits of parameter x unsigned char str len const char p This function returns the length of the string p bit str equal const char p const char q This function returns whether the strings p and q are equal bit str prefix const char p const char q This string returns whether the string p is a prefix of string q void str copy char p unsigned char s char q unsigned char n This function copies up to n characters from string q to string p S is the size of string n c Van Ooijen Technische Informatica Wouter van Ooijen page 57 of 7
58. char c This function prints a single character to the LCD The cursor is advanced one position When the end of a line is reached further characters are ignored The table below shows the characters that have a special effect ASCII value 0 7 User defined characters Newline the cursor is placed on the first position of the next line If the cursor was already on the last line further characters will eb ignored Carriage return the cursor is placed on the first postion of the current line The current line is not cleared Clear the LCD is cleared and the cursor is placed at the top left position void lcd string print const char p This function prints a string of characters using lcd char print void lcd custom unsigned char n c Van Ooijen Technische Informatica Wouter van Ooijen page 55 of 74 DB038 A PIC experiments board version 2 00 unsigned char dl unsigned char d2 unsigned char d3 unsigned char d4 unsigned char d5 unsigned char d6 unsigned char d7 unsigned char d8 This function defines user defined character n n 0 7 5 4 7 LED and seven segment display functions Header file db038 leds h Code file db038 leds c SEGMENT A SEGMENT G SEGMENT DP These macro s define the bit patterns for the individual segments SEVEN 0 SEVEN E These macro s define the bit patterns for the numbers O PF void leds show unsigned char leds unsigned char milliseconds
59. connector If the on board I2C peripherals are left out or removed the I2C connector could be used as second PS 2 connector 2 11 1 Software interface I2C The I2C interface is activated by making pins RAO and RA1 inputs and pins REO RE2 outputs and the value on these pins 0b001 The 16F887 chip has I2C hardware but the I2C bus is not connected to the pins that connect to this hardware Hence the I2C protocol must be implemented in software Make these pins digital inputs before the selector REO RE2 is set to 0b000 Set the output value of RAO and RA1 to O but the pins are still inputs Now the PS 2 protocol can be implemented in software by switching between input and reading the value and output REO RE2 05001 c Van Ooijen Technische Informatica Wouter van Ooijen page 24 of 74 DB038 A PIC experiments board version 2 00 2 12 Dallas one wire DS18520 optional and connector Dallas one wire connector Optional DS18S20 temperature sensor can be fitted here B UN T x A LU A Enea T a F MES o At Li az dd o 3f Js PS A PROG TE 1 3 O e T PS2 16S t POW Sensor Temperatur HP GND gt DSxxxx GND A Dallas One Wire interface is provided on an RJ11 RJ12 6 6 connector The connector has pins for ground 5V and one wire data the pinout of the connector conforms to the de facto standard for one wire One 16F887 pin RA4 is used exclusively for the one wire bus this pin
60. cro PORTA FLUSH must be called to copy the change to the port itself Similar macros are provided for PORTB PORTC PORTD and PORTE PIN SET port bit PIN CLEAR port bit These macro s set or clear the specified bit LSB 0 in the specified port s shadow register and copy the shadow register to the port register Example PIN SET PORTA O J PIN COPY port bit bit value This macro copies the bit value to the specified bit of the shadow register of the specified port and copies the shadow register to the port Example PIN COPY PORTA 1 RAO PORT SET port byte value This macro sets the specified port s shadow register to the specified byte value and copies the shadow register to the port Example PORT COPY PORTE 0x03 void wait ms unsigned int x This function waits x milliseconds Note that the parameter is an unsigned int 16 bits so the maximum delay is 65 seconds 5 4 2 A D converter Header file db038 adc h Code file db038 adc c unsigned int adc channel read unsigned char channel This function configures the specified A D pin performs an A D conversion and returns the 10 bit right adjusted result value O 1203 The table below shows the relation between channel numbers and 1 0 pins 7 AN7 RE2 15 Fixed Ref unsigned int adc ldr void unsigned int adc potmeter void c Van Ooijen Technische Informatica Wouter van Ooijen page 52 of 74 DB038
61. crochip changes its production process In between these extremes would advise you to keep well within all characteristics Note that Microchip in application notes or in summarizing a chip s features often does not stick to this rule You might interpret this as a permit to do likewise but remember that the consequences are for you not for them PICIO pins have a primitive over voltage under voltage protection consisting of diodes to Vcc and Gnd These diodes are certainly not meant to carry significant current during normal operation and it is a continuing debate whether they are designed to carry any current at all during normal operation of the chip It is reported that even a minimal current through these diodes can cause the A D converters to behave very strangely A funny consequence of these diodes is that when the power to a PIC is removed but one of its inputs is still high it will be powered via the protection diode This is not a guaranteed mode of operation but it can ruin an attempt to reset the PIC by removing the power PICs are fairly robust against mistreatment but I killed a few by applying the power in reverse A power supply voltage well above the allowed 5 5V also been reported as an effective PIC killer To protect myself against this mistake often put a 1N400x fools diode between the power lines to short the power if ever accidentally apply it with reverse polarity and always use a 7805 based power supply
62. d the byte can be accessed in INDF But to access the next random byte this whole procedure has to be done again Contrast this with the very simple way in which a small array that fits in one bank can be accessed set the bank bits add the start address of the array within the bank and the index move the result to FSR and use the byte in INDF To access the next byte just change the FSR accordingly When you argue that you will use C or another high level language and be shielded from these details you might be in for an unpleasant surprise most compilers do not support arrays spread over multiple banks some don t even support banking at all and those who do will still produce the same large code that you would produce by hand increasing the size of your application and reducing its execution speed My conclusion about the PIC architecture is that for PICs the relation between application complexity and engineering effort is much less smooth than for more regular architectures especially due to paging and banking This means that PICs will often do well read as good as or better than other architecture for smaller applications but do not so well worse than other architectures for larger applications But a lot of experience 1s needed to rate an application s complexity before applying this rule it 1s certainly not just the amount of code data or MIPSs One might ask why use PIC microcontrollers at all Alternatives are available
63. e Microchip ICD2 The 18F2550 chip that is the heart of the programmer must itself be programmed This is of course done before the board is shipped but the chip can be re programmed using an ICSP pin header This header is located between the second RJ connector and the LCD connector The pinout is compatible with a Microchip PICkit2 programmer but one pin which has no function in the programming process is omitted and an extender connector is required to make the connection The pictures below show how this connection is to be made c Van Ooijen Technische Informatica Wouter van Ooijen page 12 of 74 DB038 A PIC experiments board version 2 00 2 4 USB to asynchronous serial interface J USB2 a RCZ 4k RES communication interface E23 FT232RLS 100n Mod diodo 33533 ZIE TaumyuvuUvbUVUV Ys UV 000 00090 4 10 f Vuo OO0pg Rie 2k 8 4717 ose L417 Hey 17 E NI R27 BC858 lt E a a R DU A EEEE REEE o Boo N dee gs te x 95 SILA 153 00006000 310505909000 dra amp i oat ue E MS A Sa dc 234567 a OSASE 71901234567 1343139333 9 Bids ser p p 15 98 te d nasddtd MITTIT any MCR NOLI PU 5 nn bei R24 y i e D400y e ug0yy III LI E de T Ky ane UTR me AAAI w ADGA ee EEN A second USB port is provided that connects to an FT232RL chip T
64. e SAU Je command command lt lt 1 Correct receiving an RC5 message is a bit more subtle because the timing is controlled by the sender On the bright side 36 kHz modulation is removed by the receiver module so that is one thing less to worry about A naive implementation of RC5 is shown below It waits for the first edge which is halfway the first start bit then waits one quarter of a bit cell three quarters into the bit cell of the first start bit samples the value waits one bit cell samples again etc Ideally all sampling moments are into each bit cell so a high at that moment corresponds with a 1 and a low corresponds with a 0 one ron dora ie ony Wal Sel a the receiver is active low pise e e ee ro lot WEE o 3 1s eS ee oe Once you have a single bit receive function receiving a full RCS message is easy ias ciao emeue ees TE GIOI e vie ee e pese ccc cH ccc unsigned Char Ie COS R a 05 a S 7 while receiver walt 444 us COS OC Clie Wes Site Sec C FOR Rs D xcu I I c Van Ooijen Technische Informatica Wouter van Ooijen page 63 of 74 DB038 A PIC experiments board version 2 00 The problem with this simple approach to receiving a bit is that it is very sensitive to timing problems Let s assume that the receiver s clock is 10 faster than the sender s The RC5 message consists of 14 bits so the sample point for the last bit LSB of the command is 13 and some bit cells after the ris
65. e by switching between input and reading the value and output REO RE2 0b000 2 11 I2C EEPROM optional TCN75A I2C connector en FS I2c scL 47 Fi T2C SDA 47 ca NS ps2 scL 126 5E 47 ra Ps2 sDA 47 I2ZC SDf I2C and PS 2 termination and safety DE O Ca NE MES WIT temp sensor GND GND TCN75 temperature sensor I2C connector gt EEPROM in socket TNG a gt TL d O WA M Le D 6 w j mreny ON gt ut g Menu A ra o on As e LITE E oo 19 EL _ 011 6 gar je A O un UREN 9000 00000000M000 234567 5012345674401 ry Outputs of two multiplexors are uses as I2C lines 47 Q series resistors provide a minimal protection against hardware and software errors and help to damp ringing when longer lines are used 2 2 kQ pull up resistors are provided as required by an I2C interface Note that both the EEPROM and the temperature sensor chip have their address pins tied to ground so the user selectable address bits are 0 c Van Ooijen Technische Informatica Wouter van Ooijen page 23 of 74 DB038 A PIC experiments board version 2 00 female The I2C connector is a PS 2 style miniature DIN connector Two chips can be fitted on the board that connect to the I2C lines an EEPROM and a TCN75 temperature sensor The I2C connector is physically and logically equivalent to the PS 2
66. e configured in the configuration fuses The proper place to specify the configuration fuses values 1s in the source of your program often near the top of your file The configuration fuses can also be specified in the Configure gt Configuration Bits tab in MPLAB or even in the application used to program the PIC Don t do that without the configuration fuses value your program is not complete The configuration bits that are available differ for various PICs Check the chapter Special features of the CPU in the chip s datasheet for the details For the 16F887 the configuration bits are split in two words CONFIGI and CONFIG2 The tables below show explains the features that can be configured and the gives the suggested value for the DB038 board c Van Ooijen Technische Informatica Wouter van Ooijen page 43 of 74 DB038 A PIC experiments board version 2 00 DEBUG Selects whether the internal debugger hardware is enabled The DEBUG_OFF ni debugger hardware claims the pins RB6 and RB7 for BEN communication with the external debugger hardware The DB038 programmer is not meant to be used as debugger LVP Selects whether Low Voltage Programming 1s enabled LVP _LVP_OFF Lj claims the RB3 pin LVP is not needed on a DB038 pin RB3 is SRI used for other this feature disabled disabled unless you need and understand this feature IESO selects whether the Internal External Switchover feature 1s ESO OFF Mul enabled Keep this disab
67. ed version of the protocol uses the second stop bit as 6 bit of the address This second start bit is a 1 in the basic RCS code The extended version replaces it by the inverse of the 6 address bit so and extended code receiver will conveniently interpret the 6 address bit of a basic RC5 message as 0 SAT2 CD video reserved CD photo Sending an RCS signal is relatively simple C pseudo code is shown below The rc5_bit_send function sends one bit according to the bi phase encoding The two for loops can each send 31 pulses of 14 us light and 14 us no light but the first loop will switch the LED only when the bit that is to be transmitted is 0 the second loop will do so only when the bit is 1 Note that 14 us is used as an approximation of 1000 2 36 The time used by the other instructions in the loop can probably not be neglected 1us at 20 MHz is 5 PIC instructions jumps count as 2 so in practice this 14 us will probably have to be lowered a bit EE a c Van Ooijen Technische Informatica Wouter van Ooijen page 62 of 74 DB038 A PIC experiments board version 2 00 The rc5_send function sends a full RC5 message monte WOILC teo MOSS Sie Sine unsigned char toggle unsigned char address unsigned char command io MONI Ee siTe GS Bcd ER sce ooo seme Coge gue e Ol a ae GS Dit sal Ice as MD address address lt lt 1 e e 1 i E EI e O E A El COS rune sema COM
68. emperature register and shows it on the seven segment displays mene en povere bythe US the reading can be tb due towhageNucuatons main uart Receives characters from the UART 19k2 and from the keypad received characters are sent over the UART and their ASCII code is shown in hexadecimal on the seven segment display main wavecom Demonstrates communication with a Wavecom GSM modem c Van Ooijen Technische Informatica Wouter van Ooijen page 59 of 74 DB038 A PIC experiments board version 2 00 6 Background information 6 1 The RCS infra red remote control protocol IR remote control units use modulated Infra Red light to send information to for instance a television set guess they use light because using light is unlike using radio waves not subject to complex regulation Infra red light was used instead of visible light used because there are much less sources of infra red light in the average living room than sources of visible light and infra red light will not blind a human eye There are some domestic sources of IR light most notable FL lamps which produce a 100 Hz or 120 Hz depending on the country flicker To minimize interference from these sources the remote control s IR light is modulated switched on and off at a much higher frequency The most common IR protocols use 36 kHz Philips or 38 kHz Sony The matching receive module contains a band filter that rejects all signals that are not in the frequency
69. eral introduction PIC byte instructions bit set clear difference between literals and memory addresses Lesson 2 Skip instructions GOTO CALL RETURN macro s use of MPLAB simulation timing Lesson 3 Delay tricks banking read modify write issue DB038 hardware overview use of pickit2 application Lesson 4 using one 7 segment display Lesson 5 Multiplexing 7 segment displays and LEDs reading the keypad Lessons 6 7 code paging Optional subjects switch bounce A D conversion serial communication IR music UART The subjects for lessons 5 6 and 7 can be dealt with quickly In the remaining time and some extra time in their project week the students must complete a self defined project 7 2 Simple assignments sor uo e RI Blink a LED Kitt style LED display use shadow registers for the ports us delay routine delay W us ms delay routine delay W ms conversion macro return R if W equals X otherwise do not change W BCD to seven segment value Multiply subroutine Beep at 1 kHz requires an accurate delay Read A D and display the raw values potmeter LDR 10 Display a value on 1 seven segment display requires BCD to seven segment conversion 11 Display a 4 digit value on 4 seven segment displays time multiplexing 12 Read the keypad 73 Intermediate projects 1 2 3 Ot Sy gt a Play a melody Audio beat detector disco jewel Display a text on a HD44780 character LCD be sure t
70. es lateron 6 Finish the wizard 7 Select Project Select Language Toolsuite Set the Active Toolsuite to HI TECH Universal Toolsuite The location should automatically be set to the path where the Hi Tech suite is installed if not you must set it manually lv ea You can add existing files by right clicking on the appropriate entry Source Files for C files in the project window A new file can be created by choosing File gt New and saving the file in the project directory Note that after saving the file you must still add it to the project Select Project Build F10 or better Project Rebuild ctrl F10 to build your project When you change header files even those listed as header files in the files list Project Build does not seem to recompile the C files Once created you can start MPLAB and open the project by double clicking the mcp file 5 3 Details for PIC programming The integer sizes of the compiler are shown in the table below The bit type is a non standard integer type that can hold only 0 and 1 It is restricted to global variables local static variables and function return values it cannot be the type of a parameter or local variable The short long type is also a non standard type not found in normal C compilers Remember that when the signed or unsigned designation is omitted all integers default to unsigned except for char for which the default is compiler dependent So except when you don t care
71. he last location stored by a CALL and returns control back to it CALL and RETURN are used to implement subroutines A special form of the RETURN instruction RETLW stores the specified literal value in the W register before control 1s transferred to the retrieved location GOTO x Store return address then jump to X CALL x Retrieve stored return address and jump to it RETURN W n Retrieve stored return address and jump to it SEL The chip has a primitive stack that is used for one purpose only saving and storing code return addresses This stack has 8 entries For pushing the stack behaves like an 8 entry book shelve when you push a new address onto the stack let s say at the left end the oldest address at the right end falls off and is lost c Van Ooijen Technische Informatica Wouter van Ooijen page 37 of 74 DB038 A PIC experiments board version 2 00 forever For popping there appears to be a copying machine at the far end when you take pop the leftmost book from the shelve the rightmost book 1s duplicated Hence there are always exactly 8 addresses in the stack When more than 8 addresses are pushed onto the stack the oldest address will be lost This in itself 1s no problem but when subsequently more than 8 addresses are popped the 9 pop will return the same address as the 8 pop which will likely cause the program to crash There is no way for the processor to detect that a stack overflow or underflow has occurred
72. his chip converts the USB to asynchronous serial for direct connection to the PIC16F887 s UART pins At the PC side the drivers provided by the manufacturer http www ftdichip com can emulate a Windows serial port convenient the Windows application can use the port like any other serial port or provide a DLL interface which might be less convenient but offers higher throughput On the FTDI website the Windows serial port driver is called VCP driver Virtual Communication Port If the board is to be used with only the second USB connected it should be selected as the power source The 16F887 s UART pins are connected only to the FTDI232RL chip The other interface pins of the FT232RL chip are not connected The 1kQ series resistor in the TxD line makes it possible for an external signal to override the FT232RL s output without doing any harm to the chip c Van Ooijen Technische Informatica Wouter van Ooijen page 13 of 74 DB038 A PIC experiments board version 2 00 2 5 Power source selection jumper 91 LM RA Vay RL Powered from serial USB Powered from wall wart battery Powered from USB interface connector programming interface jumper in left position jumper in middle position jumper in right position The USB interface chips are always powered from their own USB connector A jumper selects the power source for the rest of the board this connector is part of the programmer circuit p 11 One exception the motor
73. ing edge of the first start bit Assuming the sender and receiver are perfectly synchronized at that first edge the receiver s sample moment will be 1096 of 13 bit times earlier The width of the IR pulse is 75 bit cell so this will raise problems You can calculate for yourself what the maximum clock difference is for successful communication In practice IR remote controls often use a cheap ceramic resonator or even the build in RC oscillator of a microcontroller A good resonator has a maximum inaccuracy of 196 the RC oscillator of a microcontroller can be much worse 5 or 10 This timing problem arises because the simple approach synchronizes at one point the rising edge of the first start bit and then tries to stay synchronized for all 13 bit cells A better approach is to synchronize in each bit cell Within the each bit cell there is only one point in time that can be used to synchronize on the edge halfway the bit cell Hence the rcb bit receive function below first samples the receiver and stores this info just like the simple version Next it waits half a bit cell then it waits for an edge and then it waits for a quarter of a bit cell r_ k Ia The problem identified and solved here maintaining synchronization is central to all forms of serial communication Asynchronous serial communication what we incorrectly call RS232 solves this by using relatively accurate clocks and resynchronization at the start of each char
74. io outp t LSP and CONNECT A Ru WD OM bU Es 27 AIAL Sotwaredgnter dte Pad aii 27 2 15 AUGIO INPUTFCORNECtorrarr iii 28 2 15 1 Software interface audio input eese eese ene nennen rennen aene tuna reenenionene 28 2 16 Composite video output connector 29 2 16 1 Software interface video output cccccesessscoscscsesestcercssscesesssscoscncnccesccersusecesenerenetensecees 29 2 17HD44780 character LED CONNECO iii adi 30 217 1 Softwareintertace lt characteriLCD ia 30 2 18 On board keypad and external keypad pads nennen 31 2 15 1 Software Interface Keypad sana 31 LIS VIOtOL Bryce vci 33 2 19 1 Software interface motor CUFrent enean rns sere nnns 33 2 19 2 Software Interface H DridBes aiii id 34 3 PIC 14 bit architecture and instruction set SUMMAry ii 35 o A T 35 3 2 Data lodd and Store sans 36 33 Arithmetic ana logic Instruction See in ds 36 c Van Ooijen Technische Informatica Wouter van Ooijen page 2 of 74 DB038 A PIC experiments board 3 4 3 5 3 6 3 7 3 8 3 9 JL o Cocoa tmi a aeta tubes E td ur ts nana D2 Project CREATION E UTERE 5 3 Details for PIC programming menn 54 CUINA ads 5 4 1 Da IES dai 5 4 2 P D CONVOELGI A LE TO 5 4 3 Dallas ONE Weiss ita om 5 4 4 Chea 5 4 5 Pila 5 4 6 LEDs TUM rede POE 5 4 7 LED and seven segment display functions ennemis 5 4 8 Character ana stre TURCO Street 5 4 9 WAR TT
75. istance it will reflect the IR light sufficiently to light up the LEDs VIDEO Acrude 3x3 checkerboard video signal is generated no test O FACTORY TEST This test performs the following sub tests It will halt with an error message on the seven segment displays when a sub test fails 1 The speaker beeps twice 2 The kitt pattern is shown once back and forth 3 The seven segment test cycle is shown once 4 The potentiometer A D value is read and checked It is assumed that the potentiometer is set at half past ten The LDR LM335 and TL431 A D values are read and checked 6 The external voltage A D value is read and checked An external 12V supply must be connected Without an external supply the error message E4 will be shown 7 The motor driver circuit is tested This requires that a dummy load is connected 50 Q for the upper motor 100 Q for the lower motor When all sub test are completed successfully the seven segments display will show the message good and the LEDs will show a mirrored 4 LED kitt display Subsequently the B KBD UART C MIC D IR REFLEX and VIDEO tests should be performed y c Van Ooijen Technische Informatica Wouter van Ooijen page 66 of 74 DB038 A PIC experiments board version 2 00 7 Suggested lessons assignments and projects 7 1 Ashort course in PIC assembler This is an outline of a PIC assembler course teach at the Hoogeschool Utrecht Lesson 1 Gen
76. lable on the ML10 connectors A D Note that A contains the PIC pins RAO RA5 and REO RE2 Pin RA4 is not connected to any Dwarf Bus connector but it is available on the Dallas 1 Wire connector The tables below show the correspondence between Dwarf Bus pins and wire cup connectors and PICmicro controller pins The green entries show the irregularities The ground and 5V lines are also available on three 3 pin wire cup strips middle cup is 5 Volt top and bottom cups are ground like on a coax cable ground outside signal in the centre me i za us EI ae Op SW ey 2900000009 2900900000 Z oN nl D Si Vl Sa 5 Volt Ground c Van Ooijen Technische Informatica Wouter van Ooijen page 10 of 74 DB038 A PIC experiments board version 2 00 2 3 Programmer CONE JT USE 1 C U 36 64 l 5 6 X O Q U USB programmer PIN 2x3 jumper G jumper selects pouer source X 470u d bd imu bd D i5 amp CON17 LI IN 1x5 C sd R44 SMD bead Il USB PCB B C22 e H E 4k7 L2 i 4 Fra SAVA R 2 MD c SB
77. laneous interfaces sida ias H bridges and external power nnn Audio TINE ACES aces alla 9 External links 10 Document change notes page 3 of 74 DB038 A PIC experiments board version 2 00 1 Introduction The DB038 is a PIC experiments board lt combines a PICkit2 compatible USB programmer and a PIC 16F887 target microcontroller the user can substitute a pin compatible 40 pins chip with a wide selection of on board peripherals and a range of connectors for external peripherals The board except for the motor drivers can be powered from a USB interface so one cable to a Windows PC is all you need to get going This is the ideal board for a PIC programming introduction course A fully populated DB038 board contains e asimplified PICkit2 compatible programmer connects to a Windows PC via USB e aprogramming connector RJ 6 6 connector ICD2 compatible can be used to program an external chip this requires that on board target PIC is removed e aconnector for a wall wart battery or other power supply to operate the board without a PC e aPIC16F887 microcontroller with a 20 MHz resonator e 8 LEDs e 4 seven segment LED displays e a16 key keypad an external 4x4 matrix keypad can be connected in parallel e a16 character x 2 line LCD other character LCDs can be connected e two L6202 H bridge motor driver chips for connecting two small DC motors e aTSOP 1736 1737 or 1738 IR remote control receiver chip
78. led unless you need and understand this feature BOREN Selects whether and when brown out reset is enabled Keep this BOR OFF disabled unless you need and understand this feature Selects whether Data Memory read protection is enabled CPD OFF Selects whether Code Memory read protection is enabled CP OFF MCLRE Selects whether the RE3 MCLR pin is used as MCLR or as RE3 MCLRE OFF The DB038 board assumes the pin is MCLR PWRTE Selects whether the power up timer is enabled Keep this PWRTE ON enabled unless you understand this feature and need to run without it disabled unless you need and understand this feature Selects the type of oscillator and the functions of the RA7 and RA7 pins The DB038 board uses a 20 MHz resonator so this feature must be configured accordingly Selects which parts of the code memory 1f any are write WRT HALF protected Writing to code memory is not for the beginner so it is advised to make as much code memory write protected as possible until you need and fully understand this feature Selects the brown out trip level If the brown out feature 1s _BOR40V used BOREN setting in CONFIG it is advised to set it to 4 0V the alternative 1s 2 1 V In an assembly program the configuration fuses can be specified using the _ config directive The code snippet below shows the suggested configuration for the 16F887 The include must be before the __config lines because this file contain
79. n the current value of one of the flag bits in the status register To make this use of BTFSS and BTFSC more readable the assembler accepts the synonyms show in the table below Skip next instruction 1f and only if the zero flag is not set Two special increment and decrement instructions exit that look a lot like the increment and decrement already described but these forms e do not affect the zero flag e skip the next instruction when the result is zero a a lor W a 1 Ip next instruction when result is 0 DECFSZ a F DECFSZ a W a lor INCFSZ a F c Van Ooijen Technische Informatica Wouter van Ooijen page 38 of 74 DB038 A PIC experiments board version 2 00 W a 1l INCFSZ a W skip next instruction when result 1s 0 The normal decrement and increment instructions DECF INCF affect the zero flag When you need a decrement or increment instruction that does not affect any flags you can use DECFSZ or INCFSZ followed by a NOP 3 7 SLEEP the watchdog interrupts NOP The sleep instruction puts the chip in a very low power state This sleep state can be terminated by a reset or by an interrupt The chip has a watchdog timer When this timer 1s enabled in the configuration fuses it will reset the chip unless the CLRWDT instruction CLeaR WatchDog Timer is executed periodically The watchdog 1s enabled by a bit in the Configuration Fuses check the 16F887 datasheet section special feat
80. ned A digital signal on an analog pin is no problem but the reverse is so the pins that have analog capabilities default to analog But this means that for digital use such pins must first be configured for digital use On the 18F887 this applies to some of the pins of PORTA PORTB and PORTE Note that for digital use both the A D converter and the Comparator might need to be disabled Contrary to the analog functions which are generally enabled by default most digital special lO functions UART I2C PWM etc must be enabled before they can be used and often the pin must also be configured for the appropriate direction When using a special digital function it is advised to read both the section on those functions and the section on the IO port and pin PICs use a funny IO architecture where a reading of a pin always returns the current external level of the pin which can be different from the last value written to a pin even when the pin is set as output for two reasons e PICinstructions execute in a 2 stage pipeline and for IO pins the read part of the next instruction takes place before the writing of the previous instruction e The load on the pin can be too high for it to reach its desired level This can easily happen for a short time when the load is capacitive but it can also happen with a static load that is well within the normal operating specifications All PIC instructions that modify some bits in a byte are read modify
81. o get and use the correct 4 bit initialization sequence Show a processed A D value temperature external supply voltage Use the UART to communicate with a PC Beep and play a melody using a PWM melody Simple calculator VU meter on the LEDs spot peak and bar current c Van Ooijen Technische Informatica Wouter van Ooijen page 67 of 74 DB038 A PIC experiments board version 2 00 9 10 11 Send IR remote codes RC5 Sony etc Interface to one Dallas one wire chip Make an access control system enter pin code on keypad can be changed also 7 4 Advanced projects to CO ed ETRE 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Use the I2C EEPROM Use the I2C temperature sensor Complex calculator hex amp dec sine cosine etc Enter melody on keypad store in internal or external EEPROM play on request Interact with PC show waveform from A D converter simple oscilloscope Interface multiple Dallas 1 wire chips Connect and interface to external SPI chips HC595 MCP23S17 Connect and interface to external 12C chips PCF series MCP2317 Receive IR remote control codes show on displays log to PC IR cheater whenever the TV is set to channel 5 immediately change it to channel 6 Interface to a PS 2 keyboard and or mouse Dump a wav from the PC to the board play it using PWM Record sound from the microphone pass it to the PC st
82. oes not attempt to vary the voltage to the target chip The PIC 18F2550 handles all aspects of the USB communication with the user PC and the programming of the target chip The IRF9024 MOSFET switches the power to the target PIC and its peripherals The yellow LED13 lights up when the programmer is active is busy programming the target chip When the small pushbutton switch below the USB connector is pressed while the USB connection is made the 18F2550 chip will enter bootloader mode so the user can download a different firmware The DB038 board works c Van Ooijen Technische Informatica Wouter van Ooijen page 11 of 74 DB038 A PIC experiments board version 2 00 OK with pickit2 firmware version 1 20 and the pickit2 PC application version 1 20 Firmware and PC application version 1 21 do not work OK with this board Other versions have not been tested The circuit around transistor T2 L2 D1 C15 is a simple step up voltage converter that generates the Vpp programming enable voltage for the 16F887 target PIC The PIC 18F2550 is the controlling element in this converter R15 and R16 allow the PIC to sense the generated voltage so the chip can adjust its control of T2 accordingly The voltage on C15 will be approximately 13 Volt The 18F2550 drives the transistors T3 T4 and T5 to switch the target 16F887 s MCLR pin to either the generated Vpp voltage on C15 or to ground or to let the pin float M PICkit 2 Microcontroller Programmer
83. on I used MPLAB 8 40 contains a free C compiler This is the Lite version of the Hi Tech C compiler It has code optimization disabled which results in code that is roughly twice the size of the optimized version The price for the fully licensed version of this compiler is some 1200 so guess for now you will prefer the larger code size of the free version There are cheaper C compilers on the market but not with an easy to use free version There is even the GNU SDCC compiler but as far as know the PIC version is still under development as it has been for years You can find a quick start guide 19 pages and a manual 519 pages in the installation directory default is C Program Files HI TECH Software PICC PRO 9 65 doc This chapter serves as a short introduction to using this C compiler on the DB038 board and documents the C library provided for the DB038 Like all compilers and assemblers the C compiler generates a hex file which can be downloaded to the DB038 board using the pickit2 application 5 2 Project creation You can create a new project using these steps Start MPLAB Start Project gt Project Wizard Select the device PIC16F887 Create New project File specify the project file create it in a new empty directory don t make the path name too long and avoid spaces and weird characters in the path name 5 You are prompted to add files to the project Add the files that you already have you can add other fil
84. ond FT232RL drives this USB line via 1kQ resistor we Activate Activate keypad row 1 LEDs seven segment m pee TTE display and LCD when otherwise OK ui Output LEDs and Activate FRE row 2 RAS is also used segments of metals Activate keypad row 3 row 3 might be enabled and seven highest the LCD otherwise OK eee DA D7 display active lines of the RD6 Output low LCD RD7 Output Address for the three CD4051 multiplexers OK when the RE1 Output determines sub function of RAO RA2 multiplexers are disabled jumper RE3 This pin is not available as I O because its primary function MCLR is used c Van Ooijen Technische Informatica Wouter van Ooijen page 9 of 74 DB038 A PIC experiments board version 2 00 2 2 Dwarf Bus connectors and wire cups CONTI Q D 22 22 22 CONI CON2 CON3 GND 5U GND 50 pin 1x3 pin 1x3 pin 1x3 A32 22 23 22 22 22 22 22 I a JB n oa hakata m n A prote wf iom i d A A ee oet DE esso eee ale La AS PA SS O LO LI REEDEDETJEICETTT3133 933333939 H 99 X99 CC 91234567 81234567 8 012345 O amp c a ni ERE L3 ES e Most I O pins of the chip are besides being used for the peripherals also available on four Dwarf Bus ML10 connectors and four wire cup strips The Dwarf Bus connectors can be used to connect Dwarf Board peripherals The four Dwarf Busses are avai
85. ore it there for later replay via the board Cricket make cricket like sound in the dark but be silent in the light Scared of sound robot Line following robot probably requires 2 external sensor like CNY70 Light seeking robot Object avoiding robot use IR reflex to detect objects Data logger record daylight maybe you can even distinguish clouds from sunshine temperature maybe add other sensors like humidity log everything to a PC Create composite video Video game PIC pong PC program parses a B W picture and translates it to code that displays that picture as video Advanced access control system keypad external keypad master code log to PC Lap counter and or speed display for model train or model racetrack use IR reflex for detection or add external CNY70 s Magic wand message device you will probably need to add a tilt switch or another device to synchronize the message with the movement A PC application converts a ringtone file to a PIC include file that plays the ringtone Extra multiple melodies played at random or on command from the keypad or an IR command Guitar tuner Microphone is the input string is selected by the keypad deviation is shown on the LEDs You will probably need to implement a DFT MIDI player Automatic light controller button press or presence of people switch light on IR reflex but only at night LDR light goes off after a fixed time use potentiometer or button press light c
86. orking for jumps and calls is to use the LGOTO and LCALL pseudo instructions The assembler c Van Ooijen Technische Informatica Wouter van Ooijen page 40 of 74 DB038 A PIC experiments board version 2 00 translates these pseudo instructions to a setting of the PCLATH register followed by the GOTO or CALL instruction Another option 1s to use the PAGESEL pseudo instruction followed by a GOTO or CALL But note that conditionally executing an LGOTO or LCALL will not produce the expected result because only the first instruction will be skipped For a conditional jump or call the PAGESEL must be put before the skip The code produced by the LCALL LGOTO PAGESEL pseudo instructions depends on the chip for which the code is generated On chips with less than 2048 instructions one code page no code will be produced beside the GOTO and CALL A consequence is that a conditional LGOTO or LCALL will work on such chips but will fail on chips with more code pages On chips with more than one code page a sequence of one or two BCF and BSF instructions will be generated followed for LGOTO and LCALL by the GOTO or CALL An unfortunate consequence 1s that you cannot be sure how many instructions will be generated hence you do not know how long executing these instructions will take The older PICs could not read their own code but newer PICs implement a special procedure to read the content of the code memory This procedure is described in the
87. orresponding LED or segment e Ahigh value on one of RDO RD1 RD2 and RD3 actives one of the rows of the keypad REO RE1 and RE2 are used to select one of the columns and RA1 is used to read whether the button at the intersection is pressed e RD3 connects to the RS line of the optional LCD RD4 RD7 connect to the D4 D7 lines These lines do not influence the LCD unless line E is toggled Line E connects to pin RA5 which is dedicated to this purpose A number of pins RB4 RB5 and RC7 are driven by on board peripherals via a resistor These pins can be used externally but when used as inputs the external circuit must drive the pin from a sufficiently low impedance to overrule the on board peripheral When used as output the PIC will easily supply this drive but the on board peripheral might cause some extra current to be drawn Otherwise the table should be self explaining c Van Ooijen Technische Informatica Wouter van Ooijen page 7 of 74 DB038 A PIC experiments board i RAO REO REl Input and 0b000 FO PS 2 SDA open drain 0b001 F1 I2C SDA output Battery voltage Analog input 0b101 F5 LDR LM335 temperature sensor TL431 2 50 Volt analog reference RAL REO REl Input and Ob000 GO PS 2 SCL open drain 0b001 G1 I2C SCL Loudspeaker output 0b011 G3 Not used Read keypad column 1 leftmost Read keypad column 2 Digital input 0b111 G7 Read keypad column 4 rightmost
88. outputs and the value on these pins 0b100 and making port D an output and each pin low for a corresponding LED on and high for a corresponding LED out The rightmost LED corresponds to the lowest least significant bit RA2 RDO RD7 Outputs Each pin corresponds to one LED low for LED on high for LED off RDO corresponds to the rightmost LED REO RE2 0b100 2 9 4 Software interface Seven segment displays One of the four seven segment displays is activated by making pin RA2 an output and high pins REO RE2 outputs and the value on these pins 0b000 0b011 and making port D an output and each pin low for a corresponding segment on and high for a corresponding segment off Segment A corresponds to the lowest bit of port D bit 0 segment G corresponds to bit 6 the decimal point to bit 8 RDO RD7 Outputs Low enables segment A Low enables segment B Low enables segment C Low enables segment D Low enables segment E Low enables segment F Low enables segment G Low enables decimal point REO RE2 Outputs Enables digit 3 leftmost Enables digit 2 Enables digit 1 Enables digit O rightmost c Van Ooijen Technische Informatica Wouter van Ooijen page 21 of 74 DB038 A PIC experiments board version 2 00 2 10 PS 2 connector ci 120 scL ud connector Fa FP gI2c spa 47 ea gt ps2 scl PS2 SC 47 ra Ps2 sDA 47 I2C and PS 2 termination and safety PS 2 connector gt a a y
89. ovides access to the 1 C bus On the DB036 board this bus connects to the TCN75 A temperature sensor and the EEPROM 24C01 The 13C bus is also available on a connector so chips can also be connected externally define I2C TCN75 ADDRESS 0x48 define 12C_24C01 ADDRESS 0x50 c Van Ooijen Technische Informatica Wouter van Ooijen page 53 of 74 DB038 A PIC experiments board version 2 00 These defines provide the I2C addresses of the indicated chips These addresses are without the R W bit void i2c read unsigned char address unsigned char datal unsigned char n This function performs a read operation on the l2C bus The address is the lC device address without the R W bit Data is a pointer to the bytes that will be read N is the number of bytes that will be read void i2c write unsigned char address const unsigned char data unsigned char n This function performs a write operation on the I C bus The address is the I C device address without the R W bit Data is a pointer to the bytes that will be written N is the number of bytes that will be written 5 4 5 Keypad Header file db038 keypad h Code file db038 keypad c define KEYPAD 0 0 define KEYPAD 1 1 define KEYPAD 2 2 define KEYPAD_ 3 3 define KEYPAD 4 4 define KEYPAD 5 5 define KEYPAD 6 6 define KEYPAD 7 7 define KEYPAD 8 8 define KEYPAD 9 9 define KEYPAD A Ox0A define KEYPAD B 0x0B define KEYPAD C 0x0C define KEYPAD D OxOD define
90. pdf http www voti nl docs TSOP17 pdf http www ti com lit gpn ua7805 http www st com stonline products literature ds 1373 pdf http www national com ds LM LM158 pdf 10 Document change notes version Date 2 00 2010 04 23 1 01 2009 11 13 1 00 2009 08 28 0 1 2008 09 15 Notes Adapted for board 1 05 IR explanation added Hitec C libraries chapter added General rewrite EPS pictures First version adapted from the DB037 document c Van Ooijen Technische Informatica Wouter van Ooijen page 74 of 74
91. red when a carry occurs so it is often referred to as the carry borrow flag carry refers to the carry for addition borrow refers to the negated the 1s used to indicate negation borrow for subtraction c Van Ooijen Technische Informatica Wouter van Ooijen page 36 of 74 DB038 A PIC experiments board version 2 00 Add ADDWF a W ADDWF a F ADDLW n affects Z C DC SUBWE a W SUBWF a F SUBLW n affects Z C DC And ANDWE a W ANDWF a F ANDLW n IORWF a W IORWF a F IORLW n Xor XORWF a W XORWF a F XORLW n 3 4 Bit manipulation The are bit set and bit clear instructions set or clear a single bit in a memory location Note that both the memory location and the affected bit within the memory location are encoded in the instruction For the memory location indirect addressing can be used to affect a calculated address but there 1s no direct way to affect a calculated bit within a byte The assembler accepts the synonyms show in the table below for setting and clearing the flag bits in the status register SETZ BSF 3 0 CLRZ Clear zero flag BCF 3 0 SETC Set carry flag BSF 3 2 CLRC Clear carry flag BCF 3 2 3 5 Control jump and subroutines The processor has instructions for e transferring control to a different location GOTO and for e first storing the location of the next instruction on the stack and then transferring control to a different location CALL The RETURN instruction retrieves and deletes t
92. ress must be calculated at run time The PIC instruction set itself does not support indirection the use of a calculated address Instead two memory mapped registers are used the FSR register acts as pointer the INDF register acts as 1f it were the registers who s address 1s currently in FSR This 1s roughly equivalent to indirection as it is available on other processor architectures but with only a single pointer register The data addressing scheme shown so far has a big problem to move data from one bank to another bank a LOT of bank selection instructions must be used To reduce this problem some addresses map to the c Van Ooijen Technische Informatica Wouter van Ooijen page 41 of 74 DB038 A PIC experiments board version 2 00 corresponding address in bank 0 or sometimes to another bank Another way to say the same thing 1s that some registers appear at more than one address The registers that map to all banks are called shared The shared data RAM is very convenient for the assembler programmer but there are only 16 shared addresses on most 14 bit cores but some PICs have no shared RAM at all When your program does not use too much data the most convenient data banking strategy 1s to keep the bank selection bits pointing to bank 0 only changing these bits when you must access a probably special function register in another bank and then set the bank bits back immediately afterwards Use the RAM in the higher data bank
93. resulting in very compact and fast code or cumbersome and deficient resulting in bloated and slow code It all depends The PIC instruction set 1s very good at the bit manipulations and byte sized arithmetic that are typical for small controller applications Problems arise when either multi byte arithmetic 1s needed or the code and or data 1s so large that the paging and banking gets in the way This typically happens when more complex calculations or larger data sets both comparatively speaking are required The use of a compiler will often shield you from the ugly details but it cannot hide the large amounts of code required to do things that can be done with much less code on more mainstream architectures On the other hand good compilers will take advantage of the power of the PIC instruction set for simple operations c Van Ooijen Technische Informatica Wouter van Ooijen page 45 of 74 DB038 A PIC experiments board version 2 00 To illustrate the weak side of the PIC architecture imagine an application that requires random access to a 120 byte array There are PICs that have 120 and more bytes of RAM data but this 1s spread over four memory banks none of which contains 120 bytes of data So the data access routine has to figure out for each byte in which bank the byte 1s set the banking bits appropriately and to adjust the address according to the starting address of the data fragment in that bank Store the adjusted address in FSR an
94. s mostly or only using indirect addressing You can of course set the bank selection bits yourself using for instance BCF and BSF instructions MPASM provides the BANKSEL macro to set the bank bits for accessing a specified register address using an instruction Likewise the BANKISEL macro sets the single bank bit for indirect addressing When you use this macro to access a data array you must make sure that the whole data array that you are going to access 1s within one bank The PICs data memory banking with fragmented pieces of RAM makes accessing an array that 1s larger than the amount of contiguous RAM very tedious For each access you will have to translate the array index to the correct bank bits and the address within the bank The irregular layout of the register banks makes 1t impossible to do this with just a few instructions Even high level languages often restrict the size of an array to what will fit in a single memory bank 3 10 Instruction timing The 14 bit core PICs typically run at a maximum clock frequency of 20 MHz A PIC requires 4 clocks per instructions so the chip runs at 5 MIPS 5 million instructions per second One instruction takes 0 2 ps This is true for all instructions even skipped instructions except those that write to the program counter Such instructions count as 2 taking 8 clocks or 0 4 us at 20 MHz An assembler programmer will often find the need to insert some delay between instructions The NO
95. s e definitions of CONFIG1 _DEBUG OFF etc c Van Ooijen Technische Informatica Wouter van Ooijen page 44 of 74 DB038 A PIC experiments board version 2 00 BOR OFF CP OFF MCLRE OFF amp PWRTE ON amp WDT OFF amp HS OSC _ config CONFIG2 WRT HALF amp BOR40V Like everything in the real world code protection on PICs is not absolute The ancient 16c84 was used widely in pay TV decoders so it was a favorite target for hacking and receipts for defeating its code protection were circulating on the web The newer PICS are reported to be invulnerable to these rather simple attacks but undoubtedly other attacks exist There are even companies that offer to retrieve the code from any protected PIC but such services are not cheap and often require more than one PIC and a considerable amount of money The best and probably only way to protect your code from piracy is to make sure that it is not worth the effort by keeping the price of your product low compared to the effort of breaking the code protection Note that this vulnerability of code protected chips is not limited to PICS 3 13 The 12 bit core instruction set The 12 bit core PICs like the 12F509 and 10F200 are the small brothers of the 14 bit core chips The 12 bit instruction set lacks a few instructions and there are fewer bits to specify a code or data address This makes programming a 12 bit core trickier Instructions that are missing compared to a 14 bit core
96. send a O terminated string of characters void uart string receive char received unsigned char received size unsigned int milliseconds const char terminate const char ignore c Van Ooijen Technische Informatica Wouter van Ooijen page 58 of 74 DB038 A PIC experiments board version 2 00 This function receives a string of characters The pointer received must point to a caller allocated string Characters that are in the string ignore will be skipped Receiving will terminate as soon as one of the following conditions holds e received size 1 characters have been received not counting skipped characters 1 to have room for the terminating 10 or e milliseconds milliseconds have elapsed or e Acharacter that is in the string terminate has been received 5 4 10 Examples The library zip contains a number of example programs for each example a C file and an MPLAB mcp file Example file What it does main adc Reads the potentiometer and shows its value 0 1023 in decimal format on the seven segment displays Shows on the seven segment displays when no one wire device is connected the device code when a non DS18520 device is connected or the temperature when a DS18S20 is connected also checks whether this key is pressed and if so shows it on the next display characters by 2 lines LCD in binary but slower on the decimal points of the seven segment displays main tcn75 Reads the TCN75 t
97. sent about 50 of the time A typical recommendation from a receiver manufacturer is that a pulse lasts at least 400 us otherwise the receiver might not notice it but on average over a 10 ms interval the signal must be present not more than 50 of the time Note that in this context a signal is a 36 or 38 kHz tone The output of the IR receiver module is the signal without the modulation and it is inverted Hence the output is low when the modulated signal is presents and it is high when no such signal is present as shown in the figure below IR signal IR receiver output Manufacturers of television sets and the accompanying IR controls use various ways to encode information The Philips RC5 code is the most common so it will be described here Information about other codes can be found on the internet The RC5 code uses bi phase modulation to transmit a bit A zero is transmitted as 889 us signal followed by 889 us silence a one is transmitted as 889 us silence followed by 889 us signal Note that this satisfies the requirements of a typical receiver a pulse is more than 400 us and averaged over one bit the signal is present exactly 50 of the time The signal is modulated at 36 kHz so 889 us of signal is 32 pulses These pulses can have a duty cycle of 50 13 9 us on 13 9 us off but in practice the duty cycle is often reduced to 1 3 9 26 us on 18 5 us off or 1 4 6 9 us on 20 8 us off to conserve the power consumption in the
98. small speaker or on an external speaker when one is connected After the three beeps the test will end and a new test can be selected 2 KITT Press key 2 A Kitt style pattern will be shown on the LEDs After three back and forth s the test will end a new test can be selected 3 SEVEN Press key 3 The seven segments will be tested first all segments of each digit will be activated next each segment of all displays will be activated The LCD backlight will also blink After three cycles the test will end a new test can be selected 4 POT The 8 bit analog value read from the potentiometer will be shown on the two right side seven segment displays and on the LEDs The value shown on the right side displays should be proportional to the setting of the potentiometer from 00 fully anti clockwise half past seven to FF fully clockwise half past five The two left side seven segment displays count up in hexadecimal mode 5 LDR The 8 bit analog value read from the LDR is shown on the two right side seven segment displays and on the LEDs When the LDR is shielded from light the value should be high OxFO or more when the LDR is illuminated the value should be lower The actual values can vary depend on the lighting conditions and the type of LDR fitted on the board The two left side seven segment displays count up in hexadecimal mode 6 LM335 The 8 bit analog value read from the LM335 temperature sensor is shown on the
99. t they can be programmed to do nothing on to those other functions while accessing the LCD The LCD s E line is connected to the PICs RA5 pin which is dedicated to this function Keeping this line low prevents messing with the LCD while the RD3 RD7 pins are used for other purposes The potentiometer that sets the contrast voltage for the LCD is the small potentiometer located just above the LCD connector at the left side Its normal setting OV is fully counter clockwise as indicated on the picture the arrow is at 8 hours which is 0 Volt 2 17 1 Software interface character LCD The RAS pin is dedicated to the LCD The other pins RD3 RD7 are shared with other functions Output RB3 High enables backlight RD3 RD4 RD7 Outputs D4 D7 c Van Ooijen Technische Informatica Wouter van Ooijen page 30 of 74 DB038 A PIC experiments board version 2 00 2 18 On board keypad and external keypad pads omron omron omron omron m SW13 1 m SW14 2 mm SH15 3 zg SH16 A 1 3 1 3 1 3 1 3 ops Pat AE E Em RD3 DI GO BAT54 omron omron omron omron RAI A 3 G1 rri SH9 4 pm SHie pp SHi11 d pp SH12 8 62 i dea 13 63 p le ne XA ET 6 64 RD2 DI i m z GS BAT54 omron omron omron omron E s 2 m SG Se ma S es Ue C hi 3 f 1 al 3 1 3 1 3 1 3 D X XX X XX N
100. ted set of chips itself e The errata documenting the differences between the datasheet and the actual silicon as currently available e The midrange reference manual for the 14 bit core chips only e The programming document describing how a programmer must handle the chip not interesting unless you want to design your own programmer e For chips that are a direct successor of another chip there will often be a migration document that describes in detail the differences between the old chip and the new chip e Optionally check for any application notes that might be relevant to your application The electrical characteristics chapter of the data sheet contains a section called absolute maximum ratings These figures indicate the circumstances which a chip will survive for a limited but unspecified time Don t interpret these ratings as normal operating conditions The electrical characteristics section in the datasheet describes the circumstances for which the chip is guaranteed to work This does not mean that it necessarily won t work when one or more of these characteristics are violated just that the manufacturer does not guarantee it For a one off hobby project you could exceed some characteristics power supply voltage ambient temperature clock frequency test your circuit find it working and use it For a very large production run you could do the same but with much more testing and probably extensive re testing whenever Mi
101. ther core size 1s mentioned this summary is about 14 bit cores only When you program your PICs using a High Level language the compiler will isolate you from most details of the PIC architecture but some details will still shine through So even when you use a compiler 1t 1s still a good idea to have some knowledge of the PIC architecture if only to know what kind of constructs can be translated compactly to PIC instructions and which can t The PIC architecture 1s a bit peculiar even or especially for people who are familiar with more mainstream processor architectures The PIC uses the Harvard architecture the code and data spaces are completely separate Most other CPU s use the VonNeuman architecture where code and data share a common address range On a PIC code address 0 and data address 0 have nothing to do with each other and can even address a different number of bits The addressable element in the PIC data space 1s a byte 8 bits the addressable element in the PIC code space is the instruction which is 14 bits on the 14 bit cores The basic PIC instruction set 1s very simple The processor is byte 8 bit at a time oriented There is one special register called the W register The more common name for such a register is accumulator This register 1s part of the CPU it does not appear in any memory space Most instructions specify a data memory location and work on the content of that data memory location and the content of
102. ufficient c Van Ooijen Technische Informatica Wouter van Ooijen page 31 of 74 DB038 A PIC experiments board version 2 00 RA1 Digital input ObO Selected button is not pressed Ob1 Selected button is pressed RDO RD3 Outputs 0b0001 Selects row 0 bottom row 0b0010 Selects row 1 0b0100 Selects row 2 0b1000 Selects row 3 top row REO RE2 Outputs Selects column O leftmost column Selects column 1 Selects column 2 Selects column 3 rightmost column c Van Ooijen Technische Informatica Wouter van Ooijen page 32 of 74 DB038 A PIC experiments board version 2 00 2 19 Motor driver CON4 pin 1440000 U MOT C30 C19 C20 470u 100n 199n O OOO IC19 7885 gius AN Yy SINGAPORE D3 D4 O 1N4aa4 3 MANN 1 225 ad 90 gt Po Tess 00009 2 0000002092 3456 ls r R SuB 7 sun P Su13 g x gt TEE y e A NI 2 30 Sye o suie s 114 2 o 9 4 e De De li SO 100 101 i P gt 3 0 TTL TN SU11 6 TC 76 gt gt The motor driver circuit uses two L6202 H bridge chips Resistor R1 is placed in series with the motor current The voltage over this resistor is filtered by R56 C16 and provided to multiplexer pin G3 to allow the 16F887 chip to determine the motor current This can for instance be used to detect a stall
103. ures of the CPU The standard use is that the application has one main loop which contains a single CLRWDT instruction When the program crashes the main loop will not be executed any more hence the CLRWDT instruction is not executed But the watchdog timer keeps running and when it rolls over the chip is reset The processor has a simple interrupt mechanism Various interrupt sources can trigger an interrupt When an interrupt is accepted by the processor it executes what 1s effectively a CALL to address 0x04 and it clears the GIE Global Interrupt Enable flag to prevent further interrupts The interrupt service routine should end with a RETFIE instruction which is effectively a RETURN instruction that also sets the GIE flag thus enabling further interrupts Only one interrupt can be active at any time It is up to the interrupt service routine to determine the cause of the interrupt and to take appropriate action including clearing the interrupt source When the processor was in the sleep condition when the interrupt occurred the RETFIE at the end of the interrupt service routine will return to the instruction immediately after the SLEEP instruction Put the chip in sleep low power mode SLEEP Clear the watchdog timer CLRWDT RETFIE Upon an interrupt the processor saves the current program counter but nothing else It 1s up to the interrupt service routine to save and restore the W register and any file registers that it uses It will be
104. very difficult to avoid using the W register or affecting the flags so the interrupt entry and exit code will have to save and restore at least W and the flags Note that this entry and exit code cannot make any assumptions about the currently selected register bank Hence it needs two file registers SAVE W and SAVE STATUS that are available 1n all banks and one file register SAVE PCLATH that can be in any bank Note the use of SWAPF instructions to avoid affecting the flags When the application uses more than just code page 0 and the interrupt code does any PC manipulation GOTO CALL write to PCL the PCLATH register must be also be saved at entry set to page 0 because that is where the interrupt code is and restored at exit c Van Ooijen Technische Informatica Wouter van Ooijen page 39 of 74 DB038 A PIC experiments board version 2 00 A surprisingly common mistake made by PIC beginners is to enable the watchdog without knowing The bit that switches the watchdog on or off is in the configuration flags This will let the program run for a short time then the watchdog will trigger and the chip resets When the program is blink a LED it might even seem to work correctly although the blinking will probably be irregular and or at an unexpected frequency 3 8 Code memory and code addressing Control instructions that specify a new code location GOTO and CALL contain only a limited number of bits for this new location
105. write instructions so when for instance two consecutive BCF bit clear instructions on an IO port are executed the second instruction can ruin the effect of the first because of the first of the two reasons Actually a BCF instruction and a lot of other instructions like INCF on a port can ruin any previous setting of that port because of the second reason It should be noted that the first reason occurs far more often and can be avoided by placing a NOP or another instruction between any two read modify write instructions on the same IO port But to really avoid all problems it is advised to allocate a separate register do manipulations on that register and copy it to the port register after each change This technique is called a using a shadow register For some purposes instance I2C PS 2 Dallas 1 wire open collector or open drain IO pins are needed Most PICs have one such pin RA4 but other pins can be used in this mode by writing a O to the pin itself and then writing the desired IO state to the TRIS direction register A 0 in the TRIS register happens to set the bit to output so writing to the TRIS register mimics writing to an open collector output pin But note that the TRIS registers are not in bank 0 3 12 Configuration fuses Some configuration aspects of a PIC chip cannot be set from a running program for instance the type of oscillator the hardware must know this before the program can run at all These aspects ar

Download Pdf Manuals

image

Related Search

Related Contents

les Goums  i.Sound ISOUND-5348 mobile phone case    Seringues prêtes à l`emploi pour l`administration intranasale de  fax richiesta info  SONOS PLAYBAR Product Guide  Manual del usuario    

Copyright © All rights reserved.
Failed to retrieve file