18LF2520 with 5110 LCD

18LF2520 with 5110 LCD

Postby camerart » Sun Oct 01, 2017 9:27 am

Hi, First post :)
Is there anyone her that uses BASIC? I'm stuck in time, and it's [i]basically[i] the only language I use.
I'm making a little circuit that uses an 18LF2520 and a Nokia 5110 LCD, and am looking for some help.
Cheers, Camerart.
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby drh » Sun Oct 01, 2017 3:25 pm

What kind of help? Hardware? Firmware?
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: 18LF2520 with 5110 LCD

Postby camerart » Sun Oct 01, 2017 9:05 pm

Hi D,
I use Oshonsoft for writing and simulating the programs, and MPLAB for programming the PICs, with a serial connection.
I use Kicad to make the circuits.

Here is an example program written by Chris Holden. He used a different PIC. Where it won't compile, I add 'XXXXXXXXXXXXXXX or similar mark, so I can find the problem lines.
I'm using a modified circuit, so I don't know yet exactly which pins will connect to where, but as soon as I know I can alter them.

##########################################################################
'16LF1829 INT32 5110LCD 030417 (Chris holden)
'18LF2520 INT32 5110LCD 011017
Define CONFIG1 = 0x0804
Define CONFIG2 = 0x1dff
Define CLOCK_FREQUENCY = 32

declarations:
Symbol tx = PORTA.0
Symbol rx = PORTA.1
ConfigPin tx = Output
ConfigPin rx = Input

initialise_chip:
OSCCON = 11110000b 'oscillator = 32mhz
WaitMs 10
APFCON0 = 00000000b 'APFCON ????????????????????????????
'#################################################################

AllDigital
Symbol led_pin = PORTB.4
Symbol lcd_sck = PORTB.6 'tick
Symbol lcd_data = PORTB.4 'tick?
Symbol lcd_command = PORTB.7
Symbol lcd_reset = PORTB.5

definitions:

Define STRING_MAX_LENGTH = 30

Dim i As Byte
Dim j As Byte
Dim k As Byte

Dim li As Byte
Dim lj As Byte
Dim lk As Byte

Dim si As Byte
Dim sk As Byte

Dim byte_to_send As Byte
Dim x_value As Byte
Dim y_value As Byte
Dim character_to_send As Byte
Dim char(8) As Byte
Dim move_x As Byte
Dim string_to_write As String

Dim invert_display As Bit
Dim wrap_text As Bit

init:
ConfigPin PORTB = Output
'ConfigPin portd = OutputXXXXXXXXXXXXXXXXXXXXXXX

invert_display = 0
wrap_text = 0

WaitMs 100

Gosub init_lcd
Gosub lcd_clear

x_value = 2 'columns are individual pixels
y_value = 0 'must be a row number, which is a multiple of 8
Gosub lcd_goto_xy
Gosub draw_band


x_value = 2
y_value = 1
Gosub lcd_goto_xy
invert_display = 1
wrap_text = 0
string_to_write = "{ ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Gosub lcd_write_string
invert_display = 0

x_value = 2
y_value = 3
wrap_text = 1
Gosub lcd_goto_xy
string_to_write = "abcdefghijklmnopqrstuvwxyz"
Gosub lcd_write_string

x_value = 2
y_value = 5
Gosub lcd_goto_xy
string_to_write = "123.45.67.89:0"
Gosub lcd_write_string

loop:

High led_pin
WaitMs 2000
Low led_pin
WaitMs 2000

Goto loop
End

init_lcd:
Low lcd_reset
WaitMs 10
High lcd_reset

'put into command mode
Low lcd_command

byte_to_send = 0x21 'lcd extended commands
Gosub lcd_write_byte
byte_to_send = 0xb1 'set lcd contrast
Gosub lcd_write_byte
byte_to_send = 0x04 'set temp coefficient
Gosub lcd_write_byte
byte_to_send = 0x14 'lcd bias mode 1:48
Gosub lcd_write_byte
byte_to_send = 0x0c 'put lcd into normal mode
Gosub lcd_write_byte
byte_to_send = 0x20 'dunno
Gosub lcd_write_byte
byte_to_send = 0x0c 'dunno
Gosub lcd_write_byte
WaitMs 5

