moein0114
Newbie level 6

hi , i am using the microblaze to calculate some thing and after that i want to show it on the lcd i have on my board . i ddidnt know exactly how to do it , so i searched and now i want to use this code to run the lcd for now :
i have problems ,
does any body know , what is reverse() doing here ?
i am using characteristic lcd 2*16 and i have considered the commands for my lcd kind .
i just have problem with reverse ().
what am i missing here ?
Code:
#include<stdio.h>
#include<xparameters.h>
#include<xgpio.h>
XGpio e,rs,rw,lcd_data;
char reverse(char data)
{
int i;
int temp1;
int temp2=0;
for(i=0;i<8;i++)
{
temp1 = (data>>i)&1;
temp2+= temp1 << (7-i);
}
return temp2;
}
void delay(int counter)
{
while(counter) counter--;
}
void gpio_init (void)
{
XGpio_Initialize(&e, XPAR_E_DEVICE_ID);
XGpio_Initialize(&rs, XPAR_RS_DEVICE_ID);
XGpio_Initialize(&rw, XPAR_RW_DEVICE_ID);
XGpio_Initialize(&lcd_data, XPAR_DATA_IN_DEVICE_ID);
/*Set the all GPIOs as output*/
XGpio_SetDataDirection(&e,1,0);
XGpio_SetDataDirection(&rs,1,0);
XGpio_SetDataDirection(&rw,1,0);
XGpio_SetDataDirection(&lcd_data,1,0);
}
void lcd_command(char i)
{
XGpio_DiscreteWrite(&lcd_data,1,reverse(i));
XGpio_DiscreteWrite(&rs, 1, 0);
XGpio_DiscreteWrite(&e, 1, 1);
XGpio_DiscreteWrite(&e, 1, 0);
delay(200000);
}
void lcd_write(char i)
{
XGpio_DiscreteWrite(&lcd_data, 1, reverse(i));
XGpio_DiscreteWrite(&rs, 1, 1);
XGpio_DiscreteWrite(&e, 1, 1);
XGpio_DiscreteWrite(&e, 1, 0);
delay(200000);
}
void cursor(int row, int column)
{
if(row==1)
lcd_command(0x80|(column-1));
if (row==2)
lcd_command(0x80|(0x40+(column-1)));
}
int main(void)
{
gpio_init();
XGpio_DiscreteWrite(&rw,1,0);
delay(20000);
lcd_command(0x28); // in dasture chek shode hastesho malume chi b chie , faghat bahse cursor mimuen chie ????
lcd_command(0x01);
lcd_command(0x06);
lcd_command(0x0F);
lcd_write('F');
lcd_write('P');
lcd_write('G');
lcd_write('A');
cursor(2,1);
lcd_write('C');
lcd_write('E');
lcd_write('N');
lcd_write('T');
lcd_write('E');
lcd_write('R');
return 0;
}
i have problems ,
does any body know , what is reverse() doing here ?
i am using characteristic lcd 2*16 and i have considered the commands for my lcd kind .
i just have problem with reverse ().
what am i missing here ?
Last edited by a moderator: