C CODE:
/****************************************************************
NAME:MOHSIN KHAN
AIM:TO INTERFACE AN 16*2 LCD TO PIC18F4550 IN
A 4-BIT MODE.
****************************************************************/
#include<p18f452.h>
//LCD Control pins
#define rs PORTDbits.RD0
#define rw PORTDbits.RD1
#define en PORTDbits.RD2
//LCD Data pins
#define sdata PORTD
voidlcd_ini(void);
void lcd_ini1(void);
voiddis_cmd(unsigned char);
voiddis_data(unsigned char);
voidlcdcmd(unsigned char);
voidlcddata(unsigned char);
void delay(unsigned int);
voidprint_string(char *a);
void main(void)
{
char
data0[]=" MULTIAXIS ";
char
data1[]="BLDC MOTOR";
unsignedinti=0;
TRISD=0; // Configure Port D as
output port
lcd_ini(); // LCD initialization
print_string(data0);
lcd_ini1();
print_string(data1);
}
voidlcd_ini()
{
dis_cmd(0x02); // To initialize LCD in 4-bit mode.
dis_cmd(0x20); // To initialize LCD in 2 lines, 5x7
dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x80);
}
void lcd_ini1()
{
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0xC0);
}
voiddis_cmd(unsigned char cmd_value)
{
unsigned
char cmd_value1;
cmd_value1
= (cmd_value& 0xF0); // Mask
lower nibble because RD4-RD7 pins are being used
lcdcmd(cmd_value1); // Send to LCD
cmd_value1
= ((cmd_value<<4) & 0xF0); //
Shift 4-bit and mask
lcdcmd(cmd_value1); // Send to LCD
}
voiddis_data(unsigned char data_value)
{
unsigned
char data_value1;
data_value1=(data_value&0xF0);
lcddata(data_value1);
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
}
voidlcdcmd(unsigned char cmdout)
{
sdata=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
delay(2);
en=0;
}
voidlcddata(unsigned char dataout)
{
sdata=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
delay(2);
en=0;
}
voidprint_string(char *a)
{
inti;
for(i=0;(*(a+i))!='\0';i++)
{
dis_data(*(a+i));
delay(2);
}
}
void delay(unsigned int d)
{
unsignedinti,j;
for(i=0;i<d;i++)
for(j=0;j<300;j++);
}
1 Comment:
what to do when baudrate is high?? if my baudrate is 57600 then what to do?? transmission does not occur synchronously..please help..how to transmit data with baudrate of 57600..my mail id is shaikh_moina@yahoo.com
Post a Comment