djc
Advanced Member level 1
Hello,
I wrote a code for 2 wire LCD interfacing using PIC16F72 and mikroC. Serial IC is 74HC595 . Both clock pins are shorted. LCD is operated in 4 bit mode. D4,D5,D6, D7 bit of LCD is connected to Q4,Q5,Q6 and Q7 bit of serial IC. Enable pin of LCD is connected to Q2 pin through data pin using resistor and diode combination. RS pin connected to Q3 pin of serial IC. Code is as follows,
However there is no O/P on LCD. What is wrong with the code? Plz can any one guide me??
I wrote a code for 2 wire LCD interfacing using PIC16F72 and mikroC. Serial IC is 74HC595 . Both clock pins are shorted. LCD is operated in 4 bit mode. D4,D5,D6, D7 bit of LCD is connected to Q4,Q5,Q6 and Q7 bit of serial IC. Enable pin of LCD is connected to Q2 pin through data pin using resistor and diode combination. RS pin connected to Q3 pin of serial IC. Code is as follows,
Code:
#define Data_DS PORTB.B1
#define Data_Clk PORTB.B2
char i=0,m=0,j=0;
unsigned char binaryNumber[10],val=0,RS = 0,En = 0,En_On = 0x04, En_Off = 0x00,RS_On =0x08,RS_Off = 0x00;//,En_On[8]={0,0,1,0,0,0,0,0},En_Off={0,0,0,0,0,0,0,0};
unsigned int Temp;
void Data_Out(unsigned int Data)
{
i=1;
for(m=0;m<8;m++){
binaryNumber[i++]= Data % 2;
Data = Data / 2;
//Data_DS = binaryNumber[i];
}
for(j = i-1;j> 0;j--){
Data_DS = binaryNumber[j];
Data_Clk = 1;
Delay_us(1);
Data_Clk = 0;
Delay_us(1);
}
Data_Clk = 1;
Delay_us(1);
Data_Clk = 0;
//Delay_ms(1000);
}
void Port_setting(){
TRISB = 0x00; //Set port B as output
PORTB = 0;
}
void ADCnComparator(){
ADON_bit = 0;
}
void convert_cmd_upper_nibble(unsigned char value){
Temp = 0b00000100; //D3=RS,D2=Enable
if(Value & 0x80) // D7
{
Temp = Temp | 0x80;
}
if(Value & 0x40) // D6
{
Temp = Temp | 0x40;
}
if(Value & 0x20) // D5
{
Temp = Temp | 0x20;
}
if(Value & 0x10) // D4
{
Temp = Temp | 0x10;
}
Temp = Temp & 0xF4; //Preserved the data of RS and Enable pin=1
Data_Out(Temp);
Temp = Temp & 0xF8; //Enable pin=0
Delay_ms(1);
Data_out(Temp);
}
void convert_cmd_lower_nibble(unsigned char Value){
Temp = 0b00000100; //D3=RS,D2=Enable
Value = val<<4;
if(Value & 0x80) // D7
{
Temp = Temp | 0x80;
}
if(Value & 0x40) // D6
{
Temp = Temp | 0x40;
}
if(Value & 0x20) // D5
{
Temp = Temp | 0x20;
}
if(Value & 0x10) // D4
{
Temp = Temp | 0x10;
}
Temp = Temp & 0xF4; //Preserved the data of RS and Enable pin=1
Data_Out(Temp);
Temp = Temp & 0xF8; //Enable pin=0
Delay_ms(1);
Data_out(Temp);
}
void convert_data_upper_nibble(unsigned char Value){
Temp = 0b00001100; //D3=RS,D2=Enable
if(Value & 0x80) // D7
{
Temp = Temp | 0x80;
}
if(Value & 0x40) // D6
{
Temp = Temp | 0x40;
}
if(Value & 0x20) // D5
{
Temp = Temp | 0x20;
}
if(Value & 0x10) // D4
{
Temp = Temp | 0x10;
}
Temp = Temp & 0xFC; //Preserved the data of RS and Enable pin=1
Data_Out(Temp);
Temp = Temp & 0xF8; //Enable pin=0
Delay_ms(1);
Data_out(Temp);
}
void convert_data_lower_nibble(unsigned char Value){
Temp = 0b00001100; //D3=RS,D2=Enable
Value = val<<4;
if(Value & 0x80) // D7
{
Temp = Temp | 0x80;
}
if(Value & 0x40) // D6
{
Temp = Temp | 0x40;
}
if(Value & 0x20) // D5
{
Temp = Temp | 0x20;
}
if(Value & 0x10) // D4
{
Temp = Temp | 0x10;
}
Temp = Temp & 0xFC; //Preserved the data of RS and Enable pin=1
Data_Out(Temp);
Temp = Temp & 0xF8; //Enable pin=0
Delay_ms(1);
Data_out(Temp);
}
void LCD_Cmd(unsigned char lcd_data){
//RS = 0; //For LCD Command
val = (lcd_data & 0xF0);
val = val>>4; //Extra
convert_cmd_upper_nibble(val);
delay_us(10);
//val = ((data<<4) & 0xF0);
val = (lcd_data & 0x0F);
convert_cmd_lower_nibble(val);
delay_us(10);
}
void LCD_Dat(char lcd_data_1){
//RS = 1; //For LCD Data
val = (lcd_data_1 & 0xF0);
val = val>>4;
convert_data_upper_nibble(val);
delay_us(100);
//val_1 = ((data_1<<4) & 0xF0);
val = (lcd_data_1 & 0x0F);
convert_data_lower_nibble(val);
delay_us(100);
}
void LCD_Init(){
LCD_Cmd(0x38); //Special Sequence:Write Function Set.
delay_ms(5);
LCD_Cmd(0x01); //clear the screen
delay_ms(5);
LCD_Cmd(0x0A); //Display Off cursor On
delay_ms(5);
LCD_Cmd(0x28); //4bit,2ine,5*7matrix
delay_ms(5);
LCD_Cmd(0x02); //Return Home
delay_ms(5);
LCD_Cmd(0x80); //Cursor to top left character position
delay_ms(5);
LCD_Cmd(0x06); //Increment sursor to right
delay_ms(5);
}
void Print_LCD(char *cptr){
while(*cptr != '\0'){
LCD_Dat(*cptr);
delay_us(100);
cptr++;
}
}
void main() {
Port_Setting();
ADCnComparator();
LCD_Init();
while(1){
Print_LCD("W");
}
}
However there is no O/P on LCD. What is wrong with the code? Plz can any one guide me??