Announcement

Collapse
No announcement yet.

Reinitialisng a LCD after power cycle using the FLAGS var

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reinitialisng a LCD after power cycle using the FLAGS var

    to satisfy my own curiosity I tried this simple code to see if the method actually works .
    I can say that it works just fine on all the lcds I have [both of them]
    after a power cycle the display is quite successfully reinitialised with a short low pulse on portb.7



    Code:
    '****************************************************************
    '*  Name    : LCD_TEST.BAS                                      *
    '*  Author  : RICHARD                                           *
    '           TO TEST THAT FLAGS=0 WILL REINIT LCD
    '*  Date    : 4/8/2017                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : pic18f26k22                                       *
    '*          :  2016 LCD                                         *
    '****************************************************************
    
    
    
    
    
    
    
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = OFF
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    
        DEFINE OSC 64
    
    
    
    'LCD defines begin here  
        DEFINE LCD_BITS 4  'defines the number of data interface lines (4 or 8)
        DEFINE LCD_DREG PORTB 'defines the port where data lines are connected to
        DEFINE LCD_DBIT 0  'defines the position of data lines for 4-bit interface (0 or 4)
        DEFINE LCD_RSREG PORTB 'defines the port where RS line is connected to
        DEFINE LCD_RSBIT 4  'defines the pin where RS line is connected to
        DEFINE LCD_EREG PORTB  'defines the port where E line is connected to
        DEFINE LCD_EBIT 5  'defines the pin where E line is connected
        DEFINE LCD_COMMANDUS 1500  'defines the delay after LCDOUT statement
        DEFINE LCD_DATAUS 50   'delay in micro seconds
    'END of LCD DEFINES
    
        DQ var porta.4
        temperature var word
        busyflag var bit
        counter   var word   
        OSCCON=$70
        OSCTUNE.6=1
        while ! osccon2.7 :WEND    ;wait for pll
        ANSELB=0
        ANSELC=0
        ANSELA=0                             
        trisb.7=1      ;portb.7 low sig indicates to prg that disp reinitialise req
        Pause 500       ' LCD initialize time
        lcdout $FE,1,"ready "  
        oWOUT DQ, 1, [$CC, $44] ' Start a temperature conversion
        lcdout $FE,1   'clear display
        lcdout $fe,$c0,"Heatsink Temp:"
        counter=0
        while 1        ;loop forever
            if !portb.7 then    ;low here indicates disp needs to be reinitialised
                flags=0
                while !portb.7:wend  ;wait for sw to be released
                pause 500     ' LCD initialize time
                lcdout $fe,1,$fe,$c0,"Heatsink Temp:"     ;clear and restore display
            endif
            counter=counter+1
            if  counter//100 then    ;evey 100th loop
                lcdout $fe,$80,dec2 counter/1000    ;seconds approx
                gosub rt
            endif
            if  busyflag then
                lcdout $fe,$ce,DEC (temperature/100),"  C"
            endif
            pauseus 1000         ;min time for ds18b20 to finish conversion 750mS so we get a reading about once evey 800 loops
        wend                   
    
    
    rt:
        ' ======== RETRIEVE AND PROCESS SENSOR TEMPERATURE IF IT'S READY ===============
        OWIn DQ, 4, [busyflag]    ' Check for still busy converting
        If ! busyflag then  return  ;go away i'm busy
        OWOUT DQ, 1, [$CC, $BE]  ' Read the temperature
        OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
        temperature = temperature */ 1600
        OWOUT DQ, 1, [$CC, $44] ' Start a temperature conversion for next pass
    return
    
    
    
    
    end
Working...
X