EXPERIMENTING With The PICBASIC PRO

3y ago
59 Views
11 Downloads
7.37 MB
188 Pages
Last View : 15d ago
Last Download : 3m ago
Upload by : Sasha Niles
Transcription

EXPERIMENTINGwith thePICBASIC PROYBy Les JohnsonA COLLECTION OF BWL ING BLOCKSAND WORKING APPLICATIONSUSING MELABSSIMPLE TO USEYET POWERFUL COMPILERIfRosetta TechnologiesA CROWNHILL PUBLICATION a c2

EXPERIMENTINGwith thePICBASIC PRO COMPILERBY LES JOHNSON .10 RosettaTechnologiesA CROWNHILL PUBLICATION

EPlease Note .Although every effort has been taken with the construction of this book toensure that any projects, designs or programs enclosed, operate in acorrect and safe manner . The author or publisher does not acceptresponsibility in any way for the failure of any project, design or programto work correctly or to cause damage to any equipment that it may beconnected to, or used in combination with .The author has no connection to microEngineering, Labs Inc orMicrochip Technologies .Copyright Rosetta Technologies 2000 . All right reserved . No part of thispublication may be reproduced or distributed in any form or by anymeans without the written permission of the author .The Microchip logo and name are registered trademarks of MicrochipTechnology Inc .PICBASIC COMPILER and PICBASIC PRO COMPILER are copyright ofmicroEngineering, Labs Inc .BASIC Stamp is a trademark of Parallax Inc .Author L . Johnson .Published by CROWNHILL Associates LtdFirst Edition August 2000 .

Experimenting with the PicBasic Pro CompilerIntroductionThe BASIC language has been popular since it's conception in the1970's . One of the main reasons for this is its ease of use and ability tomake a project work within a matter of hours, instead of days or weeks .But to have the ability to program a microcontroller in BASIC, is a dreamcome true . Moreover, when the BASIC language is in the form of acompiler ; it combines both speed and ease of use . Micro Engineering,Labs Inc have come up with the perfect medium for programming thePlCmicro range of microcontrollers . The PicBasic Pro Compiler allowstotal control over the full range of 14-bit and 16-bit core PIC's available .This book takes over from where the compiler's user manual left off, andis intended for use by the more adventurous programmer . It illustrateshow to control readily available devices such as Analogue to DigitalConverters, Digital to Analogue Converters, Temperature sensors etc,that may be incorporated into your own projects, as well as somecomplete projects . In addition, tips and techniques are discussed whichallow even more control over the PIC . Each experiment in the book hasan accompanying program that shows exactly what is happening, orsupposed to happen . Most are in the form of subroutines, ready to dropinto your own program .The majority of the projects will work on any of the 14-bit core devices,however, unless otherwise stated, the PIC used is the ever popularPIC16F84 using a 4mHz crystal .The accompanying CDROM has all the source listings for theexperiments, as well as the manufacturers datasheets and applicationnotes for the semiconductor devices used .My thanks go to Jeff Shmoyer, not only for co-writing the compilers, butalso for his advice in the construction of this book . I would also like tothank you for purchasing this book and I wish you every success in yourfuture projects .Les Johnson .

Experimenting with the PicBasic Pro CompilerContents .Section 1 .Display Controller Experiments .PageSimple Serial LCD controller .Multiple baud Serial LCD controller .Contrast control for an LCD module .Driving multiplexed 7-segment LED displays .Substituting common Anode LED displaysInterfacing to the MAX7219 LED controller .1-11-31-61-71 .111-14Section 2 .Interfacing with Keypads .Keypad interfacing principals12-button Keypad interface .16-button Keypad interface .Serial Keypad controller .Receiving data from the Serial Keypad controller.Assembler coded Keypad decoder .2-12-22-42-62-92-10Section 3 .Experimenting with Serial Eeproms .Giving the PIC a memory .Microwire Interface principals .SPI Interface principals .12C Interface principals .12C serial eeprom Interface principals .Interfacing to the 24C32, 12C serial eeprom .Interfacing to the 24C32 using the MSSP module .Interfacing to the 93C66, Microwire serial eeprom .Interfacing to the 25LC640, SPI serial eeprom .3-13-33-43-63-83-103-133-183-20

