Created
February 26, 2020 12:27
-
-
Save kuninet/5e6a95395a3ccab16ddc5413c9e44b45 to your computer and use it in GitHub Desktop.
LCD SC1602 DEMO for Arduino UNO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RS_PIN 2 | |
#define DATA 1 | |
#define CTL 0 | |
#define RW_PIN 8 | |
#define WR 0 | |
#define RD 1 | |
#define E_PIN 3 | |
#define ON 1 | |
#define OFF 0 | |
#define DB4_PIN 4 | |
#define DB5_PIN 5 | |
#define DB6_PIN 6 | |
#define DB7_PIN 7 | |
void pin_ctl(int pin,int n){ | |
digitalWrite(pin,n); | |
} | |
void p_out(char c){ | |
pin_ctl(E_PIN,OFF); | |
PORTD = (c & 0xf0) | (PORTD & 0x0f); | |
delay(1); | |
pin_ctl(E_PIN,ON); | |
delay(1); | |
pin_ctl(E_PIN,OFF); | |
PORTD = ((c << 4) & 0xf0) | (PORTD & 0x0f); | |
delay(1); | |
pin_ctl(E_PIN,ON); | |
delay(1); | |
pin_ctl(E_PIN,OFF); | |
} | |
void lcd_ctl_out(char c){ | |
pin_ctl(RS_PIN,CTL); | |
pin_ctl(E_PIN,OFF); | |
PORTD = ((c << 4) & 0xf0) | (PORTD & 0x0f); | |
pin_ctl(E_PIN,ON); | |
delay(1); | |
pin_ctl(E_PIN,OFF); | |
} | |
void lcd_init(){ | |
lcd_ctl_out(0x3); | |
delay(4); | |
lcd_ctl_out(0x3); | |
delay(1); | |
lcd_ctl_out(0x3); | |
delay(1); | |
lcd_ctl_out(0x2); | |
delay(1); | |
lcd_ctl_out(0x2); | |
lcd_ctl_out(0x8); | |
delay(1); | |
lcd_ctl_out(0x0); | |
lcd_ctl_out(0x8); | |
delay(1); | |
lcd_ctl_out(0x0); | |
lcd_ctl_out(0x1); | |
delay(1); | |
lcd_ctl_out(0x0); | |
lcd_ctl_out(0x6); | |
delay(1); | |
lcd_ctl_out(0x0); | |
lcd_ctl_out(0xC); | |
delay(5); | |
} | |
void lcd_char_Out(char c){ | |
pin_ctl(RS_PIN,DATA); | |
p_out(c); | |
} | |
void lcd_print(char *p){ | |
int i; | |
for(i=0;i<16;i++){ | |
lcd_char_Out(*p); | |
p++; | |
} | |
} | |
void lcd_loc(unsigned char x,unsigned char y){ | |
unsigned char outc; | |
outc = 0x80; | |
if (y > 1){ | |
outc += 0x40; | |
} | |
outc += x-1; | |
pin_ctl(RS_PIN,CTL); | |
p_out(outc); | |
} | |
void setup() { | |
pinMode(13,OUTPUT); | |
pinMode(RS_PIN,OUTPUT); | |
pinMode(RW_PIN,OUTPUT); | |
pinMode(E_PIN,OUTPUT); | |
pinMode(DB4_PIN,OUTPUT); | |
pinMode(DB5_PIN,OUTPUT); | |
pinMode(DB6_PIN,OUTPUT); | |
pinMode(DB7_PIN,OUTPUT); | |
pin_ctl(RS_PIN,CTL); | |
pin_ctl(RW_PIN,WR); | |
pin_ctl(E_PIN,OFF); | |
lcd_init(); | |
lcd_print("Hello!LCD SC1602"); | |
lcd_loc(1,2); | |
lcd_print("ArduinoUNO DADA!"); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment