Driving a Serial LCD
Posted: Sun Aug 14, 2011 5:57 pm
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);
}
}
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);
}
}