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 Basic tut file

Status
Not open for further replies.

Mosaic

Well-Known Member
16f886 PIC @ 8Mhz.

I have this modified BASIC tut program which works in Oshonsoft but the hex file produces gibberish in Proteus using the LM016L LCD module. This module works fine with Nigel's ASM LCD tut.


Code:
Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 20  'default value is 20
Define LCD_BITS = 4  'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 1
Define LCD_RWREG = 0  'portc  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  '2  'set to 0 if not used, 0 is default
'Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
'Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
'Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device

Dim an0 As Word
AllDigital
TRISA = 0xff  'set all PORTA pins as inputs
ADCON1 = 0  'set all PORTA pins as analog inputs
Lcdinit 1  'initialize LCD module; cursor is blinking

loop:
	Adcin 0, an0
	Lcdcmdout LcdClear  'clear LCD display
	Lcdout "Analog input AN0"  'text for the line 1
	Lcdcmdout LcdLine2Home  'set cursor at the beginning of line 2
	Lcdout "Value: ", #an0  'formatted text for line 2
	WaitMs 100  
Goto loop  'loop forever

Proteus layout image attached, and here is the asm file that Oshon created that produces the gibberish in Proteus
Code:
	list p=16f886
	#include <p16f886.inc>
	radix dec
; Compiled with: PIC Simulator IDE v6.91
; Microcontroller model: PIC16F886
; Clock frequency: 8.0 MHz
;
;       The address of 'an0' (word) (global) is 0x35
	an0 EQU 0x35
; Begin
	R0L EQU 0x20
	R0H EQU 0x21
	R1L EQU 0x22
	R1H EQU 0x23
	R2L EQU 0x24
	R2H EQU 0x25
	R3L EQU 0x26
	R3H EQU 0x27
	R4L EQU 0x28
	R4H EQU 0x29
	R5L EQU 0x2A
	R5H EQU 0x2B
	ORG 0x0000
	BCF PCLATH,3
	BCF PCLATH,4
	GOTO L0002
	ORG 0x0004
	RETFIE
; Begin of program
L0002:
; 1: Define ADC_CLOCK = 3  'default value is 3
; 2: Define ADC_SAMPLEUS = 20  'default value is 20
; 3: Define LCD_BITS = 4  'allowed values are 4 and 8 - the number of data interface lines
; 4: Define LCD_DREG = PORTB
; 5: Define LCD_DBIT = 4  '0 or 4 for 4-bit interface, ignored for 8-bit interface
; 6: Define LCD_RSREG = PORTB
; 7: Define LCD_RSBIT = 0
; 8: Define LCD_EREG = PORTB
; 9: Define LCD_EBIT = 1
; 10: Define LCD_RWREG = 0  'portc  'set to 0 if not used, 0 is default
; 11: Define LCD_RWBIT = 0  '2  'set to 0 if not used, 0 is default
; 12: 'Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
; 13: 'Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
; 14: 'Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
; 15: 'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
; 16: 
; 17: Dim an0 As Word
; 18: AllDigital
	BSF STATUS,RP0
	BSF STATUS,RP1
	CLRF 0x08
	CLRF 0x09
	BCF STATUS,RP1
	BCF STATUS,RP0
; 19: TRISA = 0xff  'set all PORTA pins as inputs
	MOVLW 0xFF
	BSF STATUS,RP0
	MOVWF 0x05
; 20: ADCON1 = 0  'set all PORTA pins as analog inputs
	CLRF 0x1F
	BCF STATUS,RP0
; 21: Lcdinit 1  'initialize LCD module; cursor is blinking
	BCF PORTB,1
	BCF PORTB,0
	BSF STATUS,RP0
	BCF TRISB,1
	BCF TRISB,0
	MOVLW 0x0F
	ANDWF TRISB,F
	MOVLW 0x64
	BCF STATUS,RP0
	MOVWF R0L
	CLRF R0H
	CALL W001
	MOVLW 0x33
	CALL LC02
	MOVLW 0x33
	CALL LC02
	MOVLW 0x33
	CALL LC02
	MOVLW 0x22
	CALL LC02
	MOVLW 0x28
	CALL LC02
	MOVLW 0x0D
	CALL LC02
	MOVLW 0x01
	CALL LC02