'put into data mode
High lcd_command

Return

lcd_write_byte:
For li = 0 To 7
lk = 7 - li
lj = 1
lj = ShiftLeft(lj, lk)
lj = lj And byte_to_send
If lj = 0 Then
'send a zero bit
Low lcd_data
Else
'send a one bit
High lcd_data
Endif

'toggle the clock line
High lcd_sck
ASM: nop
Low lcd_sck

Next li
Return

lcd_clear:

'put the cursor at 0,0
x_value = 0
y_value = 0
Gosub lcd_goto_xy

'put the lcd into data mode
High lcd_command

'send 504 (48*84/8) blank pixels
For i = 0 To 5
For j = 0 To 83
byte_to_send = 0x00
If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
Gosub lcd_write_byte
Next j
Next i

'just give everything a sec or two
WaitMs 10

Return

lcd_goto_xy:
Low lcd_command
byte_to_send = 0x80
byte_to_send = byte_to_send Or x_value
Gosub lcd_write_byte

byte_to_send = 0x40
byte_to_send = byte_to_send Or y_value
Gosub lcd_write_byte
High lcd_command
Return

lcd_get_character:

'set the default character to zero
char(0) = 0x00
char(1) = 0x00
char(2) = 0x00
char(3) = 0x00
char(4) = 0x00
char(5) = 0x00
char(6) = 0x00
move_x = 0

Select Case character_to_send
Case "A"
char(0) = 01111110b
char(1) = 00001001b
char(2) = 00001001b
char(3) = 01111110b
move_x = 5

Case "B"
char(0) = 01111111b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00110110b
move_x = 5

Case "C"
char(0) = 00011100b
char(1) = 00100010b
char(2) = 01000001b
char(3) = 01000001b
move_x = 5

Case "D"
char(0) = 01111111b
char(1) = 01000001b
char(2) = 01000001b
char(3) = 00100010b
char(4) = 00011100b
move_x = 6

Case "E"
char(0) = 01111111b
char(1) = 01001001b
char(2) = 01000001b
move_x = 4

Case "F"
char(0) = 01111111b
char(1) = 00001001b
char(2) = 00001001b
move_x = 4

Case "G"
char(0) = 00011100b
char(1) = 00100010b
char(2) = 01000001b
char(3) = 01001001b
char(4) = 01111010b
move_x = 6

Case "H"
char(0) = 01111111b
char(1) = 00001000b
char(2) = 00001000b
char(3) = 01111111b
move_x = 5

Case "I"
char(0) = 01000001b
char(1) = 01111111b
char(2) = 01000001b
move_x = 4

Case "J"
char(0) = 00100000b
char(1) = 01000000b
char(2) = 01000001b
char(3) = 00100001b
char(4) = 00011111b
move_x = 6

Case "K"
char(0) = 01111111b
char(1) = 00001000b
char(2) = 00010100b
char(3) = 01100011b
move_x = 5

Case "L"
char(0) = 01111111b
char(1) = 01000000b
char(2) = 01000000b
move_x = 4

Case "M"
char(0) = 01111111b
char(1) = 00000001b
char(2) = 00000010b
char(3) = 00001100b
char(4) = 00000010b
char(5) = 00000001b
char(6) = 01111111b
move_x = 8

Case "N"
char(0) = 01111111b
char(1) = 00000100b
char(2) = 00001000b
char(3) = 00010000b
char(4) = 01111111b
move_x = 6

Case "O"
char(0) = 00011100b
char(1) = 00100010b
char(2) = 01000001b
char(3) = 01000001b
char(4) = 00100010b
char(5) = 00011100b
move_x = 7

Case "P"
char(0) = 01111111b
char(1) = 00010001b
char(2) = 00010001b
char(3) = 00001110b
move_x = 5

Case "Q"
char(0) = 00011100b
char(1) = 00100010b
char(2) = 01000001b
char(3) = 01010001b
char(4) = 00100010b
char(5) = 01011100b
move_x = 7

