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.BAS sample

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi all:
I am using a 16f886 at 8Mhz

I modded the LCD.bas sample to read:

Code:
Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 10  '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 = 0  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
Define LCD_RWREG = 0  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2  '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

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 1  'larger value should be used in real device
Goto loop  'loop forever

This fails....it specifically will work if I change the LCD RSREG and EREG to operate off PORTC or PORTA.

Why doesn't the sim permit me to use portb.4 and b.5 as the control lines? It allows A.4, A.5 or C.4, C.5.
 
Last edited:
FYI B.6 and B.7 also do not work as control lines...the sim fails..I can't see why...the uC view shows the lines operating correctly. I use the CTRL-O option just to be sure the LCD module is setup right.
 
Hi
Look at this for the required settings.

Code:
Define SIMULATION_WAITMS_VALUE = 1
AllDigital

Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 10  '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 = 0  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
Define LCD_RWREG = 0  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  'set to 0 if not used, 0 is default

Define LCD_COMMANDUS = 1000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2  '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

TRISA = 0xff  'set all PORTA pins as inputs
TRISB = 0x00

ANSEL = %00000011
'Initialize the A/D converter
ADCON1 = %00000001  'Make AN0 analog inputs,
'make reference voltage = VDD
ADCON0 = %11000101  'A/D clock is internal RC, select AN0

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 1  'larger value should be used in real device
    Goto loop  'loop forever
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    6.3 KB · Views: 412
It won't work because PortB is still set to analogue. Try adding ANSELH = 0.

I have no idea why it works for Eric.

Mike.
 
It won't work because PortB is still set to analogue. Try adding ANSELH = 0.

I have no idea why it works for Eric.

Mike.

hi Mike,
Its the 'AllDigital' command

Code:
; 2: AllDigital
    BSF STATUS,RP0
    BSF STATUS,RP1
    CLRF 0x08
    CLRF 0x09
    BCF STATUS,RP1
    BCF STATUS,RP0

Eric
 
Good info

Thanks Guys, This is my 1st MCU BASIC exercise and I'm still figuring out how much is done for u and how much needs to be explicit.

I refined the PORT config code to this:

Code:
Dim an0 As Word
AllDigital  'ansel & anselh to 0.
TRISA = %00000001  'set  PORTA.0 pin as input
TRISB = 0x00  'POrtb all outputs
ANSEL = %00000001  'Make AN0 analog input

'Initialize the A/D converter
ADCON1 = %00000000  'make reference voltage = VDD, AdresH/L left justified
'as INTOSC is 8Mhz =>
ADCON0 = %10000101  'A/D clock is internal Fosc/32 , select AN0, enable conversion.

A question:
If I dimensioned the An0 as a byte, would that automatically truncate the lowest 2 bits (of 10) from the ADC sample leaving the 8MSB as ADRESH is left justified?
 
Last edited:
If you try the code in oshonsoft's simulator it works ok.. On proteus ISIS it doesn't and very rarely in realtime. If you look at the assembled file you will notice Vladimir has forgotten to add the delay in the routine LCDinit. when in 4 bit mode and only when the same port is used for both data and control lines, I haven't checked when using the high nibble

Cheers Ian
 
Last edited:
A question:
If I dimensioned the An0 as a byte, would that automatically truncate the lowest 2 bits (of 10) from the ADC sample leaving the 8MSB as ADRESH is left justified?

hi

Yes, a BYTE will be ADRESH only.
 
If you try the code in oshonsoft's simulator it works ok.. On proteus ISIS it doesn't and very rarely in realtime. If you look at the assembled file you will notice Vladimir has forgotten to add the delay in the routine LCDinit. when in 4 bit mode and only when the same port is used for both data and control lines, I haven't checked when using the high nibble

Cheers Ian

How much delay is required? Can I simulate from within basic or do I have to drop to asm?
 
Actually I managed to get this working!! adding the delay (in the right place) did nothing. The fix was the small delay required in between sending the high and low nibble.. I put a small 10us delay and it worked fine (you have to edit the assembled file LCDout and LCDcmdout routines).

Cheers Ian

I have emailed Vladimir and reported this little hiccup..
 
Last edited:
ian,
I am trying in ISIS ..no luck..getting gibberish from the LM016L LCD. I am running it from a 16F886 with the following BASIC code. Note PortC.4 & C.5 are the control lines. I have grounded pins 1,3,5 on the LCD. Portb.0 thru b.3 drives LCD pins 11 thru 14.

16f886 Config words : 23c4 and 3FFF.

Code:
Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 10  '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 = 0  '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 4
Define LCD_EREG = PORTC
Define LCD_EBIT = 5
Define LCD_RWREG = 0  'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0  'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 2  '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  'ansel & anselh to 0.
TRISA = %00000001  'set  PORTA.0 pin as input
TRISB = 0x00  'POrtb all outputs
ANSEL = %00000001  'Make AN0 analog input
OSCCON = %01111100  'set 8mhz, osc setup based On Config fuses.

'Initialize the A/D converter
ADCON1 = %00000000  'make reference voltage = VDD, AdresH/L left justified
'as INTOSC is 8Mhz =>
ADCON0 = %10000101  'A/D clock is internal Fosc/32 , select AN0, enable conversion.
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 50  'larger value 50ms should be used in real device
Goto loop  'loop forever

Any suggestions?
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top