; 22: 
; 23: loop:
L0001:
; 24: 	Adcin 0, an0
	BSF STATUS,RP0
	BSF ADCON1,ADFM
	BCF STATUS,RP0
	CLRF R0L
	CALL A001
	BSF STATUS,RP0
	MOVF ADRESL,W
	BCF STATUS,RP0
	MOVWF 0x35
	MOVF ADRESH,W
	MOVWF 0x36
; 25: 	Lcdcmdout LcdClear  'clear LCD display
	MOVLW 0x01
	CALL LC02
; 26: 	Lcdout "Analog input AN0"  'text for the line 1
	MOVLW 0x41
	CALL LC01
	MOVLW 0x6E
	CALL LC01
	MOVLW 0x61
	CALL LC01
	MOVLW 0x6C
	CALL LC01
	MOVLW 0x6F
	CALL LC01
	MOVLW 0x67
	CALL LC01
	MOVLW 0x20
	CALL LC01
	MOVLW 0x69
	CALL LC01
	MOVLW 0x6E
	CALL LC01
	MOVLW 0x70
	CALL LC01
	MOVLW 0x75
	CALL LC01
	MOVLW 0x74
	CALL LC01
	MOVLW 0x20
	CALL LC01
	MOVLW 0x41
	CALL LC01
	MOVLW 0x4E
	CALL LC01
	MOVLW 0x30
	CALL LC01
; 27: 	Lcdcmdout LcdLine2Home  'set cursor at the beginning of line 2
	MOVLW 0xC0
	CALL LC02
; 28: 	Lcdout "Value: ", #an0  'formatted text for line 2
	MOVLW 0x56
	CALL LC01
	MOVLW 0x61
	CALL LC01
	MOVLW 0x6C
	CALL LC01
	MOVLW 0x75
	CALL LC01
	MOVLW 0x65
	CALL LC01
	MOVLW 0x3A
	CALL LC01
	MOVLW 0x20
	CALL LC01
	MOVF 0x35,W
	MOVWF 0x32
	MOVF 0x36,W
	MOVWF 0x33
	CALL _append_lab_0001
	CALL LC21
; 29: 	WaitMs 100  'larger value should be used in real device
	MOVLW 0x64
	MOVWF R0L
	CLRF R0H
	CALL W001
; 30: Goto loop  'loop forever
	GOTO L0001
; End of program
L0003:	GOTO L0003
; Waitms Routine
W001:	MOVF R0L,F
	BTFSC STATUS,Z
	GOTO W002
	CALL W003
	DECF R0L,F
	NOP
	NOP
	NOP
	NOP
	NOP
	GOTO W001
W002:	MOVF R0H,F
	BTFSC STATUS,Z
	RETURN
	CALL W003
	DECF R0H,F
	DECF R0L,F
	GOTO W001
W003:	MOVLW 0x0C
	MOVWF R2H
W004:
	DECFSZ R2H,F
	GOTO W004
	NOP
	NOP
	MOVLW 0x26
	MOVWF R1L
W005:
	DECFSZ R1L,F
	GOTO W006
	CALL W007
	CALL W007
	NOP
	NOP
	RETURN
W006:
	CALL W007
	GOTO W005
W007:	MOVLW 0x0D
	MOVWF R2L
W008:
	DECFSZ R2L,F
	GOTO W008
	NOP
	RETURN
; Waitus Routine Byte
X001:	MOVLW 0x05
	SUBWF R4L,F
	BTFSS STATUS,C
	RETURN
	GOTO X002
X002:	MOVLW 0x03
	SUBWF R4L,F
	BTFSS STATUS,C
	RETURN
	GOTO X002
; Waitus Routine Word
Y001:	MOVLW 0x08
	SUBWF R4L,F
	CLRW
	BTFSS STATUS,C
	ADDLW 0x01
	SUBWF R4H,F
	BTFSS STATUS,C
	RETURN
	GOTO Y002
Y002:	MOVLW 0x05
	SUBWF R4L,F
	CLRW
	BTFSS STATUS,C
	ADDLW 0x01
	SUBWF R4H,F
	BTFSS STATUS,C
	RETURN
	GOTO Y002
; Word Division Routine
D001:	MOVLW 0x10
	MOVWF R3L
	CLRF R2H
	CLRF R2L
D002:	RLF R0H,W
	RLF R2L,F
	RLF R2H,F
	MOVF R1L,W
	SUBWF R2L,F
	MOVF R1H,W
	BTFSS STATUS,C
	INCFSZ R1H,W
	SUBWF R2H,F
	BTFSC STATUS,C
	GOTO D003
	MOVF R1L,W
	ADDWF R2L,F
	MOVF R1H,W
	BTFSC STATUS,C
	INCFSZ R1H,W
	ADDWF R2H,F
	BCF STATUS,C
D003:	RLF R0L,F
	RLF R0H,F
	DECFSZ R3L,F
	GOTO D002
	RETURN
; Adcin Routine
A001:	RLF R0L,F
	RLF R0L,F
	MOVLW 0x3C
	ANDWF R0L,F
	MOVLW 0xC1
	IORWF R0L,W
	MOVWF ADCON0
	MOVLW 0x14
	MOVWF R4L
	CALL X001
	BSF ADCON0,GO
A002:
	BTFSC ADCON0,GO
	GOTO A002
	BCF PIR1,ADIF
	BCF ADCON0,ADON
	RETURN
; Lcdout Routine
LC01:	MOVWF R4L
	BSF PORTB,0
	MOVLW 0x0F
	ANDWF PORTB,F
	MOVF R4L,W
	ANDLW 0xF0
	IORWF PORTB,F
	CALL LCX1
	SWAPF R4L,F
	MOVLW 0x0F
	ANDWF PORTB,F
	MOVF R4L,W
	ANDLW 0xF0
	IORWF PORTB,F
	CALL LCX1
	MOVLW 0x64
	MOVWF R4L
	CALL X001
	RETURN
LCX1:	BSF PORTB,1
	NOP
	NOP
	BCF PORTB,1
	NOP
	NOP
	RETURN
; Lcdcmdout Routine
LC02:	MOVWF R4L
	BCF PORTB,0
	MOVLW 0x0F
	ANDWF PORTB,F
	MOVF R4L,W
	ANDLW 0xF0
	IORWF PORTB,F
	CALL LCX1
	SWAPF R4L,F
	MOVLW 0x0F
	ANDWF PORTB,F
	MOVF R4L,W
	ANDLW 0xF0
	IORWF PORTB,F
	CALL LCX1
	MOVLW 0x88
	MOVWF R4L
	MOVLW 0x13
	MOVWF R4H
	CALL Y001
	RETURN
; Lcdout Decimal Conversion Routine
LC21:
	MOVLW 0x2C
	MOVWF FSR
LC22:
	MOVF INDF,W
	BTFSC STATUS,Z
	RETURN
	INCF FSR,F
	CALL LC01
	GOTO LC22
; APPEND CODE BEGIN: _routine_ascii_word_
_append_lab_0001:
	MOVLW 0x2C
	MOVWF FSR
	BCF 0x34,0
	MOVF 0x32,W
	MOVWF R2L
	MOVF 0x33,W
	MOVWF R2H
	MOVLW 0x10
	MOVWF R1L
	MOVLW 0x27
	MOVWF R1H
	CALL _append_lab_0002
	MOVLW 0xE8
	MOVWF R1L
	MOVLW 0x03
	MOVWF R1H
	CALL _append_lab_0002
	MOVLW 0x64
	MOVWF R1L
	CLRF R1H
	CALL _append_lab_0002
	MOVLW 0x0A
	MOVWF R1L
	CLRF R1H
	CALL _append_lab_0002
	MOVF R2L,W
	CALL _append_lab_0003
	CLRF 0x00
	RETURN
_append_lab_0002:
	MOVF R2L,W
	MOVWF R0L
	MOVF R2H,W
	MOVWF R0H
	CALL D001
	MOVF R0L,W
	BTFSC 0x03,2
	GOTO L0004
	BSF 0x34,0
L0004:
	BTFSS 0x34,0
	GOTO L0005
_append_lab_0003:
	ADDLW 0x30
	MOVWF 0x00
	INCF FSR,f
L0005:
	RETURN
; APPEND CODE END.
; End of listing
	END

Any advice as to what's going on is appreciated!!
 
Last edited:
I have never been able to get Oshonsoft's 4 bit interface to work.... I have always had to split the control port and data port.

Vladimir must have a small bug when OR'ing or AND'ing when writing to the screen. OR there needs to be a tiny delay between nibble writes.

I gave up.
 
hi Ian & OP,
I have never had a problem with 4 bit LCD with Oshonsoft, split or separate Ports.

Try this demo program uses PORTB, 4 bit Data and 3 Control, lets know if you have a problem.

Eric
 
hi Mosiac,
Your Basic program is incorrect. Note image3, shows no ADC pins.

Look at this modified version. image2 shows ADC pins.

Note: the changed lines have '++++++++++++ append

Code:
Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 20  'default value is 20
Define LCD_BITS = 4  'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 1
Define LCD_RWREG = 0  'portc  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  '2  'set to 0 if not used, 0 is default
'Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
'Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
'Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device

Dim an0 As Word
'AllDigital'+++++++++++++++++++++++

TRISA = 0xff  'set all PORTA pins as inputs
ANSELH = 0  '+++++++++++++++++++++++

ADCON1 = 0  'set all PORTA pins as analog inputs
Lcdinit 1  'initialize LCD module; cursor is blinking

loop:
	Adcin 0, an0
	Lcdcmdout LcdClear  'clear LCD display

	Lcdout "Analog input AN0"  'text for the line 1
	Lcdcmdout LcdLine2Home  'set cursor at the beginning of line 2
	Lcdout "Value: ", #an0  'formatted text for line 2
	WaitMs 100
	Goto loop  'loop forever
 
Last edited:
Still fails in Proteus ISIS

Eric, the analog issue u isolated isn't quite the issue here. While I have no problem with the oshonsoft simulation. The asm generated produces a scrambled output in the simulator I NEED to use for the other electronic circuit elements!

Note the garbled LCD in the image!

Can u advise on why that fails? Once more, Nigel's ASM LCD tut works fine in ISIS.

Edit: Nigel's hex loads and works fine in the Oshon sim. It appears that there is a lot more delay in between each letter sent in his code. I haven't been able to get this to work by adding delays in Oshon. The LCX1 routine in the Oshon asm file handles the clocking of a new char into the display. Placing a 1 ms wait does slow the lettering but no diff. to the garble. Accelerating the LCD properties in ISIS from 250Khz to 8Mhz...no improvement. There's something else going on.
 
Last edited:
Like I said...... I've never got it working in ISIS....... The code always looks good, but ISIS is unforgiving. If there NEEDS to be a clock between two commands the ISIS fails ( In the real world, it may work beautifully ).... ISIS is, unfortunately, digital.... event driven.... Remember the clocks on the real devices are independent, whereas in ISIS they are not.
 
Try a simpler example and make sure you callout the config word and OSCCON definition.

Code:
'General Device Configuration
Define CONF_WORD = 0x23c4
Define CONF_WORD_2 = 0x3eff
Define CLOCK_FREQUENCY = 8
OSCCON = 0x70  'define internal 8MHz clock

Define LCD_BITS = 4  'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 1
Define LCD_RWREG = 0  'portc  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  '2  'set to 0 if not used, 0 is default
'Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
'Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
'Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device

Dim cnt As Byte
AllDigital
TRISA = 0xff  'set all PORTA pins as inputs
Lcdinit 1  'initialize LCD module; cursor is blinking

loop:
	Lcdcmdout LcdClear  'clear LCD display
	Lcdout "Value:"  'text for line 1
	For cnt = 0 To 100
		Lcdcmdout LcdLine2Home  'set cursor at the beginning of line 2
		Lcdout #cnt  'formatted text for line 2
		WaitMs 100
	Next cnt
Goto loop  'loop forever
 
No luck with that. Super annoying.
I want to do BASIC programming as I have text and data to LCD display and I need to do a menu and some 32bit math and now this....
If I stay in Oshon I can't simulate the FETs/opamp external voltage inputs, and other such components interaction. If I go ISIS I gotta do it all in asm. I need to use both tools.

Is there a way I can just do an asm LCD display module/lib that oshon soft can call that I can make compatible with ISIS?

Edit:
I spent a few hours on this....I have to gut the entire OSHON LCD INIT sequence and replace it with Nigel's asm version to even get the cursor to flash. Two factors identified so far 1) The 100ms init delay needs to be about 165ms. 2) The init LCD cmds must be 20h,28h,06h,0dh,01h ; NOT 33h,33h,33h,22h, etc. There ALSO seems to be an issue with if the LCD E pin starts low or high, b4 the init sequence delay. Oddly it appears that high is better. I also had to replace the entire 4 bit LCD (LC02: )write sequence with Nigel's version.

The sum total of it is that there are significant issues with the Oshon approach to what ISIS accepts. There isn't an easy fix, but I did get it to work in ISIS after the surgery described. I'll have to probably create a single chunk of asm to patch the OSHON code. At least the oshon simulator accepts the 'ISIS repaired code' which works just like the weird (ISIS incompatible) OSHON native code.
 
