Page 1 of 1

Driving a Serial LCD

Posted: Sun Aug 14, 2011 5:57 pm
by Sefi
I am trying to drive a serial LCD from CrystalFontz using an 18F452 microcontroller. I can do this very easily using Proton and basic but have had huge problems with Flowcode V4.

having serached the internet for C solutions, I have found code writtem by Mark Crosbie that apparently can do this. I have tried to incorporate Mark's code into the supplementary code section and when trying to compile the preprocessor seems does not stop printing "progress dots" and in fact doesnt come back and enters an infinite loop.

The code I have found is a mixture of C with asm. I have tried to port this code from MPLAB to the FC V4 environment. Please see the code pasted belowwhich I have put in the supplemtary code section. Would one of you good people please tell me where I am going wrong.

Many thanks
Sefi

void delay_us(char d) {
char count;
char count2;

count = d;

asm {
_dmsouter:
movlw D,'20'
movwf _count2_delay_us

_dmsinner:
NOP
NOP
decfsz _count2_delay_us, f
goto $-3
decfsz _count_delay_us,f
goto $-7
return
}
}


void delay_ms(char d) {
char loop2;
char loop1;

loop1 = d;
asm {
_DELAY_1:
MOVLW 110 ; close to 1.0 msec delay when set to .110
MOVWF _loop2_delay_ms
_DELAY_2:
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ _loop2_delay_ms, F ; decrement and leave result in LOOP2
; skip next statement if zero
GOTO $-7 ; goto _DELAY_2
DECFSZ _loop1_delay_ms, F
GOTO $-0xb ; goto _DELAY_1
return
}
}

void delay_s(char d) {

char i;
for(i=0; i < 10; i++) {
delay_ms(100);
}
}

Re: Driving a Serial LCD

Posted: Mon Aug 22, 2011 2:26 pm
by Benj
Hello Sefi,

Sorry for the delay, I've recently been away on holiday. We should be able to help you get this display working correctly.

Do you have your proton basic code? If so then this may be helpful in creating a working Flowcode project.

Otherwise if you wish to continue using the C functions then you will have to do assembler lines of code like this.

asm {"_dmsouter:"};
asm {"movlw D,20"};
asm {"movwf _count2_delay_us"};

etc..

The entire code you have posted seems to only perform delay instructions (s, ms, us) which can all be handled using the flowchart delay icon. This will give you much more accurate timings as long as your clock speed and configurations are correct for your hardware.

To reference the Flowcode delays Via C code you can use the following syntax where x is a number between 1 and 255. For longer delays simply call the routine multiple times.

delay_us(x);
delay_ms(x);
delay_s(x);

If you need to test this then you can download a 1 second flasher program and see if this runs as expected on the hardware. If it does not then you know there is a problem either in the clock speed or configuration settings.

A one second flasher program consists of a endless loop where you output 1 to a pin or a port, delay for 1 second, output a 0 to the same output and finally delay for a second again.