16x2 LCD simulater by C language

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
//void setup
char line1[16];
char line2[16];
char *const pline1 = line1; // pointer to line1
char *const pline2 = line2; // pointer to line2
const char text[] = "This is simulater of LCD 16x2. It's just a concept to do my homework. The embeded system by arduino uno R3. Let have fun.";
const char *const ptext = text; // pointer to text
int phase = 0;
int max_phase=0;
int sizetext = sizeof(text);
if (sizeof(text)%16){// to find max phase
max_phase = (sizeof(text)/16) ;
}else{
max_phase = (sizeof(text)/16) - 1;
}
printf("size: %d\nmax phase: %d\n", sizeof(text),max_phase);
// to reset screen
char key = getch();
if(key=='x'){
system("cls");
}else{
return 0;
}
while(1){ // void loop()
printf("o=-=-=-=-=-=-=-=-o\n");
//line1
printf("|");
for(int i=0; i<16; i++){
printf("%c", text[i+(16*phase)]);
}
printf("|\n");
// line2
printf("|");
for(int i=0; i<16; i++){
printf("%c", text[i+(16*(phase+1))]);
}
printf("|\n");
printf("o=-=-=-=-=-=-=-=-o\n");
printf("phase : %d", phase);
char key = getch();
if (key=='w'){
if(phase>0)
phase--;
}else if(key=='s'){
if (phase<(max_phase-1) )
phase++;
}
system("cls");
}
}
 

     นี่เป็นโค้ดภาษา C จำลองการแสดงข้อความผ่านหน้าจอ LCD 16x2 โดยมีข้อความในตัวแปรชื่อ text ในการเริ่มต้นให้กด x ก่อน เราจะพบการจำลองการแสดงข้อความที่เลื่อนดูได้บน 16x2 LCD ออกมา   เรากดปุ่มเลื่อนดูข้อความได้ด้วยปุ่ม w และ s  นี่เป็นตัวอย่างแบบง่าย ใช้สำหรับทดลองแนวคิดที่จะใช้ 16x2 LCD กับ arduino uno r3

Emoticon Emoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng