1. 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.
    Dismiss Notice

LCD.BAS sample

Discussion in 'Oshonsoft' started by Mosaic, Mar 29, 2011.

  1. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,617
    Likes:
    129
    Location:
    Caribbean
    Hi all:
    I am using a 16f886 at 8Mhz

    I modded the LCD.bas sample to read:

    Code (text):
    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: Mar 29, 2011
  2. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,617
    Likes:
    129
    Location:
    Caribbean
    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.
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    Hi
    Look at this for the required settings.

    Code (text):
    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
     

    Attached Files:

  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia

    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.
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi Mike,
    Its the 'AllDigital' command

    Code (text):
    ; 2: AllDigital
        BSF STATUS,RP0
        BSF STATUS,RP1
        CLRF 0x08
        CLRF 0x09
        BCF STATUS,RP1
        BCF STATUS,RP0
    Eric
     
  7. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,617
    Likes:
    129
    Location:
    Caribbean
    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 (text):
    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: Mar 30, 2011
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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: Mar 30, 2011
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi

    Yes, a BYTE will be ADRESH only.
     
  10. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,617
    Likes:
    129
    Location:
    Caribbean
    How much delay is required? Can I simulate from within basic or do I have to drop to asm?
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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: Mar 31, 2011
  12. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,617
    Likes:
    129
    Location:
    Caribbean
    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 (text):
    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: Mar 30, 2011
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I get virtually the same results.. If I bang it into 8 bit mode it works good.. BTW if you attach the ASM file to ISIS then complie the ASM file from within ISIS you have full debugging.

    Cheers Ian
     

Share This Page