Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Libray for character LCD modules (Busy flag/random pins)
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Wed Dec 08, 2010 9:23 pm    Post subject: Reply with quote

Hi,

Your program must keep track of the cursor position.

As I said, in my library are only low-level routines
which are called by the Bascom compiler.

Best regards,

Luciano
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Fri Sep 09, 2011 3:10 pm    Post subject: Reply with quote

Luciano,

Thanks for putting in the time out so that if there is a hardware error with the LCD the program will continue and not lock up.

Once very small addition I would consider is setting a failed flag if the time out is reached. This will (if desired) give the programmer the option of knowing that there is a hardware issue and maybe taking some other action. I consider this a very low priority and would not add it unless there are other changes being made.

-Glen

_________________
http://bahbots.com
Back to top
View user's profile AIM Address
Ross_ValuSoft

Bascom Member



Joined: 20 Nov 2005
Posts: 272
Location: Melbourne, Australia

australia.gif
PostPosted: Sun Sep 11, 2011 6:22 am    Post subject: Reply with quote

Adding my thanks also Luciano.

Cheers,

Ross McKenzie
Melbourne Australia
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Mon May 07, 2012 3:10 pm    Post subject: Reply with quote

Hi Luciano,

Are you willing to enhance the LUC_Lcd4busy_timeout library so that the internal ERR flag is set when a timeout occurs.
Just like for example the HexVal and I2Csend statements does.


Best regards, Frank
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Wed May 09, 2012 6:23 pm    Post subject: Reply with quote

In the "Mixing ASM and BASIC" topic in the help file is described how to set the ERR flag.
ASM is not my favorite thing, but i think it can be done in a few lines of ASM.
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun May 13, 2012 2:28 pm    Post subject: Reply with quote

Hi Frank,

Not really useful because the LCD can also crash while its busy flag is low.
You can also have an LCD where the communication works OK but with
no output on the LCD because the display driver is broken.

* * *

(If you still want to implement it).

Recent AVR chips have General Purpose I/O Registers.

(ATmega48/88/168datasheet).

The ATmega48/88/168 contains three General Purpose I/O Registers.
These registers can be used for storing any information, and they
are particularly useful for storing global variables and Status Flags.
General Purpose I/O Registers within the address range 0x00 - 0x1F are
directly bit-accessible using the SBI, CBI, SBIS, and SBIC instructions.


* * *

With these three registers (GPIOR0, GPIOR1 and GPIOR2) you have space for
up to 24 flags.

Below is what you have to do to set and clear one of these flags in my LIB.
(First we set our flag GPIOR0,0 and then we clear it if no timeout occurred).

In your Bascom program, in order to detect the error you will have to
check if the bit is set in the register GPIOR0.
(If GPIOR0.0 = 1 Then...).

You can do the same with the Bascom ERR flag (R6 bit 2) but then you are
not sure if the error was raised by the LCD routine or by a function you have
called as parameter in the Bascom LCD command. (In case this function
also uses ERR). Same problem if the Bascom ERR flag is set by the code in
an interrupt service routine which has interrupted the LCD command.

Best regards,

Luciano

(File LUC_lcd4busy_timeout.lib).
Code:
....
....
....
....

_LCD_Busy:

*   sbi gpior0,0                          ; !!!!!!! Set your LCD error flag !!!!!!!!

*   cbi _LcdE_PORTx, _LcdE_PinNumber      ; Clear the pin E
*   cbi _LcdRW_PORTx, _LcdRW_PinNumber    ; Clear the pin RW
*   cbi _LcdRS_PORTx, _LcdRS_PinNumber    ; Clear the pin RS
*   sbi _LcdE_DDRx, _LcdE_PinNumber       ; Set E as output
*   sbi _LcdRW_DDRx, _LcdRW_PinNumber     ; Set RW pin as output
*   sbi _LcdRS_DDRx, _LcdRS_PinNumber     ; Set RS pin as output
    rcall _Clear_Nibble                   ; Clear DB4,DB5,DB6 and DB7
*   cbi _LcdDB4_DDRx, _LcdDB4_PinNumber   ; Set DB4 as input
*   cbi _LcdDB5_DDRx, _LcdDB5_PinNumber   ; Set DB5 as input
*   cbi _LcdDB6_DDRx, _LcdDB6_PinNumber   ; Set DB6 as input
*   cbi _LcdDB7_DDRx, _LcdDB7_PinNumber   ; Set DB7 as input

*   sbi _LcdRW_PORTx, _LcdRW_PinNumber    ; Setup to read busy flag
*   sbi _LcdE_PORTx, _LcdE_PinNumber      ; Set E pin
    @genus(2)                             ; Wait for 2uS
*   in R25, _LcdDB7_PINx                  ; Read busy flag from LCD into R25
*   cbi _LcdE_PORTx, _LcdE_PinNumber      ; Clear E pin
    @genus(2)                             ; Wait for 2uS
    rcall _Toggle_E_line                  ; Toggle E line to get rid of lower nibble

    dec R16                               ; Decrement timeout value in R16
    breq _bf_timeout                      ; Branch when timeout expires. (R16=0)

*   sbrc R25, _LcdDB7_PinNumber           ; Check busy flag stored in R25, high = busy
    rjmp _LCD_Busy                        ; Busy flag was high so we check it again

*   cbi gpior0,0                          ;  !!!!!!! Clear your LCD error flag !!!!!!!!

_bf_timeout:                                  ; Jump here when a timeout occurs
   
