Code: Select all
// Lcd pinout settings
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;
// Pin direction
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;
float x,y,m,n,i=0; char txt[12];
char txt1[12];
int a=10;
void main()
{
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
TRISC=0;
TRISD=255;
portc.b0=0;
portc.b0=1;
Lcd_Out(1, 3, "Hello Ahmad !");
delay_ms(300);
portc.b0=0;
delay_ms(5000);
lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Temp=");
x=adc_read(0);
y=(x*500)/1024;
floattostr(y,txt);
lcd_out(1,6,txt);
lcd_chr_cp(223);
lcd_chr_cp('c');
if(y>=30)
{
Lcd_Out(2, 1, "I think its hot");
delay_ms(3000);
}
else
{
Lcd_Out(2, 1, "I think its cold");
delay_ms(3000);
}
if(portd.B0==1)
{
lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "no need to turn");
Lcd_Out(2, 1, "on the lights");
delay_ms(3000);
}
else
{
lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Its better to");
Lcd_Out(2, 1, "turn on the ligh");
delay_ms(3000);
}
lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "car will lock in");
for(a=10;a>=0;a--)
{
inttostr(a,txt1);
lcd_out(2,4,txt1);
delay_ms(500);
}
lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 4, "car locked");
}
this is how i connected the LCD to the PIC:
I wanted to add While(1) loop as well many other commands,,,,,
so I dont know what's am I doing? or there is a problem in my compiler's version...
Help plz!