#define WAIT {LCD_EN=1; Delay_us(100); LCD_EN =0; Delay_us(100);}
sbit LCD_RS at LATD6_bit;
sbit LCD_EN at LATD7_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISD6_bit;
sbit LCD_EN_Direction at TRISD7_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void LC_cmd(unsigned char);
void LC_out(unsigned char ,unsigned char , char *);
void LC_dat(unsigned char);
void LC_ini(void);
int displ(int, char *);
void main(){
int i=5,p=-19138 ;
char ldg[]="MIkrOC",j,txt[16],txt1[16];
TRISD=0X00;
PORTD=0X00;
TRISB=0X00;
PORTD=0X00;
LC_ini();
Displ(p,txt1);
LC_out(1,1,txt1);
LC_out(2,8,"miKRoc");
}
void LC_ini(void){
LC_cmd(0x33); // Reset LCD
LC_cmd(0x32);
LC_cmd(0X28); // 4 bit mode
LC_cmd(0X0E); // display on sursor blinking
LC_cmd(0X01); // clear LCd
LC_cmd(0X80); // row1 initial position 6
}
void LC_cmd(unsigned char k){
PORTB= (k & 0xF0); // sending higher nibble
LCD_RS=0; // command
WAIT
PORTB= ((k & 0x0F)<<4); //sending lower nibble
LCD_RS=0; // command
WAIT
}
void LC_dat(unsigned char k){
PORTB= (k & 0xF0); // sending higher nibble
LCD_RS=1;
WAIT
PORTB= ((k & 0x0F)<<4); // sending lower nibble
LCD_RS=1;
WAIT
}
void LC_out(unsigned char row,unsigned char col, char *str )
{
switch(row) {
case 1: LC_cmd(0x80 + col-1); break;
case 2: LC_cmd(0xC0 + col-1); break;
default: LC_cmd(0x80 + col-1);break;
}
while(*str)
LC_dat(*str++);
}
int displ( int i,char *n)
{
char test_arr[16];
char j=0,l;
int sign=0,k=0,p=0,ttt=0;
if(i<0)
{
sign=i;
i=-i;
}
while(i>0)
{
ttt= i%10;
ttt=ttt+48;
n[j++] = (char) ttt;
i=i/10;
}
if(sign<0)
{
n[j++]= '-';
}
n[j]= '\0';
for(p=0,k=j-1;k>=0;p++,k--)
{
test_arr[p]= n[k];
}
test_arr[p]='\0';
for(k=0;test_arr[k]!='\0';k++)
{
test_arr[k]=test_arr[k];
n[k]= test_arr[k];
}
n[k] = '\0';
LC_out(2,1,test_arr);
return 0;
}