Experimenting with the PicBasic Pro CompilerContents. (continued)Section 4 .Experimenting with Analogue to Digital Converters .PageInterfacing with the MAX186 Analogue to Digital Converter .Using a 3-wire interface to the MAX1 86 .Using an external reference voltage for the MAX1 86 .Quantasizing the result.Using the MAX1 87 Analogue to Digital Converter .Interfacing to the MAX1 27 Analogue to Digital Converter .Using the on-board Analogue to Digital Converter .Achieving greater accuracy through SLEEP .Using the ADCIN command .An alternative quantasizing formula .Ironing out noisy results .4-14-44-54-64-84-94-124-154-164-184-19Section 5 .Experimenting with Digital to Analogue Converters .Using the PWM command as a Digital to Analogue Converter . 5-1Controlling the hardware PWM modules .5-5Building an R-2R Digital to Analogue Converter .5-9Interfacing to the MAX5352 Digital to Analogue Converter .5-11Interfacing to the AD8402 digital potentiometer .5-14Section 6 .Experimenting with Remote Control .Sony infrared remote control Receiver .Assembler coded Sony infrared ReceiverSony infrared remote control Transmitter .Assembler coded Sony infrared TransmitterInfrared Transmitter / Receiver .Transmitting and Receiving serial infrared .418mHz, A .M. radio Transmitter .418mHz, A .M. radio Receiver .6-16-36-46-76-86-106-136-16

Experimenting with the PicBasic Pro CompilerContents . (continued)Section 7 .Temperature Measurement Experiments .Dallas 1-wire interface principals .Interfacing with the DS1 820, 1-wire temperature sensor .Interfacing with the LM35 temperature sensor .Page7-17-57-8Section 8 .Experimenting with Robotics .Proximity detection principals .Single direction infrared proximity detector .Infrared proximity detector with distance gauge .Directional infrared proximity detector .Ultrasonic proximity detector .Driving a DC motor using an H-Bridge.Driving a DC motor using the L293D .8-18-28-48-58-78-108-12Section 9 .Experimenting with Audio Control Devices .Adding a voice to the PIC with the ISD1416 chipcorder .Recording and playing back multiple messages .Allowing the PIC to audibly count .Digital Volume control using the AD840X .Controlling the gain of an op-amp .Digital active Bass and Treble controls .9-19-29-59-79-99-10Section 10 .Programming techniquesIntegrating Assembly language into your programs .Declaring variables for use with assembler .Passing parameters using the DEFINE command .Using INCLUDE files to tidy up your code .Waking the PIC from SLEEP .A brief introduction to Hardware interrupts .Using the ON INTERRUPT command .10-110-210-310-510-710-910-17

Experimenting with the PicBasic Pro CompilerContents.(continued)Section 11 .Powering up the PIC .PageGetting the most out of batteries .The perfect Power-up .11-111-4Appendix .Component sources .Device pinouts .CDROM Contents .

Experimenting with the PicBasic Pro Compiler

Experimenting with the PicBasic Pro e serial LCD controller .Multiple baud serial LCD controller .Driving multiplexed 7-segment displays .Substituting common Anode LED displays .Interfacing to the MAX7219 LED display driver .

Experimenting with the PicBasic Pro CompilerProgram - SERLCD .BASSimple serial LCD controllerIntelligent LCD modules accept data and command instructions over afour or eight bit parallel interface . Command instructions include : cursorcontrol, clearing, scrolling, etc . These commands are described in theLCD module data sheet and in the compiler's manual . Thanks to theLCDOUT command, these displays are not difficult to use, but stillrequire at least six precious pins from the PIC to be used . The serial LCDcontroller described here, simplifies the use of these displays even more,by enabling control of the LCD with a single wire . This is invaluable indebugging your latest masterpiece, as it opens up a window into yourcode . By connecting it to an unused pin and using the DEBUG commandat specific areas within the program, variables and registers can beviewed .The program SER LCD .BAS implements a simple serial LCD controllerfor use with the PIC16F84 .When the PIC is powered up, the first thing It does is turn on the LCDand wait the appropriate time for the display to be fully initialised, thisusually takes approximately 100ms . It then looks at the polarity switch,and jumps to the appropriate section of code and displays : "T9600 Baud OK!"or"N9600 Baud OK!"for true inputfor inverted inputIt then waits for a 9600-baud serial character of whichever polarity waschosen . If the character is a special escape character (254), the nextcharacter is assumed to be a command . The PIC will therefore pass thefollowing byte to the LCD as a command . Otherwise, the data will passdirectly to the LCD . This allows the display to be cleared scrolled, etc .simply by sending data with an escape character in front of the controlbyte: Serout PortB . 0, N9600,[254, 11Pause 30This will clear the LCD . Note the PAUSE command, this gives the LCDmodule time to recover from the CLS command before sending anothercharacter.Section-1 - 1

Experimenting with the PicBasic Pro CompilerSimple serial LCD controllerIf a display with more or less than 2 lines is used then alter the last line ofthe LCD defines : Define LCD LINES2'Set number of lines on DisplayFigurel .1 shows the circuit of the Simple serial LCD controller. Serialdata enters through R5, this gives some protection to the PIC in theevent of a short circuit, it is also connected to one terminal of the DILswitch (SW1) .The DIL switch serves two purposes, first it configures the serial polaritymode (inverted or true) by pulling PortB .4 to ground through R3, justenough to register as a low reading (0), but not enough to interfere withthe output to the LCD . Sharing a pin like this is a common practice whenspare pins are not available .Secondly, it stops the input from floating, (floating means that the pin isneither set high or low) . This is achieved by resistors R2 and R4 . Whenthe polarity is configured for inverted mode, the left switch in the DILpackage is closed, which means that the right switch is open, thusallowing only R4 to be connected to the input, this pulls the serial inputpin slightly towards ground . And when true polarity is selected, the leftswitch in the DIL package is open and the right switch is closed, bringingR2 into circuit, but as R2 has a lower resistance than R4 the serial inputpin is pulled more to the supply line . Without these resistors, randomcharacters would be displayed when the input was not connected toanything.78L059 VoltsIN OUT0GNDINTELLIGENT LCDMODULERegulated 5 VoltsR11A91So5 ass 22pf0502R07RBBRB5RB4RB3R82RBIRBOR2lookRA4RA3RA2RA 1VSS RAORS1kR4220kV 5v Seri 5IDateInSWIR37Figures .1 . Simple serial LCD controller .Section- 1 - 20O

Experimenting with the PicBasic Pro CompilerPrograms - MULTILCD2.BAS & MULTILCD4.BASMultiple Baud Serial LCD controllerIf, like me, you are fascinated by serial (RS232) communication, then thisproject is a must . The baud rates are selectable from 300 to 19200 andboth inverted and non-inverted serial data is accepted . The circuit is, inessence the same as the Simple controller, but with the exception of aclever little switch called a Decimal Rotary DIL, figurel .2 shows thepinout of one of these devices . It has ten rotary positions, numbered 0 to9, and these numbers are represented as BCD1 ,9 o y 8outputs on pins, 1, 2, 4 and 8 .C coN c41.C9V2The outputs of the switch are connected to RBO - RB4,Figure 1 .2.and by looking at these inputs, the program is able todetermine which baud rate is required i .e .3 for 300 baud, 9 for 9600, 8 for 19200 (position 1 is already used) etc .9Figurel .3 shows the circuit for the multi-baud controller . Because of thehigher baud rates involved, a 16F873 running at 12mHz is used .You may have noticed that the Vdd pin of the LCD is connected toPortB .5 instead of the supply line, this is so that when the PIC is reset, allports are initialised as inputs by default, thus, also turning off the LCD,and effectively resetting it . Therefore, the first thing the program does ismake PortB .5 an output, and turn the LCD on .In order to read the rotary dil switch, the internal pullup resistors areenabled on PortB, and the lower 4-bits are made inputs, we are onlyinterested in the pins that the switch is connected to, so the port is readand the upper 4-bits are masked out by ANDing the result with%00001111, the value held in B -TEST now holds the BCD output of theswitch . A lookup table is setup by using the LOOKUP command whichholds all the baud rates that will be selected (0-9), they have alreadybeen divided by 100 (12 instead of 1200, 96 instead of 9600), this isbecause the calculation to set the baud rate for SERIN2 is, (1000000 /baud )- 20, however, this is too large a number for the compiler tohandle, therefore, it has to be scaled down, this is achieved by dividingby 100 i .e . (10000/(baud/ 100)) - 20. After the LOOKUP command, thevariable BAUD holds the selected baud rate/100, then the abovecalculation is carried out, and BAUD now holds the value to be placed inthe SERIN2 command .Section- 1 - 3

