News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Reinitializing LCD

Started by shantanu@india, Feb 27, 2022, 08:35 AM

Previous topic - Next topic

shantanu@india

Hi,
I had previously used Clear BFP.1 to reinitialize alphanumeric HD44780 based displays.
It used to work quite well.
I just had to include:

Declare SHOW_SYSTEM_VARIABLES = True
Dim  BPF        As Byte System

....and execute Clear BFP.1 at regular intervals.
This feature is not working anymore.
Regards
Shantanu

top204

#1
The BPF system variable is still valid and still works because I use it in programs a lot, when I place a microcontroller to sleep and have to bring lines low and turn off an LCD, then after waking up, power up the LCD.

First, bring the compiler's system variable BPF into the program's listing:

    Dim BPF As Byte System            ' Create system variable BPF in the program's listing

Then clear BPF to re-initialise the LCD before a Print, Cls or Cursor command is used:
    Clear BPF                         ' Force an initialisation of the LCD by the Cursor, Cls or Print commands
    Cls                               ' Clear the LCD to initialise and refresh it

Within the Print command's library assembler subroutine (Press button F2 in the IDE), you can also see it at work:
    btfsc BPF,1        <------------- Is BPF.1 set?
    bra __prt_1__      <------------- Yes. So Skip initialisation of the LCD 
    movlw 58           <------------- Otherwise... Initialise the LCD
    movwf PP0H,0
    movlw 152
    rcall __delay_us_wreg_
    movlw 51
    movwf PP3,0
    rcall __print_loop__
    movlw 19
    movwf PP0H,0
    movlw 136
    rcall __delay_us_wreg_
    rcall __print_loop__
    movlw 100
    rcall __delay_us_
    rcall __print_loop__
    movlw 100
    rcall __delay_us_
    movlw 34
    movwf PP3,0
    rcall __print_loop__
    movlw 40
    rcall __print_sendcommand
    movlw 12
    rcall __print_sendcommand
    movlw 6
    rcall __print_sendcommand
    bsf BPF,1                 <------------ Signal that the LCD has been initialised
    movf PP3H,W
    bra __prt_1__
__print_sendcommand
    bsf BPF,0
__prt_1__

The Cursor and Cls commands also use the Print subroutine, so it gets initialised with them as well, but it is better to perform a Cls after re-initialisation to give the LCD time to stabilise, because the Cls command also has a 30ms delay after it.

It is always better to clear all of the BPF variable, because bit-0 of it is used to signal a command or data being sent to the LCD as well, and if it is holding the wrong value at a specific time, a command may not be sent. See the "__print_sendcommand" label in the assembler listing above.

The LCD assembler routines have not changed since the 8-bit compiler was first created because they work, and I am not a one for "change for the sake of change". :-)

Dompie

Quote from: top204 on Feb 27, 2022, 09:16 AM....because they work, and I am not a one for "change for the sake of change". :-)
Les, I believe this is why you are not qualified to work at Microchip ;D  ;D  ;D

Johan

shantanu@india

Thanks Les... you are lucid and evocative as usual!!
You could have excelled as an University Professor you know... I'm not joking!!
Maybe we can meet someday...
Regards
Shantanu