PDA

View Full Version : Scroll LCD?



polymer52
- 19th February 2010, 14:26
Does anyone know to scroll a 2 or a 4 line serial LCD with a PIC?

Dennis
- 1st March 2010, 10:46
Hi Polymer

Here you go , I am using an 18F4520 but this should work on any pic with a parallel LCD wired in 4 bit mode , just change the LCD defines as you need.


'*************************************
'LCD demo with scrolling
'*************************************

'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines

'Port IO directions and presets for port pins begin here
'TRISX = %76543210 << tris bit order numbering
'TRISA = %11111111 'All pins are outputs
'// Define port pins as inputs and outputs ...
TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs,
TRISB = %11111111 'for 4x4 keypad all input
TRISC = %10010000
TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
'End of Port IO directions and presets for port pins begin here


'variables begin here

counter0 var byte ' Byte for counter
counter1 var byte ' Byte for second counter
'end of variables

'LCD defines begin here
DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to
DEFINE LCD_EREG PORTD 'defines the port where E line is connected to
DEFINE LCD_EBIT 3 'defines the pin where E line is connected
'DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used)
'DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used)
DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 200 'delay in micro seconds
'END of LCD DEFINES

'includes begin here
INCLUDE "modedefs.bas"

'end of includes

'Main code begins here

Pause 500 ' LCD initialize time
showtime:

lcdout $FE,1,"watch" ' Clears LCD displays "watch"

pause 1000 ' Pause 1000ms

lcdout $fe,1 ' Clears LCD sreen

lcdout $FE,$C0,"my PIC" ' Cursor to start of
' second line, displays "my PIC"

Pause 500 ' Pause 1000ms

lcdout $fe,$14,"scroll" ' Cursor moves to right one
' position and displays "scroll"
lcdout $fe,1 ' Clears LCD sreen

pause 1000

LCDOUT $fe, $80+17,"SCROLL"

Pause 1000

for counter0 = 1 to 28 ' FOR..NEXT loop so "scroll"
' scrolls off the LCD to the left

lcdout $fe,24 ' Scrolls display one position to the left

pause 150 ' Pause 150 ms

next counter0 ' do loop again till max count


pause 1000 ' Pause 1000ms

lcdout $fe,1 ' Clears LCD

Pause 500
LCDout $fe,1
LCDout $fe,1,"AWESOME!!" ' Clear and display "AWESOME!!"

pause 1000 ' Pause 1 sec

for counter0 = 1 to 5 ' FOR..NEXT loop so "AWESOME!!" scrolls
' off LCD to the left

lcdout $fe,24 ' Scrolls display one ' position to the left

pause 100 ' Pause 100ms

next ' do loop again till max count

LCDout $fe,1,"Don't miss out!"' Clear LCD , display "Don't miss out!"

pause 1000 ' Pause 1000ms

for counter0 = 1 to 16 ' FOR..NEXT loop so "Don't miss out!"
' scrolls off LCD to the right

lcdout $fe,28 ' Scrolls display one
' position to the right

pause 100 ' Pause 100ms

next ' do loop again till max count

for counter1 = 1 to 2 ' FOR..NEXT loop to display
' Keep watching! for a count of 2 loops

LCDout $fe,1 ' Clear LCD screen

LCDOUT $fe, $80+17,"Keep watching!"
' Display "Keep watching!" starting
' 17 positions from the beginning
' of the first line off LCD screen

pause 200 ' Pause 200ms

for counter0 = 1 to 28 ' FOR..NEXT loop so "Keep watching!"
' scrolls off the LCD to the left

lcdout $fe,24 ' Scrolls display one position to the left

pause 150 ' Pause 150 ms

next counter0 ' do loop again till max count

next counter1 ' do loop again till max count

Pause 500 ' Pause 500ms

goto showtime

end
And some codes for you

Control codes for HD44780 based displays:

1 = Clear screen.
2 = Send cursor to top-left position.
8 = Blank without clearing.
12 = Make cursor invisible/restore display if blanked.
13 = Turn on visible blinking cursor.
14 = Turn on visible underline cursor.
16 = Move cursor one character left.
20 = Move cursor one character right.
24 = Scroll display one character left (all lines).
26 = Poll Keypad
28 = Scroll display one character right (all lines).
35 = Place Large Digit
58 = Enter Buffer Return Status Mode
59 = Exit Buffer Return Status Mode
61 = Make Vertical Bar Graph
65 = Auto Transmit Keypresses on
66 = Backlight On
67 = Auto Line wrapping on.................(default).
68 = Auto Line wrapping off.
69 = Clear Key Buffer
70 = Backlight Off
71 = Go to position.
72 = Go to top left.
74 = Cursor on.
75 = Cursor off.................................(default).
76 = Cursor left.
77 = Cursor right.
78 = Create Custom Character
79 = Auto Transmit Keypresses Off
80 = Contrast
81 = Auto scroll on.
82 = Auto scroll off..........................(default).
83 = Blink on.
84 = Blink off (default).
85 = Set Debounce Time
86 = General purpose output on.
87 = General purpose output off........(default).
88 = Clear display.
96 = Auto Repeat Mode Off
104 = Initialize Horizontal Bar Graph
110 = Initialize Large Digits
115 = Initialize Thin Bar Vertical Graph
118 = Initialize Thick Vertical Bar Graph
124 = Make Horizontal Bar Graph
126 = Auto Repeat Mode On
192 = Move cursor to first position on second line.

Use it with [ $FE,code ], like LcdOut $FE,1 - clear LCD ...

Hope this helps -- post back updates if you add more funky routines.

Kind regards
Dennis

polymer52
- 1st March 2010, 11:34
Thanks. That helps a lot.
Jerry

isaac
- 1st March 2010, 17:46
Here is a nice one from Mel

http://list.picbasic.com/forum/messages/3064/3672.html?

Isaac

Dennis
- 1st March 2010, 18:40
Nice one Isaac :-)

Thanks for resurrecting it :-)


Dennis

wellyboot
- 1st March 2010, 20:24
Nice post & thanks for sharing Dennis