Experimenting with the PicBasic Pro CompilerMultiple baud serial LCD controllerTo read the polarity switch, PortB .4 is made an input and bit-14 of BAUDis set or cleared according to the result . Bit-14 is the mode setting, (1 inverted, 0 non inverted) : TrisB.4 1If P Test 1 thenBaud. 14 0Mode "T"ElseBaud. 14 1Mode "N"EndifTrisB.4 0'Set PortB.4 to Input'If P Test is high then Set for True Polarity'Reset bit- 14 (Mode bit, clear for True)'Variable used for the display'Else Set for Inverted Polarity'Set bit- 14 (Mode bit, set for Inverted)'Variable used for the display'Turn PortB.4 back to an outputThe incoming serial data is then read in using the SERIN2 command, asthis can achieve higher baud rates than SERIN . The program now sits ina loop, receiving data and outputting it to the LCD . If the control byte isdetected (254) the program is re-directed to a routine that input's anotherserial character, this will be the byte that informs the LCD as to whataction should be taken, scroll, clear screen etc :Loop:Serin2 SI,Baud,(RcvByte]If RcvByte 254 then ControlLcdout RcvByteGoto LoopControl:Serin2 Sl,Baud,[RcvByte2]If RcvByte2 253 then goto BarLcdout RcvByte,Rcvbyte2Goto Loop'Receive the serial byte' Trap the control byte' Else display it on the LCD' Keep on looking'Receive the second serial byte' Trap the Bargraph byte'Or send out the two bytes'Look againBar:'Receive the Third and fourth serial byteSerin2 SI,Baud,[Bar Pos,Bar Val]Lcdoutl,Bar Pos'Position of bargraph'Display the bargraphGosub BargraphGoto Loop'Look againSection-1 - 4

Experimenting with the PIcBasic Pro CompilerMultiple baud serial LCD controllerINTELLIGENT LCDMODULE5 VoltsR110kiRESETC21Ou1Cl0 .1u112mHzCrystalb sass asssaVDD RC7 110C4151311OSC2VSSVSSYRB7RBARB5RB4RB3RB2RB1RBO00 0 0 0 oSw3 SV igurel .3 . Multi-baud serial controller .Bargraph optionThe Bargraph display is initiated by sending the control byte 253 alongwith the position to start displaying from, and then the length of the bar : IBarLine 1Con 254Con 253Con 128 Control Byte Bar display initiate Display line 13 .6 VoltsIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIDebug l , Bar, Line 1, Length of Bar : Pause 1 Length of Bar' may be a value of 0 to 59 if a 4x20 display is used, or avalue of 0 to 47 for a 2x16 display . The PAUSE command allows theserial controller time to do the bargraph subroutine .The Bargraph subroutine is in the form of an include file, which is loadedin after the LCD has initialised . The include file BARGRAF2 .INC is foruse with a 2x16 LCD, and BARGRAF4 .INC is for a 4x20 LCD. The codeis fully commented . The serial controller program MULTILCD2 .BAS isfor use with 2x16 LCD modules, and program MULTILCD4.BAS is foruse with 4x20 LCD modules . The program SER TEST.BASdemonstrates the use of the bargraph option .Section-1 - 5

Experimenting with the PicBasic Pro CompilerMultiple baud serial LCD controllerContrast control for an LCD moduleIf a contrast control is needed, it is simple enough to add a small presetpotentiometer connected to the Vo pin of the LCD, as in figurel .4.Contrast increases as the pot is turned towards ground and the voltageon Pin Vo decreases . Alternately, a fixed resistor with a value of a fewhundred ohms can be connected from Vo to ground.INTELLIGENT LCDMODULE 5Vmm ma a ma a m 2W yjr o 0 011111111111VRII50kGNDFigurel .4 . LCD Contrast control .Extended-temperature LCD modules on the other hand, require anegative voltage applied to pin Vo, this can be achieved with a switchmode negative voltage converter, such as the MAXIM 1CL7660 . Asshown in figurel .5. 5V INVDDICL7660CAPC210ufVOUTCAP GNDFigurel .5. Switch-mode negative voltage generator .Section-1 - 6

