728x90

카운터와 LED TEST



VCC는 빨간선, GND는 검은색 선임을 잘 확인하고 기판에 연결



seven segment에 00 이 출력된다.






 3

 2

 1

 0

 3

 2

 1

 0

 J

 1

 9

 L

 L

 L

 L

 H

 L 

 L 

 H 


0 | 9

09를 출력하기 위해선 PORTA에서 J19에 연결되는 핀을 위와 같이 연결한다. 






프로그래밍을 통한 숫자 바꾸기


숫자 34 출력



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#define DDRA (*((volatile unsigned long *)0x21)) #define PORTA (*((volatile unsigned long *)0x22)) #define PINA (*((volatile unsigned long *)0x20)) int main(void) //void 안적으면 컴파일시 warning isn't a prototype { volatile unsigned long uiCnt; DDRA=0xFF; // 모두 출력으로 쓴다. PORTA=0x00; PORTA=((34/10)<<4)|34%10; while(1) { } return 0; }


십자리에 3을 출력

34/10=3

3=0011  

0011<<4=00110000  // 0011의 비트를 왼쪽으로 4칸 이동 (shift 연산자)


일자리에 4를 출력

34/10의 몫은 3이고 "나머지는 4"


0011 0000

0000 0100

------------------비트 or연산 (논리합)

0011 0100




카운터 


#define DDRA	(*((volatile unsigned long *)0x21))
#define PORTA	(*((volatile unsigned long *)0x22))
#define PINA	(*((volatile unsigned long *)0x20))


int main(void) //void 안적으면 컴파일시 warning isn't a prototype
{
	volatile unsigned int uiCnt;
	volatile unsigned int uiLoop;

	DDRA=0xFF; // 모두 출력으로 쓴다.	
 	PORTA=0x00;

	uiCnt=0;
	while(1)
	{	
		for(uiLoop=0;60000>uiLoop;++uiLoop);
                PORTA=((uiCnt/10)<<4)|(uiCnt%10);
		++uiCnt;
	}
	return 0;
}



위 소스 그대로 프로그래밍시 카운터 앞자리가 사라지는 문제가 생긴다.



해결을 위해 while문 사이에 소스를 추가  if(uiCnt>99) { uiCnt=0; }
#define DDRA	(*((volatile unsigned long *)0x21))
#define PORTA	(*((volatile unsigned long *)0x22))
#define PINA	(*((volatile unsigned long *)0x20))


int main(void) //void 안적으면 컴파일시 warning isn't a prototype
{
	volatile unsigned int uiCnt;
	volatile unsigned int uiLoop;

	DDRA=0xFF; // 모두 출력으로 쓴다.	
 	PORTA=0x00;

	uiCnt=0;
	while(1)
	{	
                if(uiCnt>99)
		{
			uiCnt=0;
		}

		for(uiLoop=0;60000>uiLoop;++uiLoop);
                PORTA=((uiCnt/10)<<4)|(uiCnt%10);
		++uiCnt;
	}
	return 0;
}

앞자리 문제 해결



if, else문 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>

int main()
{
	int iNum;
	printf("숫자를 입력하시오: \n");
	scanf("%d", &iNum);
	
	if(100<iNum)
	{
		printf("100보다 큰수입니다\n");
	}
	else
	{
		printf("100보다 작은수입니다\n");
	}
	return 0;
}

if()에서 괄호안이 조건


조건이 참일때 if {}의 내용들 수행

거짓일때 else {}의 내용들 수행



Output:





LED 교차 점등 TEST


#define DDRA (*((volatile unsigned char *)0x21)) #define PORTA (*((volatile unsigned char *)0x22)) #define PINA (*((volatile unsigned char *)0x20)) int main(void) //void 안적으면 컴파일시 warning isn't a prototype { volatile unsigned int uiCnt; unsigned int uiPos; uiPos=0; int iDir=1; DDRA=0xFF; // 모두 출력으로 쓴다. PORTA=0x00; // LED를 끈다. while(1) { if(1==iDir)// iDir(direction)이 1일때 { PORTA=~(1<<uiPos); //순방향 } else { PORTA=~(0x0080>>uiPos); //역방향 0x0080=1000 0000 } for(uiCnt=0;60000>uiCnt;++uiCnt); uiPos=uiPos+1; if(7<uiPos) { iDir=iDir*-1; // iDir이 -1이 되고 else{} 수행 uiPos=0; } } return 0; }


19번째 줄 PORTA=~(1<<uiPos);

~( )은 NOT 연산자


1<<uiPos   0000 0001을 왼쪽으로 uiPos(0~7)의 bit만큼 옮김

끝의 LED는 1000 0000이며, NOT 연산자인 ~()가 붙어서 0111 1111이 됨


PORTA


 L

 H

 H

 H

 H

 H

 H

 L

 0

 1

 1

 1

 1

 1

 1

 0



if(7<uiPos) { iDir=iDir*-1; uiPos=0; }

uiPos가 7을 초과할 시, iDir은 -1이 되고 else{} 수행


LED TEST



'Study > Embedded' 카테고리의 다른 글

20160316-LCD출력  (0) 2016.03.17
20160315-펌웨어 분석 및 학습  (0) 2016.03.16
20160314-펌웨어 분석(외부 인터럽트)  (0) 2016.03.15
20160310-CPU 모듈2  (0) 2016.03.10
20160309-CPU 모듈  (0) 2016.03.09

+ Recent posts