Quoting "John J. McDonough" <[EMAIL PROTECTED]>:

>
> I should have mentioned ... there is no harm in waiting too long for the
> LCD.  In fact, when you are first trying to get things done, I would
> encourage you to wait VERY long.  As I mentioned, the strobe only needs 450
> ns, so that part can simply be a couple of nops.  But if you don't wait long
> enough after sending a character, the processor on the LCD will get confused
> and will tend to start behaving randomly.  Indeed, when you are debugging,
> it is sometimes helpful to wait -seconds- so you can see what is going on.

I have tested this particular LCD with much faster timing, it does what the
function tells it to, however the main problem now is that the value i want to
pass as an argument to the function call becomes 0. Everything works if I use
global variables, but that wont be possible because of later things I want to
add.

If I call LCDputc(0x41), to the function, then c should be 0x41, but it is in
fact 0x00 instead. If I print c+0x30, it prints "0" on the display whatever I
pass as an argument to the function, however, if I inside the LCDputc function
assign a value to c, for example 0x41, it prints "A".

One interesting thing I noticed just no, if c is first assigned the value... for
example 0x03, then I reflash the instrument with c=0x02, it still is 0x03, as if
the previous value didn't get reset in the chips memory. Powercycling the chip
will correct this.

>
> The wait before, and after, the initialization is quite long, and things
> like clearing the display take longer than writing a character.  The
> physical LCD itself is quite a bit slower than the processor, so in most
> applications, you can have excessive delays waiting for the processor
> without actually impacting the application.
>
> In addition, not all LCDs are up to spec. Sometimes cheap LCDs are available
> because they didn't quite meet the specifications, and sometimes it is the
> speed.  I would suggest you read the datasheet for the controller, and
> initially wait at least double the required times until you get things
> running.  Once everything is working, then back the times closer to the
> spec.  Although some LCDs might not quite make the spec, my experience is
> that they rarely miss by much, so just a tiny bit more than the minimum is
> USUALLY enough.  But until you get your code sorted, better to just send the
> commands to the LCD at a leisurely pace.

The final program will probably read the busy flag and then wait perhaps 10ms,
but it's a long way there, in the meantime I just use slow timings.

Actually, with the 16F690 at 8MHz, I needed no NOP:s at all between writes, and
the LCD would still perform 100%, but I put some delays there anyway to be
sure.

For now, the problem is passing arguments along with the function calls. Where
does it store an argument when passing it to a function call?

Does this look right:
(I suck at assembly code, but here is what I think is the actual function call):


; ; Starting pCode block
S_hello__main   code
_main:
;       .line   39; hello.c     init();
        CALL    _init
_00124_DS_:
;       .line   41; hello.c     blinkarg(5);
        MOVLW   0x05
        MOVWF   POSTDEC1
        CALL    _blinkarg
        INCF    FSR1L, F
;       .line   42; hello.c     delay100ktcy(1);
        MOVLW   0x01
        CALL    _delay100ktcy
        GOTO    _00124_DS_
        RETURN




...and then the function seems to be here...


; ; Starting pCode block
S_hello__blinkarg       code
_blinkarg:
;       .line   23; hello.c     void blinkarg(unsigned char blinks)
        MOVFF   FSR2L, POSTDEC1
        MOVFF   FSR1L, FSR2L
        MOVFF   r0x00, POSTDEC1
        MOVFF   r0x01, POSTDEC1
        MOVFF   r0x02, POSTDEC1
        MOVFF   r0x03, POSTDEC1
        MOVFF   r0x04, POSTDEC1
        MOVLW   0x02
        MOVFF   PLUSW2, r0x00
;       .line   28; hello.c     for(i=0;i<blinks;i++) {
        CLRF    r0x01
        CLRF    r0x02
_00109_DS_:
        MOVFF   r0x00, r0x03
        CLRF    r0x04
        MOVF    r0x02, W
        ADDLW   0x80
        MOVWF   PRODL
... and so on.

Can anyone find a specific reason to why the argument is cleared before the
LCDputc() function uses it?


Here is the entire program again in C:
#define __pic18f2550
#include <pic18fregs.h>
#include <sdcc-lib.h>
#include <delay.h>
#define OUT LATCbits.LATC7

typedef unsigned int config;
code char at __CONFIG3H _config4 = 0x00; //0b00000000

void init(void)
{
        OSCCON=0xf7;    //0b11110111
        TRISA=0xff;     //0b00000000
        TRISB=0xff;     //0b11111111
        TRISC=0x00;     //0b11111110
}


void blinkarg(unsigned char blinks)
{
  int i;
  //blinks=5;
  //blinks=+2;
  for(i=0;i<blinks;i++) {
    OUT=1;
    delay1ktcy(1);
    OUT=0;
    delay1ktcy(1);
  }
  blinks=0;
}

void main(void)
{
  init();
  while(1) {
    blinkarg(5);
    delay100ktcy(1);
  }
}

Robert Bergfors

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to