Last edited:
You can.... If you write your own it will still work tickey boo..... I wrote a GLCD library for Oshonsoft for the T6963C chip and sent it to Vladimir .... But it must have been rubbish as he never implemented it.. Take my C routines ( from the tutorial page ) and convert them to basic... It wont take long. You then place them in a module... The only thing I couldn't do was print strings, so I used lookup tables.... BUT... Since then, Vladimir has included a pointer...
 
If I stay in Oshon I can't simulate the FETs/opamp external voltage inputs, and other such components interaction. If I go ISIS I gotta do it all in asm. I need to use both tools.

hi Mosaic,
I have some external modules for Oshonsoft that may help with the external voltage inputs.

If you can say what type of external inputs you need for the Simulation, I may be able to help.

E.
 
I've done some thinking

Here is a working LCD routine...

Code:
Define CONF_WORD = 0x23c4
Define CONF_WORD_2 = 0x3eff

Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 20  'default value is 20


Dim an0 As Word
Dim t As Byte
Dim ch As Byte
TRISB = 0
TRISA = 0xff  'set all PORTA pins as inputs
ANSEL = 1  'set all PORTA pins as analog inputs
ANSELH = 0

Call lcd_init()

loop:
	Adcin 0, an0
	Call lcd_cmd(0x80)  'clear LCD display
	For t = 0 To 16
			ch = LookUp("Analog input AN0"), t
			Call lcd_data(ch)
	Next t
	Call lcd_cmd(0xc0)  'set cursor at the beginning of line 2
	For t = 0 To 8
			ch = LookUp("value = "), t
			Call lcd_data(ch)
	Next t
	Call lcd_print(an0)
	Call lcd_data(0x20)
	WaitMs 100
Goto loop  'loop forever
End                                               

Proc lcd_init()
	WaitMs 100
	PORTB = 0x20
	WaitUs 10
	Call lcd_clk()
	WaitMs 15
	Call lcd_clk()
	WaitMs 15
	Call lcd_cmd(0x28)
	Call lcd_cmd(0xc)
	Call lcd_cmd(0x1)
End Proc                                          

Proc lcd_cmd(x As Byte)
	PORTB = x And 0xf0
	WaitUs 10
	Call lcd_clk()
	WaitMs 5
	PORTB = 0
	x = ShiftLeft(x, 4)
	PORTB = x And 0xf0
	WaitUs 10
	Call lcd_clk()
	WaitMs 5
End Proc                                          

Proc lcd_data(x As Byte)
	PORTB = x And 0xf0
	RB0 = 1
	WaitUs 10
	Call lcd_clk()
	WaitMs 5
	PORTB = 0
	x = ShiftLeft(x, 4)
	PORTB = x And 0xf0
	RB0 = 1
	WaitUs 10
	Call lcd_clk()
	WaitMs 5
End Proc                                          

Proc lcd_clk()
	RB1 = 1
	WaitUs 20
	RB1 = 0
End Proc                                          

Proc lcd_print(x As Word)
	Dim numb As Word
	Dim start As Bit
	start = True
	numb = x / 10000
	If numb > 0 Then
		x = x - (numb * 10000)
		numb = numb + 48
		Call lcd_data(numb)
		start = False
	Endif
	numb = x / 1000
	If numb > 0 Or start = 0 Then
		x = x - (numb * 1000)
		numb = numb + 48
		Call lcd_data(numb)
		start = False
	Endif
	numb = x / 100
	If numb > 0 Or start = 0 Then
		x = x - (numb * 100)
		numb = numb + 48
		Call lcd_data(numb)
		start = False
	Endif
	numb = x / 10
	If numb > 0 Or start = 0 Then
		x = x - (numb * 10)
		numb = numb + 48
		Call lcd_data(numb)
	Endif
	x = x + 48
	Call lcd_data(x)
	
End Proc

The print routine needs some work.... But it works in ISIS
By the way ..... If you edit the ASM output then compile the asm..... Change all the 0x33's in the init routine for 0x22's... re assemble.... it should work in ISIS.

This should get you going though..... its the same as the C code..
 
@ Eric:

I expect to have a FWB rectified sinewave 0-4.5V input to the C2 comparator inputs to determine phase shift.

