Pic Getting Started

12
8/13/2019 Pic Getting Started http://slidepdf.com/reader/full/pic-getting-started 1/12 IC Simulator IDE Getting Started ThereareelevenexamplesbundledwithPICSimulatorIDE.Theyarelocatedinapplicationolder. Thisisshortstepbystepguideorthebeginnersthatwillhelpthemtotesttheseexamplesandin thatwayexplorethemostimportanteaturesoPIC SimulatorIDE. Example! "Timer#modulesimulation$T%&#interrupts Example' " &(#)I*Texternalinterrupts Example+ "EEP&,%datamemoryaccesssimulation Example- " %athmultiplyroutine$demonstrationocompiler$assembleranddebugger Example "/)Dmodulesimulation Example0 "Comparatorandvoltagereerencemodulessimualtion Example1 "2CDmodulesimulation Example3 " 4ardware5/&Tmodulesimulation Example6 "Sotware5/&Tsimulationinterace Example!# " 17segment2EDdisplayssimulation Example!! " Signalgeneratorandoscilloscopesimulationmodules E8/%P2E! 7Examinetimer#.basileromtheapplicationolder.This(asicprogramuses Timer#module interruptstoperiodicallychangethevalueonP,&T(pins. 9iletimer#.asmwasgeneratedusing integrated(asiccompiler.9iletimer#.hexwasgeneratedusingintegratedassembler. TRISB = 0x00 'set all PORTB pins as outputs PORTB = %11111111 'make all PORTB pins high INTCON.T0I = 1 'ena!le Time"0 inte""upts INTCON.#I = T"ue 'ena!le all un$maske inte""upts OPTION&R#.T0CS = alse 'set Time"0 (lo(k sou"(e to inte"nal inst"u(tion ()(le (lo(k n On Inte""upt 'inte""upt "outine PORTB = PORTB $ 1 'e("ement the *alue on PORTB INTCON.T0I = 0 'ena!le ne+ T,R0 inte""upts Resume 7StartPICSimulatorIDE. 7Clic:on,ptions;Select%icrocontroller. 7Select<PIC!093-<andclic:onSelectbutton. 7Clic:on9ile;2oadProgram. 7Selecttimer#.hexileandclic:on,pen.Thatwill loadtheprograminto PICprogrammemory. 7Clic:onTools;%icrocontroller=iew.Thatwill openthe%icrocontroller =iewwindow. 7&epositionthewindowsonthescreentogetbetterview. 7Selectthe&ate;Extremely9astsimulationrate. 7Clic:onSimulation;Start.Thesimulationwillstartimmediately. 7This(asicprogramusesTimer# moduleinterruptsto periodicallychangethevalueonP,&T( pins. 7Thesimulationcanbestoppedanytimebyclic:ingonSimulation;Stop. *ote"Iyouwouldli:etocompilethisexampleorsomeotherPICmicrocontrollermodel$it mightbe necessarytochangeT#IEandT#I9bit namestoT%&#IEandT%&#I9.>oushouldchec:inthe datasheetothemodelyouwanttousewhatarethecorrect bitnamesorI*TC,*register. 7Screenshot" view 1

Transcript of Pic Getting Started

Page 1: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 1/12

IC Simulator IDEGetting Started

There are eleven examples bundled with PIC Simulator IDE. They are located in application older.This is short step by step guide or the beginners that will help them to test these examples and inthat way explore the most important eatures o PIC Simulator IDE.