Experimenting with the PicBasic Pro Comp il erPrograms - 5CC DISP.BASDriving multiplexed 7-segment LED displaysThe main consideration when designing an interface to an LED display isthe number of pins available on the PIC . To drive a five digit nonmultiplexed display would require a PIC with 45 I/O pins, one for eachsegment . This is of course impractical therefore, multiplexing is almostuniversally adopted . Which will still take 13 pins, but on the larger PICswith 33 I/Os this is not usually a problem .As most of you will already know, multiplexing is accomplished by drivingeach display in sequence . As each display is turned on, the segmentdata from the PIC is set to the correct pattern for that digit . The patternsfor each digit are shown in table 1 .1 .Binary value on A-G 01111110011Digit le 1 .1 . Binary pattern for 7-segment digits .63691791021091247127103To illustrate how a single digit is displayed, we will look at digits 4 and 5 .The binary pattern for digit 4 is %01100110, and for digit 5 it is%01101101 . Figurel .6 shows how these binary patterns relate to thesegments to illuminate .OFF 0ON 1ON,OFFOFFONON0011 AD0A7)0ECONOFFONOFFONONON1010111A0Ges eIFECIFigurel .6 . Binary relationship to illuminated segments .Remember, that the 'A' segment is attached to the LSB of the binarynumber .Section-1 - 7

Experimenting with the PicBasic Pro CompilerDriving multiplexed 7-segment displaysConnecting the display to the PIC is uncomplicated . The A-segmentconnects to PortC bit-0, and the G-segment connects to PortC bit-6.Segments B . .F connect to the pins in between . The decimal point isconnected to bit-7 of the same port .In this demonstration, we shall be using common cathode displays . Asthe name suggests, all the cathodes for the individual segment LEDs areconnected together internally, as shown below in figurel .7.ABCDEFGDPCommonFigurel .7. Individual LEDs within a common cathode display .By examining figurel .7 we can see that applying approx 2V to the anodeof a particular segment LED, while the common line is connected toground an individual segment may be illuminated .To multiplex more than one display, requires us to take control of theirindividual cathodes . This is achieved by a transistor acting as a switch,as shown in figurel .8.ABCDEFaDPFigurel .8 . Transistor switch .A logic high on the base of the transistor will switch it on, thus pulling thecommon cathodes to ground . R2 limits the current that can flow betweenthe individual segment LEDs . R1 limits the voltage supplied to the baseof the transistor.We n

Experimenting with Digital to Analogue Converters. Using the PWM command as a Digital to Analogue Converter . 5-1 Controlling the hardware PWM modules. 5-5 Building an R-2R Digital to Analogue Converter. 5-9 Interfacing to the MAX5352 Digital to Analogue Converter . 5-11 Interfacing to the AD8402 digital potentiometer. 5-14 Section 6.

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

The PicBasic Pro Compiler produces code that may be programmed into a wide variety of PICmicro microcontrollers having from 8 to 84 pins and various on-chip features including A/D converters, hardware timers and serial ports. There are many, many PICmicros, some pin-compatible with the 5x series, that may be used with the PicBasic Pro Compiler.

application. This month, our goal is to code a PICBASIC PRO-based DHCP engine into the EDTP Ethernet MINI. So, let’s get started. DHCP WITH PICBASIC PRO We’ll need to add some DHCP-specific PBP code modules to our existing PICBASIC PRO-based EDTP Ethernet MINI driver to ge

Chính Văn.- Còn đức Thế tôn thì tuệ giác cực kỳ trong sạch 8: hiện hành bất nhị 9, đạt đến vô tướng 10, đứng vào chỗ đứng của các đức Thế tôn 11, thể hiện tính bình đẳng của các Ngài, đến chỗ không còn chướng ngại 12, giáo pháp không thể khuynh đảo, tâm thức không bị cản trở, cái được