|
PIC18 Simulator IDE Getting Started Page
This presentation will help you to test the included LCD.BAS example and in that way get acquainted with the most frequently used features of PIC18 Simulator IDE.
EXAMPLE 1
- Examine lcd.bas file from the application folder. This program reads analog value on AN0 analog input and displays formatted output on the attached 2x16 LCD module. File lcd.asm was generated using integrated Basic compiler. File lcd.hex was generated using integrated assembler.
Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 1
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 2 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
Dim an0 As Word
AllDigital 'configure all pins for digital use
ADCON1 = 0x0e 'configure AN0 input for analog use
Lcdinit 1 'initialize LCD module; cursor is blinking
loop:
Adcin 0, an0
Lcdcmdout LcdClear 'clear LCD display
Lcdout "Analog input AN0" 'text for the line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "Value: ", #an0 'formatted text for line 2
WaitMs 1 'larger value should be used in real device
Goto loop 'loop forever
- Start PIC18 Simulator IDE.
- Click on Options\Select Microcontroller.
- Select 'PIC18F4520' and click on Select button.
- Click on Options\Change Clock Frequency.
- Enter '4' and click on OK button.
- Click on Tools\BASIC Compiler
- Click on File\Open
- Select lcd.bas file and click on Open. The basic source program will be displayed in the editor.
- Click on Tools\Compile & Assemble & Load. The compiler will generate lcd.asm file with assembler source. The integrated assembler will assemble that file and make lcd.lst and lcd.hex files. Lcd.hex file will be loaded into the simulator program memory.
- Close BASIC Compiler window.
- Select the option Compact Microcontroller View from the Options menu.
- Click on Tools\Microcontroller View. That will open the Microcontroller View window.
- Click on Tools\LCD Module. That will open the LCD Module simulator window. Click on Yes to load the LCD parameters from the basic program file.
- Reposition the windows on the screen to get better view.
- Select the Rate\Extremely Fast simulation rate.
- Click on Simulation\Start. The simulation will start immediately.
- Click on A button associated with RA0/AN0 pin.
- Using the slider change the analog value on this pin and click on Accept button.
- Watch how this change affect the LCD Module. 10-20 ms of real simulation time will be necessary to see the first activity on the LCD module. Watch Real Time Duration field.
- The last three steps can be repeated.
- The simulation can be stopped any time by clicking on Simulation\Stop.
- Try to run the simulation in Step By Step mode while the Basic Compiler window is opened and lcd.bas file loaded in the editor. Then use Run To Next Basic Statement command.
- Screenshot: view
|