Case "R"
char(0) = 01111111b
char(1) = 00011001b
char(2) = 00101001b
char(3) = 01000110b
move_x = 5

Case "S"
char(0) = 00100010b
char(1) = 01000101b
char(2) = 01001001b
char(3) = 00110010b
move_x = 5

Case "T"
char(0) = 00000001b
char(1) = 00000001b
char(2) = 01111111b
char(3) = 00000001b
char(4) = 00000001b
move_x = 6

Case "U"
char(0) = 00111111b
char(1) = 01000000b
char(2) = 01000000b
char(3) = 01111111b
move_x = 5

Case "V"
char(0) = 00000011b
char(1) = 00011100b
char(2) = 01100000b
char(3) = 00011100b
char(4) = 00000011b
move_x = 6

Case "W"
char(0) = 00111111b
char(1) = 01000000b
char(2) = 00100000b
char(3) = 00011000b
char(4) = 00100000b
char(5) = 01000000b
char(6) = 00111111b
move_x = 8

Case "X"
char(0) = 01100011b
char(1) = 00010100b
char(2) = 00001000b
char(3) = 00010100b
char(4) = 01100011b
move_x = 6

Case "Y"
char(0) = 00000011b
char(1) = 00000100b
char(2) = 01111100b
char(3) = 00000111b
move_x = 5

Case "Z"
char(0) = 01111001b
char(1) = 01001001b
char(2) = 01001101b
char(3) = 01001011b
move_x = 5

Case "a"
char(0) = 00100000b
char(1) = 01010100b
char(2) = 01010100b
char(3) = 01111000b
move_x = 5

Case "b"
char(0) = 01111111b
char(1) = 01000100b
char(2) = 01000100b
char(3) = 00111000b
move_x = 5

Case "c"
char(0) = 00111000b
char(1) = 01000100b
char(2) = 01000100b
char(3) = 01000100b
move_x = 5

Case "d"
char(0) = 00111000b
char(1) = 01000100b
char(2) = 01000100b
char(3) = 01111111b
move_x = 5

Case "e"
char(0) = 00111000b
char(1) = 01010100b
char(2) = 01010100b
char(3) = 01011100b
move_x = 5

Case "f"
char(0) = 01111110b
char(1) = 00001001b
char(2) = 00000001b
move_x = 4

Case "g"
char(0) = 10011000b
char(1) = 10100100b
char(2) = 10100100b
char(3) = 01111100b
move_x = 5

Case "h"
char(0) = 01111111b
char(1) = 00000100b
char(2) = 00000100b
char(3) = 01111000b
move_x = 5

Case "i"
char(0) = 01000100b
char(1) = 01111101b
char(2) = 01000000b
move_x = 4

Case "j"
char(0) = 10000100b
char(1) = 10000101b
char(2) = 01111100b
move_x = 4

Case "k"
char(0) = 01111111b
char(1) = 00010000b
char(2) = 00010000b
char(3) = 01101100b
move_x = 5

Case "l"
char(0) = 01000001b
char(1) = 01111111b
char(2) = 01000000b
move_x = 4

Case "m"
char(0) = 01111100b
char(1) = 00000100b
char(2) = 00000100b
char(3) = 01111000b
char(4) = 00000100b
char(5) = 00000100b
char(6) = 01111000b
move_x = 8

Case "n"
char(0) = 01111100b
char(1) = 00000100b
char(2) = 00000100b
char(3) = 01111000b
move_x = 5

Case "o"
char(0) = 00111000b
char(1) = 01000100b
char(2) = 01000100b
char(3) = 00111000b
move_x = 5

Case "p"
char(0) = 11111100b
char(1) = 00100100b
char(2) = 00100100b
char(3) = 00011000b
move_x = 5

Case "q"
char(0) = 00011000b
char(1) = 00100100b
char(2) = 00100100b
char(3) = 11111100b
move_x = 5

Case "r"
char(0) = 01111000b
char(1) = 00000100b
char(2) = 00000100b
char(3) = 00000100b
move_x = 5

Case "s"
char(0) = 01001000b
char(1) = 01010100b
char(2) = 01010100b
char(3) = 01010100b
char(4) = 00100000b
move_x = 6

Case "t"
char(0) = 00111111b
char(1) = 01000100b
char(2) = 01000100b
move_x = 4

Case "u"
char(0) = 00111100b
char(1) = 01000000b
char(2) = 01000000b
char(3) = 01111100b
move_x = 5

Case "v"
char(0) = 00011100b
char(1) = 00100000b
char(2) = 01000000b
char(3) = 00100000b
char(4) = 00011100b
move_x = 6

Case "w"
char(0) = 00111100b
char(1) = 01000000b
char(2) = 00100000b
char(3) = 00010000b
char(4) = 00100000b
char(5) = 01000000b
char(6) = 00111100b
move_x = 8

Case "x"
char(0) = 01101100b
char(1) = 00010000b
char(2) = 00010000b
char(3) = 01101100b
move_x = 5

Case "y"
char(0) = 10001100b
char(1) = 10010000b
char(2) = 10010000b
char(3) = 01111100b
move_x = 5

Case "z"
char(0) = 01100100b
char(1) = 01010100b
char(2) = 01001100b
move_x = 4

Case "0"
char(0) = 00111110b
char(1) = 01000001b
char(2) = 01000001b
char(3) = 00111110b
move_x = 5

Case "1", 1
char(0) = 01000010b
char(1) = 01111111b
char(2) = 01000000b
move_x = 4

Case "2", 2
char(0) = 01100010b
char(1) = 01010001b
char(2) = 01010001b
char(3) = 01001110b
move_x = 5

Case "3", 3
char(0) = 01000010b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00110110b
move_x = 5

Case "4", 4
char(0) = 00011111b
char(1) = 00010000b
char(2) = 00010000b
char(3) = 01111100b
char(4) = 00010000b
move_x = 6

Case "5", 5
char(0) = 00100111b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00110001b
move_x = 5

Case "6", 6
char(0) = 00111110b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00110010b
move_x = 5

Case "7", 7
char(0) = 00000001b
char(1) = 01110001b
char(2) = 00011001b
char(3) = 00000111b
move_x = 5

Case "8", 8
char(0) = 00110110b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00110110b
move_x = 5

Case "9", 9
char(0) = 00100110b
char(1) = 01001001b
char(2) = 01001001b
char(3) = 00111110b
move_x = 5

Case "."
char(0) = 01100000b
char(1) = 01100000b
move_x = 3

Case ":"
char(0) = 01100110b
char(1) = 01100110b
move_x = 3

Case 32
move_x = 4

Case "{"
Gosub draw_wifi

EndSelect

Return

send_character_to_lcd:

'put the lcd into data mode
High lcd_command

For i = 0 To 6
byte_to_send = char(i)
If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
Gosub lcd_write_byte
Next i

Return

lcd_write_string:

sk = Len(string_to_write) - 1
For si = 0 To sk

'convert the requested character into an array of bits to display
character_to_send = string_to_write(si)
Gosub lcd_get_character

'check the character will fit on the screen
k = x_value + move_x

If k > 82 And wrap_text = 0 Then
'don't write anything more on this line
x_value = 84
Else
If k > 82 Then
x_value = 2
y_value = y_value + 1
Gosub lcd_goto_xy
Endif

'send the character to the lcd
Gosub send_character_to_lcd

'update the "cursor x" position
x_value = x_value + move_x
Gosub lcd_goto_xy
Endif

Next si
Return

draw_band:
x_value = 0
Gosub lcd_goto_xy

'put the lcd into data mode
High lcd_command

byte_to_send = 11110000b
If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
For i = 0 To 83
Gosub lcd_write_byte
Next i

byte_to_send = 0xff
If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
For i = 0 To 83
Gosub lcd_write_byte
Next i

byte_to_send = 00000111b
If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
For i = 0 To 83
Gosub lcd_write_byte
Next i


Return

draw_wifi:

For i = 0 To 14
Select Case i
Case 0, 14
byte_to_send = 00001000b

