#include <string.h>
volatile char *DDR_DATA = (volatile char *)0x30;
volatile char *DDR_COMM = (volatile char *)0x107;
volatile char *PORT_DATA = (volatile char *)0x31;
volatile char *PORT_COMM = (volatile char *)0x108;
#define EN 0
#define RS 1
#define EN_HIGH *PORT_COMM |= (1<<EN);
#define EN_LOW *PORT_COMM &= ~(1<<EN);
#define RS_HIGH *PORT_COMM |= (1<<RS);
#define RS_LOW *PORT_COMM &= ~(1<<RS);
void delay1(int i){
delayMicroseconds(2);
}
void init_port(void){
*DDR_DATA = 0xFF; //8-pins
*DDR_COMM = 0x03; //2-pins
}
void outcommand(char comm){
//*PORT_DATA = data;
*PORT_DATA = (*PORT_DATA &0xF0) |((comm >> 4) & 0x0F);
RS_LOW;
EN_pulse();
delayMicroseconds(1);
*PORT_DATA = (*PORT_DATA & 0xF0 ) |(comm & 0x0F);
RS_LOW;
EN_pulse();
delayMicroseconds(2);
//delayMicroseconds(100);
}
void outdata(char data){
//*PORT_DATA = data;
*PORT_DATA = (*PORT_DATA &0xF0) |((data >> 4) & 0x0F);
RS_HIGH;
EN_pulse();
delayMicroseconds(2);
*PORT_DATA = (*PORT_DATA & 0xF0 ) |(data & 0x0F);
RS_HIGH;
EN_pulse();
delayMicroseconds(2);
}
void EN_pulse(void){
EN_HIGH;
delayMicroseconds(2);
EN_LOW;
delayMicroseconds(2);
//delayMicroseconds(100); // Additional delay for 4-bit mode
}
void lcd_control_write(){
RS_LOW;
EN_HIGH;
delay1(1);
EN_LOW;
delay1(1);
}
void init_lcd(){
delay(20);
outcommand(0x02);//30
outcommand(0x28); //8bit -2 line mode
outcommand(0x28); //Display on-off control
outcommand(0x0C); //Display on-off control
outcommand(0x06); //Entry Mode Set
outcommand(0x01); //Clear Display
}
// void write_command(char command){
// lcd_control_write();
// outdata(command); //Entry Mode Set
// lcd_control_write();
// }
void write_string(char *ptr){
while(*ptr != '\0')
{
write_data(*ptr);
ptr++;
}
}
void write_data(char wr_data){
outdata(wr_data);
}
void setup() {
delay(15);
char *arr = "USE LSB PINS";
// put your setup code here, to run once:
init_port();
init_lcd();
outcommand(0x80);
write_string(arr);
}
void loop() {
// put your main code here, to run repeatedly:
//right_shift();
// left_shift();
//right_Shift_Display();
// delay(1000);
}