18F LCD Example

    Swordfish has many built in libraries, one being "LCD.bas". This library allows seemingly easy control of LCD modules, and only requires a few declarations.

Note the PIC's power supply/oscillator are not shown

Click here to see this circuit in action!

    Note that the contrast resistor pot can be anything from 4.7K to 10K, and that the unused data lines on the LCD do not need to be tied to earth. Be sure to allow a small delay before sending data/commands to the LCD module on startup, as its microprocessor has to initialize as well. 150mS should be enough for most devices.

    To make life even easier, you can solder pins to the LCD so that you can just 'insert' it into your breadboard

    One thing to remember about LCD modules is to give them ~100-200ms to power-up. They run through their own initialization, and if you were to send data to it immediately, nothing would be displayed.

Device = 18F4520
Clock = 20

// some LCD options...
#option LCD_DATA = PORTD.4              // Assign the LCD connections
#option LCD_EN = PORTD.3                //
#option LCD_RS = PORTD.2                //

// import LCD library...
Include "LCD.bas" 
Include "convert.bas"
Dim Variable As Word

// Start Of Program...
DelayMS(150)                            // Let the LCD warm up
LCD.Cls                                 // Clear the LCD screen
LCD.WriteAt(1,1,"Hello World")          // Send some text to the LCD
Variable = 0                            // Clear the "Variable" register
While True
    Inc(Variable)                       // Increment the "Var1" register
    // Convert to a string, 
    //  and always display 5 characters    
    LCD.WriteAt(2,1,Convert.DecToStr(Variable,5))   
    
    DelayMS(1000)                       // Delay for 1 second                 
Wend

 

     Video Tutorials:

    Download nothing available yet...

    Link: What is a Swordfish Library?

Where you can get the components;

 

Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Collapse 18F PIC Examples18F PIC Examples
LED's
Switches
Expand 7 Segment Displays7 Segment Displays
LCD's
Expand 7 Segment Displays7 Segment Displays
ADC
ADC (Another Example)
EEPROM's
DS1307
Expand RS232 and UARTRS232 and UART
DS18B20
External ADC
Hall Effect Sensor
Pulse Width Modulation (PWM)
Infrared UART
Swordfish Modules
Expand Code SnippetsCode Snippets
Expand Handy TipsHandy Tips