-
1
- #1
DTSFA
Electrical
- May 31, 2012
- 41
I am using a 16f877 PIC to drive a 16x2 LCD,
if I run the code to where the lift checks if between floors , all is good, if I run code to end , at the start, I get what looks like a 'y' in the display,
and rest of code seems to output weird characters, behave illogically
is this a timing issue ?
or something else, all advice welcome,
( I am rusty on c code at mo, so please go easy)
code is written, compiled using MikroC Pro
thanks
if I run the code to where the lift checks if between floors , all is good, if I run code to end , at the start, I get what looks like a 'y' in the display,
and rest of code seems to output weird characters, behave illogically
C:
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
int i=0;
void main() {
ADCON1 = 0x0F;
TRISB = 0;
PORTB = 0xFF;
TRISC = 1;
PORTC = 0x00;
Lcd_Init();
while(1){
for (i=0;i<3;i++){
if (PORTC.F0==0){
Lcd_Out(1,1,"Door fault");
Lcd_Out(2,1,"Check interlocks");
}
else {
Lcd_Out(1,1,"Door closed");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
for (i=0;i<3;i++){
if (PORTC.F1==0){
Lcd_Out(1,1,"No up safety");
Lcd_Out(2,1,"Platf./Carriage?");
}
else {
Lcd_Out(1,1,"Safety Edge Ok");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
for (i=0;i<3;i++){
if (PORTC.F2==1){
Lcd_Out(1,1,"Lift at upper");
Lcd_Out(2,1,"Level");
}
else {
Lcd_Out(1,1,"Checking..");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
for (i=0;i<3;i++){
if (PORTC.F3==1){
Lcd_Out(1,1,"Lift at lower");
Lcd_Out(2,1,"Level");
}
else {
Lcd_Out(1,1,"Between floors");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
for (i=0;i<3;i++){
if (PORTC.F4==1){
Lcd_Out(1,1,"Lift going up");
}
else {
Lcd_Out(1,1,"Checking..");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
for (i=0;i<3;i++){
if (PORTC.F5==1){
Lcd_Out(1,1,"Lift going dn");
}
else {
Lcd_Out(1,1,"Checking..");
}
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
is this a timing issue ?
or something else, all advice welcome,
( I am rusty on c code at mo, so please go easy)
code is written, compiled using MikroC Pro
thanks