Case 1, 13
byte_to_send = 00000100b

Case 2, 12
byte_to_send = 00000010b

Case 3, 11
byte_to_send = 00010010b

Case 4, 10
byte_to_send = 00001001b

Case 5, 9
byte_to_send = 00100101b

Case 6, 8
byte_to_send = 10010101b

Case 7
byte_to_send = 11010101b
EndSelect

If invert_display = 1 Then byte_to_send = byte_to_send Nand 0xff
Gosub lcd_write_byte
Next i

x_value = x_value + 16
Gosub lcd_goto_xy

Return
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby jtemples » Sun Oct 01, 2017 10:25 pm

APFCON doesn't apply to your PIC; you can delete that line.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: 18LF2520 with 5110 LCD

Postby camerart » Mon Oct 02, 2017 2:54 pm

Hi,
I've finished the circuit board? but there is a problem. I programmed a simple led flashing routine, a voltage shows flashing voltage at the PINs, app 1V, but the leds don't flash. If I short the 3.3V across to the PINs the leds light ok.
There is no voltage drop at the regulator.
I have a similar circuit as a previous project, and the LEDs flash ok.
C.
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby drh » Mon Oct 02, 2017 5:45 pm

Schematic?
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: 18LF2520 with 5110 LCD

Postby camerart » Mon Oct 02, 2017 8:47 pm

Hi D,
Unfortunately I don't have a schematic. I was playing with a circuit transfer method, so it was all deleted as it wasn't fully connected up, and I used extra wires.
Here's the PCB:
Hope it shows what you need.
Here's the simpler program I am trying:
C.

'18lf2520 8mHz INT 5110 021017 1221
'Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
Define CLOCK_FREQUENCY = 8
Define SINGLE_DECIMAL_PLACES = 2
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08 'INT OSC
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
AllDigital
OSCCON = %01110010 'internal 8Mhz clock
'SET PIN IN/OUT
TRISA = %00000001 'IN/OUT 0=Button
TRISB = %00000000
TRISC = %00010001 'RC4 SDI
'SET BITS ON/OFF
PORTA = %00000000 'ON/OFF
PORTB = %00000000
PORTC = %00000000
PORTE = %00001000 'POSS MCLR RE3
Symbol rstbutton = PORTE.3 '???????????????????????
Symbol button = PORTA.0
Symbol yled = PORTC.1
Symbol rled = PORTC.2
'Symbol cs = PORTB.0
'Symbol sck = PORTC.3
'Symbol sdi = PORTC.4 'MISO
'Symbol sdo = PORTC.5 'MOSI
'Symbol d102data = PORTA.2
start:
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000
yled = 1
WaitMs 1000
yled = 0
WaitMs 1000
Goto start
Attachments
CIRCUIT.jpg
CIRCUIT.jpg (56.34 KiB) Viewed 7093 times
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby camerart » Tue Oct 03, 2017 9:42 am

Update: I've just been checking resistances around the circuit, comparing with a working similar circuit. The working circuit show most PINs have 10ish Mohms, but the none working circuit shows Kohms, so it appears there is some shorting. I'll work on this.
C.
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby camerart » Tue Oct 03, 2017 11:29 am

Hi,
Removed the PIC and the solder paste had made a mess under it. Cleaned it re-soldered it and it's now working.
Lessons have been learnt!
C.
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Re: 18LF2520 with 5110 LCD

Postby camerart » Tue Oct 03, 2017 3:54 pm

Hi,
I've altered the program that I'm copying, to suit the wire connections.
It doesn't show anything on the LCD, but I can see from the LED that it is getting to the LOOP.
Do the connected PINs need pull-ups/downs?
C.
Attachments
18lf2520 8MHz INT 5110 031017 1530.txt
(13.95 KiB) Downloaded 399 times
User avatar
camerart
 
Posts: 9
Joined: Sun Oct 01, 2017 9:20 am
PIC experience: Experienced Hobbyist

Next

Return to Graphics and LCD

Who is online

Users browsing this forum: No registered users and 7 guests

cron