*   cbi _LcdRW_PORTx, _LcdRW_PinNumber    ; Back to write mode
....
....
....

 
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Mon May 14, 2012 9:39 pm    Post subject: Reply with quote

Hi Luciano,

Thank you very much for your explanation.
It takes only two lines of ASM.

I really like to know when a LCD fails.
The hardware monitors the carbon monoxide value in fluegasses.
Nobody looks at the display until a level is measured that is to high.
In that case it would be nice if the display works (-:
When the display craches under normal conditions it can be replaced.

Frank.
Back to top
View user's profile
TSEYFARTH

Bascom Member



Joined: 01 Jul 2006
Posts: 1042

usa.gif
PostPosted: Mon Aug 17, 2015 3:16 am    Post subject: Reply with quote

Hi Luciano,

I am trying to use your LUC_lcd4busy_timeout.lib but cannot get it to compile without changing LCDMODE to from PIN to BUS. The compiler errors are:

Error40 Line 2346 Variable can not be used with RESET [PORTG], in file
Error41 Line 2346 Variable can not be used with SET [PORTG], in file

I am using an ATMEG32a


Code:

     $regfile = "m32def.dat"            'register file for MEGA32A-AU
     $crystal = 16000000                '16MHz crystal
     $baud = 9600
     $hwstack = 175                     '200                                         '100                                         ' default use 32 for the hardware stack
     $swstack = 180                     '200                                         '100                                         ' default use 10 for the SW stack
     $framesize = 112                   '100                                       '40                                        ' default use 40 for the frame space
     $lib "LUC_lcd4busy_timeout.lib"
 



Code:

'*** These 4 pins are not used by Lucianos code ****
   Config Portc.0 = INPUT 'Output
   Config Portc.1 = INPUT 'Output
   Config Portc.2 = INPUT 'Output
   Config Portc.3 = INPUT 'Output


   'PCB2.39 012014 for Leamington
   ' LCD    AVR
   ' pin    pin
   ' ============
   '//--- REQUIRED PINS ---//
   'DB4     'PC.4
   'DB5     'PC.5
   'DB6     'PC.6
   'DB7     'PC.7
   'ENABLE  'PB.0
   'R/W     'PB.1 'Note that RW must be connected to a pin!
   'RS      'PB.2

   '//--- NOT USED LCD PINS ---//
   'DB0     'PC.0
   'DB1     'PC.1
   'DB2     'PC.2
   'DB3     'PC.3

   Const _LcdDB4_PORTx = PortC   'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdDB4_DDRx = DDRC     'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdDB4_PinNumber = 4   'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdDB5_PORTx = PortC   'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdDB5_DDRx = DDRC     'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdDB5_PinNumber = 5   'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdDB6_PORTx = Portc   'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdDB6_DDRx = DDRc     'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdDB6_PinNumber = 6   'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdDB7_PORTx = Portc   'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdDB7_DDRx = DDRc     'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdDB7_PINx = Pinc     'Valid values: PINA, PINB, PINC, PIND, PINE.
   Const _LcdDB7_PinNumber = 7   'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdE_PORTx = PortB     'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdE_DDRx = DDRB       'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdE_PinNumber = 0     'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdRW_PORTx = PortB    'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdRW_DDRx = DDRB      'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdRW_PinNumber = 1    'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   Const _LcdRS_PORTx = PortB    'Valid values: PORTA, PORTB, PORTC, PORTD, PORTE.
   Const _LcdRS_DDRx = DDRB      'Valid values: DDRA, DDRB, DDRC, DDRD, DDRE.
   Const _LcdRS_PinNumber = 2    'Valid values: 0, 1, 2, 3, 4, 5, 6, 7.

   'Define the used LCD
   'Start off as 20x2 but set later depending on the jumper setting
   '   If Lcd2or4 = 1 Then
         Config Lcd = 20 * 2
    '   Else
   '      Config Lcd = 20 * 4
   '   End If
      Initlcd
      Cursor Off Noblink
 



If I set it to BUS, then it kinds of works. It starts out as a 20x2, but then changes to a 16x2 - there is no code from me to do this. I have tested the same board with the same display (A Newhaven OLED Character display) and it does work - aside from loosing a character on left, by having what appears to be column 1 moved to the left over time. Newhaven told me it was a timing error in code, which is why I am trying your lib. Previously I had used this code:



Code:

   Config Portc.1 = Output
   Config Portc.2 = Output
   Config Portc.3 = Output

   Config Portb.0 = Output                                  'LCD Enable
   Config Portb.1 = Output                                  'LCD R/W
   Config Portb.2 = Output                                  'LCD Reg Sel
   Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portb.0 , Rs = Portb.2
    'Start off as 20x2 but set later depending on the jumper setting
   Lcd2or4 = Pinb.6
   If Lcd2or4 = 1 Then
      Config Lcd = 20 * 2 , Chipset = Ks077                 '4                                    'configure lcd screen
   Else
      Config Lcd = 20 * 4 , Chipset = Ks077                 '4                                    'configure lcd screen
   End If

   Initlcd                                                  'Initialize the LCD
   Portb.1 = 0                                              'Set the W/R Pin to logic zero(0)
   Cursor Off Noblink
 



Curiously, if I modify the above to include the RW pin, I get similar errors.

Further, Newhaven says their display uses a ST7066U chipset.
I have found datasheets that suggest the following are compatible, including the one you wrote about in your lib

HD44780
KS0063
KS0065B

Any ideas and help would be really appreciated!
Thank you,
Tim
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum