PDA

View Full Version : Trying to get LCD to work on 18f45k22 and portB and EasyPic V7 - no luck



dbachman
- 18th November 2017, 20:27
Hi,
I have tried everything I can think of to get this to work...anybody got any ideas what I am doing wrong or a missed setting?

Thanks Don


@ __CONFIG _CONFIG1H, _IESO_OFF_1H & _FCMEN_OFF_1H & _PRICLKEN_ON_1H & _PLLCFG_ON_1H & _FOSC_ECMPIO6_1H
@ __CONFIG _CONFIG2L, _PWRTEN_OFF_2L & _BOREN_SBORDIS_2L & _BORV_190_2L
@ __CONFIG _CONFIG2H, _WDTPS_32768_2H & _WDTEN_OFF_2H
@ __CONFIG _CONFIG3H, _MCLRE_EXTMCLR_3H & _T3CMX_PORTB5_3H & _HFOFST_ON_3H & _CCP3MX_PORTB5_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC1_3H
@ __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _XINST_OFF_4L & _LVP_OFF_4L & _STVREN_ON_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
'************************************************* ***************
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
Define LCD_Bits 4
DEFINE LCD_LINES 2
Define LCD_Commandus 2000
Define LCD_DATAUS 50

ANSELB = %00000000
TRISB = %00000000


pause 500
LCDOUT $FE,1,"Hello"

END

richard
- 18th November 2017, 21:27
_PLLCFG_ON_1H & _FOSC_ECMPIO6_1H


what sort of external clock are you using ?
@ what freq ?

you have no define OSC

TRISB = %00000000 is unnecessary for lcd

dbachman
- 18th November 2017, 22:16
Hi Richard,

I am using an 8mhz ext. crystal..

dbachman
- 18th November 2017, 22:32
Richard,

This code is written in Mikro Basic I think and works...I was trying to convert it to PicBasic..

Below it I have pasted the Config file that goes with it..

' *
' * Project name:
' Lcd_Test (Demonstration of the LCD library routines)
' * Copyright:
' (c) Mikroelektronika, 2011.
' * Revision History:
' 20110929:
' - initial release (FJ);
' * Description:
' This code demonstrates how to use LCD 4-bit library. LCD is first
' initialized, then some text is written, then the text is moved.
' * Test configuration:
' MCU: PIC18F45K22
' http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
' Dev.Board: EasyPIC7 - ac:LCD
' http://www.mikroe.com/easypic/
' Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
' Ext. Modules: Character Lcd 2x16
' http://www.mikroe.com/store/components/various/
' SW: mikroBasic PRO for PIC
' http://www.mikroe.com/mikrobasic/pic/
' * NOTES:
' - Turn on Lcd backlight switch SW4.6. (board specific)
' *

program Lcd

' Lcd module connections
dim LCD_RS as sbit at LATB4_bit
LCD_EN as sbit at LATB5_bit
LCD_D4 as sbit at LATB0_bit
LCD_D5 as sbit at LATB1_bit
LCD_D6 as sbit at LATB2_bit
LCD_D7 as sbit at LATB3_bit

dim LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections

dim txt1 as char[16]
txt2 as char[9]
txt3 as char[8]
txt4 as char[7]
i as byte ' Loop variable

sub procedure Move_Delay() ' Function used for text moving
Delay_ms(500) ' You can change the moving speed here
end sub

main:
ANSELB = 0 ' Configure PORTB pins as digital

txt1 = "mikroElektronika"
txt2 = "EasyPIC7"
txt3 = "Lcd4bit"
txt4 = "example"

Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
Lcd_Out(1,6,txt3) ' Write text in first row
Lcd_Out(2,6,txt4) ' Write text in second row
Delay_ms(2000)
Lcd_Cmd(_LCD_CLEAR) ' Clear display4

Lcd_Out(1,1,txt1) ' Write text in first row
Lcd_Out(2,5,txt2) ' Write text in second row
Delay_ms(500)

' Moving text
for i=0 to 3 ' Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT)
Move_Delay()
next i

while TRUE ' Endless loop
for i=0 to 7 ' Move text to the left 8 times
Lcd_Cmd(_LCD_SHIFT_LEFT)
Move_Delay()
next i

for i=0 to 7 ' Move text to the right 8 times
Lcd_Cmd(_LCD_SHIFT_RIGHT)
Move_Delay()
next i
wend
end.

The config file...

<?xml version="1.0"?>
<MCU_DEVICE_FLAGS>
<DEVICE>
<DEVICE_NAME>P18F45K22</DEVICE_NAME>
<VALUE>
<COUNT>11</COUNT>
<VALUE0>
<VAL>$300001:$0033</VAL>
</VALUE0>
<VALUE1>
<VAL>$300002:$001F</VAL>
</VALUE1>
<VALUE2>
<VAL>$300003:$003C</VAL>
</VALUE2>
<VALUE3>
<VAL>$300005:$00BD</VAL>
</VALUE3>
<VALUE4>
<VAL>$300006:$0081</VAL>
</VALUE4>
<VALUE5>
<VAL>$300008:$000F</VAL>
</VALUE5>
<VALUE6>
<VAL>$300009:$00C0</VAL>
</VALUE6>
<VALUE7>
<VAL>$30000A:$000F</VAL>
</VALUE7>
<VALUE8>
<VAL>$30000B:$00E0</VAL>
</VALUE8>
<VALUE9>
<VAL>$30000C:$000F</VAL>
</VALUE9>
<VALUE10>
<VAL>$30000D:$0040</VAL>
</VALUE10>
</VALUE>
</DEVICE>
</MCU_DEVICE_FLAGS>

richard
- 18th November 2017, 22:40
your config is incorrect for those settings




ASM
__config _CONFIG1H, _FOSC_HSHP_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__config _CONFIG2L, _PWRTEN_OFF_2L & _BOREN_SBORDIS_2L & _BORV_190_2L
__config _CONFIG2H, _WDTEN_ON_2H & _WDTPS_32768_2H
__config _CONFIG3H, _CCP2MX_PORTC1_3H & _PBADEN_OFF_3H & _CCP3MX_PORTB5_3H & _HFOFST_ON_3H & _T3CMX_PORTC0_3H & _P2BMX_PORTD2_3H & _MCLRE_EXTMCLR_3H
__config _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
__config _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
__config _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
__config _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
__config _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
__config _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
__config _CONFIG7H, _EBTRB_OFF_7H
ENDASM

and you need a


define OSC 32

statement in your code

why use a xtal ? why run at 8MHz ?
when the chip has a int osc that can do 64mhz

dbachman
- 18th November 2017, 23:53
Well that worked fine.....
Well the board has a crystal hook up but can be strapped in and out.
I did try just the define osc 32 with my config and it also worked...
as you probably surmised, I am pretty much a newbie..so why the ocs 32 define and say not 16 or 8?

By the way thanks a bunch

richard
- 19th November 2017, 00:13
define OSC 32
tells the compiler to perform all timing calculations for a clock speed of 32 MHz
it defaults to 4 MHz if omitted , it should match the real clock speed used
using 8 or 16 is simply wrong


_PLLCFG_ON with a 8mhz xtal yields a 32 MHz clock

no point guessing read the manual, read the data sheet

dbachman
- 19th November 2017, 01:00
Soif I was using an internal oscillator, I would define it in Config1h and further in OSCCON?

richard
- 19th November 2017, 01:27
using an internal oscillator, I would define it in Config1h and further in OSCCON?

yes

not forgetting if and when the pll is engaged
and setting define OSC appropriately

there is a tool called meconfig , look it up and download a copy , it makes life easier.
pity is that melabs don't update things much anymore so newer chips are missing , its still useful though

dbachman
- 19th November 2017, 01:56
Ok Richard Thank you but it looks like meconfig is not anywhere.. at least I couldn't find it to download..I will keep looking but ME labs has a posting that is discontinued and end of life....

richard
- 19th November 2017, 02:57
I couldn't find it to download.
me either, thats a shame . i better not have another pc crash or that may be the end of it


welcome to the Death Spiral (http://lexicon.ft.com/Term?term=death-spiral-(costing_based)) of legacy software

seems the spiral is tightening

dbachman
- 20th November 2017, 01:44
What is the chance you could email me a copy?

richard
- 20th November 2017, 02:30
ok , the install file is only 1900k bytes, but too big to post
pm me your email and I can send it


ps
maybe one of the moderators could upload it to Darrel's central repository , its his work after all

meConfig install that is

dbachman
- 21st November 2017, 00:32
I guess I don't know how to pm..lol

richard
- 21st November 2017, 05:33
I guess I don't know how to pm..lol
Like this Don