Example ! " Timer# module simulation$ T%&# interruptsExample ' "&(#)I*T external interrupts

Example + " EEP&,% data memory access simulationExample - "%ath multiply routine$ demonstration o compiler$ assembler and debugger

Example " /)D module simulationExample 0 " Comparator and voltage re erence modules simualtion

Example 1 " 2CD module simulationExample 3 "4ardware 5/&T module simulationExample 6 " So tware 5/&T simulation inter aceExample !# "17segment 2ED displays simulation

Example !! "Signal generator and oscilloscope simulation modules

E8/%P2E !

7 Examine timer#.bas ile rom the application older. This (asic program uses Timer# moduleinterrupts to periodically change the value on P,&T( pins. 9ile timer#.asm was generated usingintegrated (asic compiler. 9ile timer#.hex was generated using integrated assembler.

TRISB = 0x00 'set all PORTB pins as outputs PORTB = %11111111 'make all PORTB pins high INTCON.T0I = 1 'ena!le Time"0 inte""upts INTCON.#I = T"ue 'ena!le all un$maske inte""upts OPTION&R #.T0CS = alse 'set Time"0 (lo(k sou"(e to inte"nal inst"u(tion()(le (lo(k n

On Inte""upt 'inte""upt "outine

PORTB = PORTB $ 1 ' e("ement the *alue on PORTB INTCON.T0I = 0 'ena!le ne+ T,R0 inte""upts Resume

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!093-< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select timer#.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 This (asic program uses Timer# module interrupts to periodically change the value on P,&T(

pins.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.*ote" I you would li:e to compile this example or some other PIC microcontroller model$ it might benecessary to change T#IE and T#I9 bit names to T%&#IE and T%&#I9. >ou should chec: in thedatasheet o the model you want to use what are the correct bit names or I*TC,* register.

7 Screenshot" view

1

Page 2: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 2/12

E8/%P2E '

7 Examine rb#int.bas ile rom the application older. This (asic program uses &(#)I*T pin basedinterrupts to change the value on P,&T/. 9ile rb#int.asm was generated using integrated (asiccompiler. 9ile rb#int.hex was generated using integrated assembler.

TRIS- = 0x00 'set all PORT- pins as outputs PORT- = 0x 'make all PORT- pins high INTCON.INT = 1 'ena!le RB0/INT inte""upts INTCON.#I = 1 'ena!le all un$maske inte""upts n

On Inte""upt 'inte""upt "outine PORT- = PORT- $ 1 ' e("ement the *alue on PORT- INTCON.INT = 0 'ena!le ne+ RB0/INT inte""upts Resume

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!093-< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select rb#int.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 This (asic program uses &(#)I*T pin based interrupts to change the value on P,&T/.7 Clic:ing on T button associated with &(#)I*T pin will :eep toggling the logical state o this pin.Interrupts will be triggered on the rising edge o the pulses. Every time the value on P,&T/ will bechanged.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

2

Page 3: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 3/12

E8/%P2E +

7 Examine eeprom.bas ile rom the application older. This example ills the whole data EEP&,%memory and the enters an in inite loop. 9ile eeprom.asm was generated using integrated (asiccompiler. 9ile eeprom.hex was generated using integrated assembler.

im a -s B)te 'eep"om a "ess im ! -s B)te 'eep"om ata

o" a = 0 To 2 'go th"ough +hole eep"om memo") ! = 344 $ a 'set the ata *alue to !e +"itten 5"ite a6 ! 'pe" o"m the +"iting to eep"om Next a

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!093-< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select eeprom.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;EEP&,% %emory Editor. That will open the EEP&,% %emory Editor window.7 &eposition the windows on the screen to get better view.7 Clic: on ,ptions;Change EEP&,% ?rite Time. Enter !## or the new value and clic: on ,@. >oushould be very cautious when choosing this value$ because the realistic value is about '#### cloc:cycles at - %4A. In this simple example we will use short value$ because it can not a ect theunctionality o the program$ but can signi icantly decrease simulation execution time.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on ,ptions;In inite 2oop Stops Simulation to select that option.7 Clic: on Simulation;Start. The simulation will start immediately.7 This example ills the whole data EEP&,% memory and the enters an in inite loop.7 5pon detection o the in inite loop the simulator will automatically stop the simulation.

7 Screenshot" view

E8/%P2E -

7 Examine multiply.bas ile rom the application older. This example will multiply two numbers !'+Bhex 1( and '+- Bhex E/ and get the result '313' Bhex 1#0E . 9ile multiply.asm was generatedusing integrated (asic compiler. 9ile multiply.hex was generated using integrated assembler.

im a -s 5o" ' i"st num!e" im ! -s 5o" 'se(on num!e" im x -s 5o" '"esult

a = 132 'set i"st num!e" ! = 327 'set se(on num!e" x = a 8 ! '(al(ulate "esult

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!093-< and clic: on Select button.

3

Page 4: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 4/12

7 Clic: on Tools;(/SIC Compiler7 Clic: on 9ile;,pen7 Select multiply.bas ile and clic: on ,pen. The basic source program will be displayed in the editor.

7 Clic: on Tools;Compile. The compiler will generate multiply.asm ile with assembler source anddisplay &/% %emory 5sage window. Clic: on Close to close it.7 Close (/SIC Compiler window.7 Clic: on Tools;/ssembler7 Clic: on 9ile;,pen7 Select multiply.asm ile and clic: on ,pen. The assembler source program will be displayed in the

editor.7 Clic: on Tools;/ssemble. / ter the operation is completed the assembler will generate two iles"multiply.lst and multiply.hex. The output ile multiply.lst will be displayed.7 Close /ssembler window.7 Clic: on 9ile;2oad Program.7 Select multiply.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;(rea:points %anager. That will open the (rea:points %anager window.7 Clic: on >es to use existing assembler listing ile.7 &eposition the windows on the screen to get better view.7 Clic: on the line corresponding to ##!1 address to de ine the brea:point on this instruction B2###'"G,T, 2###' .7 Select the 4old PC In 9ocus option7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 ?hen this mathematical routine is inished the program enters the in inite loop at the address##!1$ but because o the brea:point$ the simulator will automatically switch to Step (y Stepsimulation rate.7 >ou can stop the simulation now by clic:ing on Simulation;Stop or continue the execution byclearing the de ined brea:point and clic:ing on &ate;Extremely 9ast.7 General purpose register pair B!647!34 will hold the irst argument ##1(.7 GP& pair B!(47!/4 will hold the second argument ##E/.7 The result 1#0E will reside in B!D47!C4 register pair.

7 Screenshot" view

E8/%P2E

7 Examine adc.bas ile rom the application older. This program reads analog value on /*# analoginput and displays 37bit conversion result on P,&T(. 9ile adc.asm was generated using integrated(asic compiler. 9ile adc.hex was generated using integrated assembler.

S)m!ol a &a(tion = - CON0.#O& ON 'set ne+ name o" -/ (on*e"sion sta"t!it S)m!ol ispla) = PORTB 'set ne+ name o" PORTB use to ispla) the(on*e"sion "esult

4

Page 5: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 5/12

TRISB = %00000000 'set PORTB pins as outputs TRIS- = %111111 'set PORT- pins as inputs - CON0 = 0x(0 'set -/ (on*e"sion (lo(k to inte"nal sou"(e - CON1 = 0 'set PORT- pins as analog inputs 9igh - CON0.- ON 'tu"n on -/ (on*e"te" mo ule

main:#osu! geta "esult 'go to (on*e"sion "outine ispla) = - R S9 ' ispla) the "esult o the (on*e"sion #oto main '"epeat o"e*e" n

geta "esult: '(on*e"sion "outine 9igh a &a(tion 'sta"t the (on*e"sion 5hile a &a(tion '+ait until (on*e"sion is (omplete 5enRetu"n

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!09311< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select adc.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 Clic: on / button associated with &/#)/*# pin.7 5sing the slider change the analog value on this pin and clic: on /ccept button.7 ?atch how this change a ect the state on P,&T( pins.7 The last three steps can be repeated.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

E8/%P2E 0

7 Examine comp.bas ile rom the application older. This example uses analog comparator module

to detect the state o /*# and /*! analog inputs in regard to '. = re erence voltage generated byinternal module. 9ile comp.asm was generated using integrated (asic compiler. 9ile comp.hex wasgenerated using integrated assembler.

S)m!ol (omp&(hange = PIR1.C,I '(ompa"ato" inte""upt lag

C,CON = 0x0 'set (ompa"ato" mo e to t+o (ommon "e e"en(e (ompa"ato"s+ith outputs TRIS- = 0x0; 'set R-06 R-1 an R-3 as inputs6 othe" PORT- pins as outputs

<RCON = 0xe( 'tu"n on6 (on igu"e *oltage "e e"en(e mo ule o" 3.4< an(onne(t it to R-3

5

Page 6: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 6/12

TRISB = 0x00 'set PORTB pins as outputs

loop1:5hile Not (omp&(hange '+ait o" (ompa"ato" output (hange 5enPORTB = C,CON ' ispla) C,CON "egiste" on PORTB pins6 RB an RB; a"e(ompa"ato" outputs (omp&(hange = 0 '"eset (ompa"ato" inte""upt lag #oto loop1 '"epeat o"e*e"

7 Start PIC Simulator IDE.

7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!090'3< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select comp.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on ,ptions;5se =oltage or /nalog Inputs to select this option.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 Clic: on / button associated with /*# or /*! pin.7 5sing the slider change the analog value on that pin and clic: on /ccept button.7 ?atch how this change a ect the state on P,&T/ and P,&T( pins.7 The last three steps can be repeated.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

E8/%P2E 1

7 Examine lcd.bas ile rom the application older. This program reads analog value on /*# analoginput and displays ormatted output on the attached 'x!0 2CD module. 9ile lcd.asm was generatedusing integrated (asic compiler. 9ile lcd.hex was generated using integrated assembler.

e ine - C&C OC> = 2 ' e ault *alue is 2 e ine - C&S-,P ?S = 10 ' e ault *alue is 30 e ine C &BITS = @ 'allo+e *alues a"e 7 an @ $ the num!e" o atainte" a(e lines e ine C & R # = PORTBe ine C & BIT = 0 '0 o" 7 o" 7$!it inte" a(e6 igno"e o" @$!itinte" a(e e ine C &RSR # = PORTe ine C &RSBIT = 1e ine C & R # = PORTe ine C & BIT = 2e ine C &R5R # = PORT 'set to 0 i not use 6 0 is e ault e ine C &R5BIT = 3 'set to 0 i not use 6 0 is e ault e ine C &CO,,-N ?S = 3000 ' ela) a te" C C, O?T6 e ault *alue is 4000

e ine C & -T-?S = 40 ' ela) a te" C O?T6 e ault *alue is 100 e ine C &INIT,S = 3 ' ela) use !) C INIT6 e ault *alue is 100 'the last th"ee e ine i"e(ti*es set the *alues suita!le o" simulationA

6

Page 7: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 7/12

the) shoul !e omitte o" a "eal e*i(e

im an0 -s 5o"

TRIS- = 0x 'set all PORT- pins as inputs - CON1 = 0 'set all PORT- pins as analog inputs ( init 1 'initiali e C mo uleA (u"so" is !linking

loop:- (in 06 an0( (m out ( Clea" '(lea" C ispla) ( out -nalog input -N0 'text o" the line 1 ( (m out ( ine39ome 'set (u"so" at the !eginning o line 3 ( out <alue: 6 Dan0 ' o"matte text o" line 3 5ait,s 1 'la"ge" *alue shoul !e use in "eal e*i(e

#oto loop 'loop o"e*e"

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!09311< and clic: on Select button.7 Clic: on 9ile;2oad Program.7 Select lcd.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 Clic: on Tools;2CD %odule. Clic: on >es or the 2CD %odule to load the setup parameters romthe basic program. That will open the 2CD %odule simulator window. B*ote" 2CD %oduleparameters can be setup manually using Setup command.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 Clic: on / button associated with &/#)/*# pin.7 5sing the slider change the analog value on this pin and clic: on /ccept button.7 ?atch how this change a ect the 2CD %odule.7 The last three steps can be repeated.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.*ote" /t the beginning o this simulation you will need to be patient$ because 2CD initialiAationse uence will ta:e about !#ms o real time. ?atch &eal Time Duration ield.

7 Screenshot" view

E8/%P2E 3

7 Examine uart.bas ile rom the application older. This program irst sends 0 lines o ormattedoutput to hardware 5/&T serial port and then responds to the bytes received on that serial port bysending one line o ormatted text or every received byte. 9ile uart.asm was generated usingintegrated (asic compiler. 9ile uart.hex was generated using integrated assembler.

im i -s B)te ' e(la"e a *a"ia!le 9se"open E 00 'open ha" +a"e ua"t po"t o" !au "ate E 00

7

Page 8: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 8/12

'5ait,s 1000 'this ela) shoul !e use in a "eal e*i(e

o" i = 10 To 4 Step $1 ' o"$next loop 9se"out Num!e": 6 Di6 C" 'sen o"matte output to se"ial po"t '5ait,s 400 'this ela) shoul !e use in a "eal e*i(e Next i

loop:9se"in i '+ait to "e(ei*e a !)te on se"ial po"t 9se"out Num!e": 6 Di6 C" 'sen o"matte output to se"ial po"t

#oto loop 'loop o"e*e"

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!09311< and clic: on Select button.7 Clic: on ,ptions;Change Cloc: 9re uency.7 Enter <-< and clic: on ,@ button.7 Clic: on ,ptions;Change 5/&T Transmit)&eceive Time.7 Enter <!##< and clic: on ,@ button.7 Clic: on 9ile;2oad Program.7 Select uart.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;4ardware 5/&T Simulation Inter ace. That will open the window or inter acinghardware 5/&T during the simulation.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 ?ait until the program has inished sending 0 lines o ormatted text to the serial port.7 5sing one o three available buttons in the 5/&T Input section o the 5/&T inter ace send a byteto the serial port.7 ?atch how program responds by sending one line o ormatted output.7 The last two steps can be repeated.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

E8/%P2E 6

7 Examine so tuart.bas ile rom the application older. This program irst sends 0 lines o ormattedoutput to so tware 5/&T serial port BT8 line" P,&T(.! and then responds to the bytes received onthat serial port B&8 line" P,&T(.' by sending one line o ormatted text or every received byte. 9ileso tuart.asm was generated using integrated (asic compiler. 9ile so tuart.hex was generated usingintegrated assembler.

e ine S RO?T& -F?S = 400im i -s B)te ' e(la"e a *a"ia!le '5ait,s 1000 'this ela) shoul !e use in a "eal e*i(e

o" i = 10 To 4 Step $1 ' o"$next loop Se"out PORTB.16 E 006 Num!e": 6 Di6 C" 'sen o"matte output to

8

Page 9: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 9/12

PORTB.1 GTH line o so t+a"e ?-RT '5ait,s 400 'this ela) shoul !e use in a "eal e*i(e Next i

loop:Se"in PORTB.36 E 006 i '+ait to "e(ei*e a !)te on PORTB.3 GRH line o

so t+a"e ?-RT Se"out PORTB.16 E 006 Num!e": 6 Di6 C" 'sen o"matte output to

se"ial po"t #oto loop 'loop o"e*e"

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!093-< and clic: on Select button.7 Clic: on ,ptions;Change Cloc: 9re uency.7 Enter <-< and clic: on ,@ button.7 Clic: on 9ile;2oad Program.7 Select so tuart.hex ile and clic: on ,pen. That will load the program into PIC program memory.7 Clic: on Tools;So tware 5/&T Simulation Inter ace. That will open the window or inter acingso tware 5/&T during the simulation.7 De ault settings should be set" &8 2ine 777 P,&T(.'$ T8 2ine 777 P,&T(.!$ (aud &ate 77760##$ 2ogic 2evels 777 Standard. I not$ using commands rom Settings menu ma:e the necessarychanges.7 Clic: on ,ptions;Compact %icrocontroller =iew to select it.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;5ltimate B*o &e resh simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 ?ait until the program has inished sending 0 lines o ormatted text to the serial port. Pay attentionto the state o P,&T(.! pin on the %icrocontroller =iew window.7 5sing one o three available buttons in the 5/&T Input section o the 5/&T inter ace send a byteto the serial port. Pay attention to the state o P,&T(.' pin on the %icrocontroller =iew window.7 ?atch how program responds by sending one line o ormatted output.7 The last two steps can be repeated.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

E8/%P2E !#

7 Examine 1segment.bas ile rom the application older. This program displays numbers rom # to66 on the two 17segment 2ED displays with parallel connection and two enable lines using T%&#interrupt multiplexing procedure. 9ile 1segment.asm was generated using integrated (asic compiler.9ile 1segment.hex was generated using integrated assembler.

im igit -s B)te 'input *a"ia!le o" # T,-S> su!"outine

9

Page 10: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 10/12

im igit1 -s B)te '(u""ent high igit im igit3 -s B)te '(u""ent lo+ igit im mask -s B)te 'output *a"ia!le "om # T,-S> su!"outine im mask1 -s B)te '(u""ent high igit mask im mask3 -s B)te '(u""ent lo+ igit mask im i -s B)teim phase -s Bit

S)m!ol 1ena!le = PORTC.0 'ena!le line o" highe" ;$segment ispla) S)m!ol 3ena!le = PORTC.1 'ena!le line o" lo+e" ;$segment ispla) TRISB = %00000000 'set PORTB pins as outputs TRISC.0 = 0 'set RC0 pin as output TRISC.1 = 0 'set RC1 pin as output 1ena!le = alse3ena!le = alsemask1 = 0mask3 = 0phase = 0INTCON.T0I = 1 'ena!le Time"0 inte""upts INTCON.#I = 1 'ena!le all un$maske inte""upts OPTION&R #.T0CS = 0 'set Time"0 (lo(k sou"(e to inte"nal inst"u(tion()(le (lo(k

loop:o" i = 0 To EE

igit1 = i / 10 'get (u""ent high igit igit3 = i ,o 10 'get (u""ent lo+ igit T,R0 = 0 '"eset Time"0 to p"e*ent its inte""upt !e o"e !oth masks a"e

ete"mine igit = igit1#osu! getmask 'get mask o" high igit mask1 = maskigit = igit3#osu! getmask 'get mask o" lo+ igit mask3 = mask#osu! sho+1 ' ispla) ne+ mask #osu! sho+3 ' ispla) ne+ mask 5ait?s 400 ' ela) inte"*al suita!le o" simulation

'use la"ge ela) o" the "eal e*i(e6 sa) 5-IT,S 400 Next i#oto loopn

On Inte""upt 'Time"0 inte""upt "outine '(ontinuousl) s+it(h !et+een high an lo+ igit ispla)s I phase = 0 Then

phase = 1#osu! sho+1

lsephase = 0#osu! sho+3

n iINTCON.T0I = 0 'ena!le ne+ T,R0 inte""upts Resume

getmask: 'get app"op"iate ;$segment mask o" input igit mask = ook?pG0x2 6 0x0 6 0x4!6 0x7 6 0x 6 0x 6 0x; 6 0x0;6 0x; 6

0x 6 igitRetu"n

sho+1: 'sho+ high igit on its ispla) 3ena!le = alsePORTB = mask11ena!le = T"ue

Retu"n

sho+3: 'sho+ lo+ igit on its ispla) 1ena!le = alsePORTB = mask3

10

Page 11: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 11/12

3ena!le = T"ueRetu"n

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!09311< and clic: on Select button.7 Clic: on ,ptions;Change Cloc: 9re uency.7 Enter <-< and clic: on ,@ button.7 Clic: on 9ile;2oad Program.7 Select 1segment.hex ile and clic: on ,pen. That will load the program into PIC program memory.

7 Clic: on Tools;17Segment 2ED Displays Panel. That will open the window with our 17segmentdisplays.7 Clic: on Setup button below the display number '.7 Clic: twice on the orange ield next to the Display Enable label to select pin that will be used toenable)disable this display.7 Select P,&TC.# and then clic: on Select.7 Clic: on Setup button below the display number !.7 Clic: twice on the orange ield next to the Display Enable label to select pin that will be used toenable)disable this display.7 Select P,&TC.! and then clic: on Select.7 Clic: on the 4ide Setup button to save some screen space.7 &eposition the windows on the screen to get better view.7 Select the &ate;5ltimate B*o &e resh simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 The program will display numbers rom # to 66 on the two 17segment 2ED displays using T%&#interrupt multiplexing procedure.7 Experiment with the @eep 2ast Display option.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

E8/%P2E !!

7 Examine i'c.bas ile rom the application older. This routine programs the irst +' locations in theexternal serial EEP&,% device using I'C communication protocol. In this example it is used todemonstrate oscilloscope and signal generator simulation modules. 9ile i'c.asm was generated

using integrated (asic compiler. 9ile i'c.hex was generated using integrated assembler.im a " -s 5o" '*a"ia!le o" sto"ing PRO, !)te a "ess im ata -s B)te '*a"ia!le o" sto"ing PRO, !)te ata

S)m!ol s a = PORTC.3 'ni(kname o" S - pin S)m!ol s(l = PORTC.2 'ni(kname o" SC pin

o" a " = 0 To 21 'the i"st 23 !)tes +ill !e +"itten ata = 344 $ a " 'set the ata !)te to !e +"itten I3C5"ite s a6 s(l6 0xa06 a "6 ata 'pe" o"m I3C +"ite ope"ation to

se"ial PRO,

11

Page 12: Pic Getting Started

8/13/2019 Pic Getting Started

http://slidepdf.com/reader/full/pic-getting-started 12/12

5ait,s 1 'small ela) inte"*al Next a "

7 Start PIC Simulator IDE.7 Clic: on ,ptions;Select %icrocontroller.7 Select <PIC!09311< and clic: on Select button.7 Clic: on ,ptions;Change Cloc: 9re uency.7 Enter <-< and clic: on ,@ button.7 Clic: on 9ile;2oad Program.7 Select i'c.hex ile and clic: on ,pen. That will load the program into PIC program memory.

7 Clic: on Tools;,scilloscope. That will open the our channel digital oscilloscope window.7 Clic: on Settings;Turn ,n), ,scilloscope Channel !.7 Select P,&TC.' and then clic: on Select.7 Select Pull7up option or channel ! pin.7 Clic: on Settings;Turn ,n), ,scilloscope Channel '.7 Select P,&TC.+ and then clic: on Select.7 Select Pull7up option or channel ' pin.7 Clic: on Settings;Turn ,n), ,scilloscope Channel +.7 Select P,&T(.# and then clic: on Select.7 Clic: on Settings;Turn ,n), ,scilloscope Channel -.7 Select P,&T(.! and then clic: on Select.7 Clic: on Tools;Signal Generator. That will open the our channel continuous pulses generator.7 Clic: on Settings;Turn ,n), Signal Generator !.7 Select P,&T(.# and then clic: on Select.7 Enter ## to de ine period or channel ! pulses and then clic: on ,@.7 Enter ' to de ine duty cycle or channel ! pulses and then clic: on ,@.7 Clic: on Settings;Turn ,n), Signal Generator '.7 Select P,&T(.! and then clic: on Select.7 Enter !### to de ine period or channel ' pulses and then clic: on ,@.7 Enter # to de ine duty cycle or channel ' pulses and then clic: on ,@.7 Clic: on Tools;%icrocontroller =iew. That will open the %icrocontroller =iew window.7 &eposition the windows on the screen to get better view.7 Select the &ate;Extremely 9ast simulation rate.7 Clic: on Simulation;Start. The simulation will start immediately.7 I'C communication can be observed on the oscilloscope module as well as the pulses generatedby the signal generator.7 The simulation can be stopped any time by clic:ing on Simulation;Stop.

7 Screenshot" view

12