I have to drive an NFET with a software PWM pulse.
Also drive another NFET with a hw pwm pulse via a low pass filter for linear control.
I have to track the charging start & peak voltages for a capacitor to calc the avg current flow. The capacitor is partially discharged regularly by the Nfet with the soft pulse.
I need to interface with a rotary incremental encoder for the menu system.


@Ian:
I need a guide as to how to make my own OSHON LCD module pls!

Edit: I see you are using Oshon to do it's own parsing. I guess an LCD init PROC can also be created to deliver a proper init/delay. It seems like a decent option that gives a bit more control. Thanks!
 
Last edited:
ISIS Compatible OSHON Hybrid

Ok, based on the assistance of the forum I have come up with an OSHON compatible HD44780 LCD approach to simulating in ISIS. For full Oshon compatibility just replace the INIT & Cmd proc calls with the Oshon equivalent.

This approach permits the use of all Oshon instructions and allows the 4 data line & 2 control line single port LCD interface. I use PORTB.

I hope this sample Oshon Basic Compiler code helps others.

Code:
'General Device Configuration , 16f886 - Use of the procs below cause this to work in ISIS.
'Once the LCD init and all LCD cmds are handled by the PROCedures below , regular OSHON instructions function with ISIS sim (LM016L LCD)
Define CONF_WORD = 0x23c4
Define CONF_WORD_2 = 0x3eff
Define CLOCK_FREQUENCY = 8
OSCCON = 0x70  'define internal 8MHz clock

Define LCD_BITS = 4  'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0  '0 low port nybble or 4 hi port nybble for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB  'note match this in lcd_cmd Proc below
Define LCD_RSBIT = 7
Define LCD_EREG = PORTB  'note match this in lcd_init Proc below
Define LCD_EBIT = 6
Define LCD_RWREG = 0   'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  '2  'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 100  'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they can be omitted for a real device

Dim cnt As Byte
Dim an13 As Word  '10bit adc.
AllDigital
TRISB = %00110000  'set rb5,rb4 portb pins as dig. inputs
ANSELH = %00100000  'an13,rb5 is analog input
ADCON1 = 0
Lcdinit 1  'initialize OSHON LCD module; cursor is blinking
Call lcd_init()  'ISIS lcd init.

loop:

	Adcin 13, an13  'sample ADC
	Call lcd_cmd(0x01)  'clear lcd
	Call lcd_cmd(0x86)  'set cursor to start+6
	Lcdout "Value:"  'text for line 1
	For cnt = 1 To 100
		Call lcd_cmd(0xc0)  'set cursor at the beginning of line 2
		Lcdout #cnt  'formatted text for line 2
		Lcdout "  analog : " #an13  'output decimal adc.
		WaitMs 10
	Next cnt
Goto loop  'loop forever

End                                               
Proc lcd_init()  'http://www.geocities.com/dinceraydin/lcd/commands.htm
	PORTB.6 = 1  'set e line High, reqd for ISIS.
	WaitMs 165
	Call lcd_cmd(0x20)
	Call lcd_cmd(0x28)
	Call lcd_cmd(0x06)
	Call lcd_cmd(0x0c)  '0x0d => cursor.
	Call lcd_cmd(0x01)
End Proc                                          
Proc lcd_clk()  'clocks the data lines into the  LCD controller, if RS line is 0 then data = an LCD command.
	PORTB.6 = 1  'eline
	WaitUs 20
	PORTB.6 = 0
End Proc                                          
Proc lcd_cmd(x As Byte)  'splits the command byte into two clocked nybbles.Send hi then low nybbles.
	Dim y As Byte
	y = ShiftRight(x, 4)  'shift hi nyb to low, as data lines are the low nybble of the port, not required for hi nybble data lines.
	PORTB = y And 0x0f  'clear hi nyb, use f0 if data line were the hi nybble
	PORTB.7 = 0  'clr rs line to take cmds
	WaitUs 10
	Call lcd_clk()  'edge trigger the 1st nybble of the command on the data lines
	WaitMs 5
	PORTB.7 = 0  'clr rs line to take cmds
	'x = ShiftRight(x, 4) 'required if data lines were the hi nybble of the port.
	PORTB = x And 0x0f  'clear hi nybble, use f0 if data line were the hi nybble
	WaitUs 10
	Call lcd_clk()  'clock the low nybble of the command.
	WaitMs 5
End Proc

EDIT: I found these links to be good resources:
https://www.electro-tech-online.com/threads/links-character-lcds-tutorials-and-info.112077/
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top