Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD and PIC

Status
Not open for further replies.

Ambient

New Member
I am ordering a inchworm kit, hopefully tomorrow, and was wondering about ordering a PIC16F631-I/P at the same time to save on shipping. but this PIC only has 1.75k of flash. I want to use the PIC to control one of these: https://www.sparkfun.com/commerce/product_info.php?products_id=709#. THe rest of the software will be a counter. The project is to make a counter that will go up to some value (and displaying number) on the LCD.

Can anyone tell me if there will be enough space for the program? I have a feeling there will be but I don't want to order PICs that I can't use. Sorry if this is a dumb question, I have not programmed for the PIC's yet. My arduino consumes a lot of memory for firmware, so I am not sure if PICs are the same. I will be using the MPLAB and a free C compiler.
 
That PIC doesn't have the A/D module and TMR2, that might be useful for future projects. What about about a PIC16F690? It has more memory too, just to be on the safe side :)
 
If you want to drive the LCD then you need at least 6 I/O lines preferably 7. If you use an 8 pin chip then you won't have any pins left for anything else like the ICSP connection. I would suggest getting a 16F88 as these are very flexible and William (Blueroom) uses them in a lot of his samples.

As far as programming space goes, a timer with LCD routines should easily fit in the 88.

Mike.
 
The Unicorn will control either a 16x2 LCD with backlight or a 128x64 GLCD. It will be available from dipmicro next week. That sparkfun LCD as long as its a top connector version should work fine. Unicorn also hooks directly to the Inchworms ICD2 cable and can also upgrade the Inchworm+ (make sure you order that version if you want to use Unicorn as a USB upgrade)
Unicorn uses the 18F4550 it's a little intimidating at first but you'll get the hang of it.
**broken link removed**
 
You could just wire it up without the Unicon, and you can pickup LCD's cheaper at www.futurlec.com ($7.90 I think)
**broken link removed**

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

Sample code with Swordfish
Code:
Device = 18F452
Clock = 20

// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTE.0
#option LCD_EN = PORTE.1

// import LCD library...
Include "LCD.bas" 
Include "utils.bas"
Include "convert.bas"

Dim Var1 As Word

// Start Of Program...
SetAllDigital                           // Make all pins digital I/O's

DelayMS(150)                            // Let the LCD warm up
Cls                                     // Clear the LCD screen

WriteAt(1,1,"Hello World")              // Send some text to the LCD

Var1 = 59248
WriteAt(2,1,DecToStr(Var1,5))           // Convert to a string, and display the first 5 characters
WriteAt(2,10,DecToStr(Var1,2))          // Convert to a string, and display the first 2 characters "48"

While 1 = 1                             // Loop forever
Wend                                    //

The library "utils.bas" was included for the command "SetAllDigital". This is a rather handy command that makes all your input/output pins digital. "Convert.bas" was included for the conversion library as an example of how to convert variables to strings. One thing to remember about LCD's 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.
 
The PIC16F631-I/P has plenty of memory for running a typical LCD display. And of course you can wire it directly up to the LCD. The 4 bit mode (like pictured above) is a little tricky to get running but not so bad. Lots of waiting for the LCD (PICs can be very fast, LCDs are not) The not so polished code below shows how it works in 8 bit mode on the Unicorn (A 16F series PIC will require banksel x or BxF STATUS, RP0 instructions and you have to change the LAT instruction to PORT)

The LCD display was simulated using an evaluation version of Oshons 18F simulator.

Code:
 ; LCD entry routines watches busy flag
LCD_Chr bsf     LCD_RS          ; enter here for Charater mode
LCD_Ins bsf     LCD_E           ; enter here for Instruction mode
        clrf    TRISD           ; make PORTD an output
        movwf   LATD            ; put data on LCD port
        bcf     LCD_E           ; latch byte to LCD
        movlw   0xFF     
        bcf     LCD_RS
        movwf   TRISD           ; make LCD port input
        bsf     LCD_RW          ; enter read mode
        bsf     LCD_E           ; enable LCD
_BusyFl btfsc   PORTD,7         ; wait for bit 7 to be pulled low
        bra     _BusyFl
        bcf     LCD_RW          ; return to Instruction mode
 

Attachments

  • LCD Simulation.png
    LCD Simulation.png
    3.8 KB · Views: 159
Last edited:
wow I did not expect this much help so fast! Thanks everyone. I did take a look at the LCD's from futurlec, but none of them are black with white text like I wanted. I am making a shot counter for my a-5 paintball marker and it HAS to look cool, hehe. I have seen other LCDs that are similar but they are usually twice as expensive. I have limited space, as you can imagine.

I need 11 pins minimum for the LCD, and one pushbutton count up or down, and another for changing the number that it resets at (in divisions of 10 probably). So having 18 I/O and more flash will give me more room if I wanted to add a digital compass, timer or clock, or some other totally unnecessary but cool device. :)

EDIT: oh and thanks for the sample code, that will save me a lot of time trying to figure out how to get characters from variables.

One last question about that simulator: I know that not all LCDs need the same code, will that simulator work with just one specific type or possible the one that I want? I am a complete NOOB with LCDs (and PICs). 0 experience.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top