작업 환경
-메인 OS : Windows 8.1K(Intel Core i5-4590)
-작업 OS : Ubuntu 14.04.5 LTS 64bit(VirtualBox)
-장 비 명 : Hybus-Smart4412
exam.c
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <asm/ioctls.h>
#define tact "/dev/tactsw"
#define dot "/dev/dot"
void menu();
void Inside();
void Outside();
void UptoDown();
void DowntoUp();
void Center();
int main()
{
int tact_d, i = 0;
unsigned char c;
tact_d = open(tact, O_RDWR);
if(tact_d<0)
{
printf("open failed\n");
}
while(1)
{
menu();
while(1)
{
read(tact_d, &c, sizeof(c));
usleep(100000);
if(c) break;
}
switch(c)
{
case 1:Inside();break;
case 2:Outside();break;
case 3:UptoDown();break;
case 4:DowntoUp();break;
case 12:printf("Shutdown!\n");return;
}
}
close(tact_d);
return 0;
}
//tactsw 선택목록
void menu()
{
puts("*********Dot Dot Menu*********");
puts("* 1. I N S I D E *");
puts("* 2. O U T S I D E *");
puts("* 3. U P to D O W N *");
puts("* 4. D O W N to U P *");
puts("* 12. E X I T *");
puts("******************************");
}
//LED - 밖에서 안으로
void Inside()
{
int dot_d , i , j;
unsigned char data[8];
dot_d = open(dot , O_RDWR);
memset(data , 0 , sizeof(data));
for(i=0 ; i<4 ; ++i)
{
for(j=i ; j<8-i ; ++j)
{
//data[i] |= 0x80>>i;
data[j] |= 0x80>>i;
//data[7-i] |= 0x80>>i;
data[7-i] |= 0x80>>j;
//data[i] |= 0x01<<i;
data[i] |= 0x01<<j;
//data[7-i] |= 0x01<<i;
data[7-j] |= 0x01<<i;
write(dot_d , &data , sizeof(data));
usleep(500000);
}
}
close(dot_d);
}
//LED - 안에서 밖으로
void Outside()
{
int dot_d , i , j;
unsigned char data[8];
dot_d = open(dot , O_RDWR);
memset(data , 0 , sizeof(data));
for(i=4 ; i>=0 ; --i)
{
for(j=i ; j<7-i ; ++j)
{
data[j] |=0x80>>i;
data[7-i] |= 0x80>>j;
data[7-j] |= 0x01<<i;
data[i] |= 0x01<<j;
write(dot_d , &data , sizeof(data));
usleep(500000);
}
}
close(dot_d);
}
//숫자 - 위에서 아래로
void UptoDown()
{
int i,j,k,dot_d;
unsigned char c=0;
int result =0;
unsigned char a[8];
int cnt=8;
int temp[5];
char op;
unsigned char d[10][8] = {
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //zero
{0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x7E, 0x00}, //one
{0x3C, 0x66, 0x06, 0x1C, 0x30, 0x60, 0x7E, 0x00}, //two
{0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00}, //three
{0x0C, 0x1C, 0x3C, 0X6C, 0x7E, 0x0C, 0x0C, 0x00}, //four
{0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0x00}, //five
{0x1C, 0x30, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00}, //six
{0x7E, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00}, //seven
{0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00}, //eight
{0x3C, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0x00}, //nine
};
memset(a,0,sizeof(a));
if ( ( dot_d= open ( dot , O_RDWR )) < 0 )
{
fprintf(stderr, "open error\n");
exit(1);
}
for(j=0;j<10;j++)
{
for (i=0;i<8;i++)
{
a[0]=d[j][7-i];
write(dot_d,&a,sizeof(a));
usleep(100000);
for(k=7;k>=0;k--)
{
if(k==7)
{
a[k]=0;
continue;
}
a[k+1]=a[k];
}
}
}
close(dot_d);
}
//알파벳 - 아래에서 위로
void DowntoUp()
{
int i, k,j,k_temp, dot_d, range;
char temp [8]={0x00};
char num[27][8]=
{
{0x3C, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00}, //A
{0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00}, //B
{0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C, 0x00}, //C
{0x78, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0x78, 0x00}, //D
{0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00}, //E
{0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x00}, //F
{0x3C, 0x66, 0x60, 0x7E, 0x66, 0x66, 0x3E, 0x00}, //G
{0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00}, //H
{0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00}, //I
{0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38, 0x00}, //J
{0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00}, //K
{0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00}, //L
{0x66, 0xFF, 0xFF, 0xDB, 0xDB, 0xC3, 0xC3, 0x00}, //M
{0x66, 0x66, 0x76, 0x7E, 0x6E, 0x66, 0x66, 0x00}, //N
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //O
{0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00}, //P
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x06}, //Q
{0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66, 0x00}, //R
{0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C, 0x00}, //S
{0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, //T
{0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //U
{0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00}, //V
{0xC3, 0xC3, 0xC3, 0xDB, 0xDB, 0xFF, 0x66, 0x00}, //W
{0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00}, //X
{0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00}, //Y
{0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E, 0x00}, //Z
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
};
dot_d=open(dot, O_RDWR);
if(dot_d<0)
{
printf("Dot Open Failed !!!\n");
exit(0);
}
k=0;
k_temp=k;
while(1)
{
for(i=7;i>=0;i--)
{
if(k>=0)
{
temp[i]=num[0][k];
k--;
}
}
k_temp++;
k=k_temp;
write(dot_d, temp, sizeof(temp));
usleep(100000);
if(temp[0]==0x00 && temp[7]==0x00)
break;
}
close(dot_d);
}
1. 초기설정
sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib lib32z1
2. 컴파일
/opt/gnueabi/opt/ext-toolchain/bin/arm-linux-gnueabihf-gcc exam.c -o exam
3. Test
- 윈도우(메인 OS)로 실행파일 복사
- Tera Term에서 포트 설정 후 설정 -> 시리얼 포트 -> 속도를 115200으로 설정
- Hybus-Smart4412 장비 부팅
- 메뉴 -> 전송 -> ZMODEM -> 보내기 에서 실행파일 선택
- chmod 777 [실행파일명] (실행파일 권한 설정)
- ./[실행파일명] (실행 후 테스트)
(★중요 : 만약 소스파일을 수정 했다면 Tera Term 에서 먼저 rm [실행파일명] 을 한 뒤 다시 ZMODEM -> 보내기 에서 실행파일 선택 후 chmod 777 [실행파일명] 와 ./[실행파일명] 다시 실행)
'Embedded > Kernel Porting' 카테고리의 다른 글
[Kernel Porting] 커널포팅 최종실습-1 (0) | 2016.12.21 |
---|---|
[Kernel Porting] Dot matrix를 이용한 전광판 만들기 (1) | 2016.12.21 |
[Kernel Porting] Dip스위치와 Dot matrix를 이용하여 다양하게 점멸해보기 (0) | 2016.12.19 |
[Kernel Porting] Dot matrix 표정다른 스마일 2초반복 (0) | 2016.12.19 |
[Kernel Porting] Dot matrix 슬픈 스마일 그려보기 (0) | 2016.12.19 |