chap #2 펌웨어작성을위한c언어icfs1.tistory.com/upload_control/download.blog?fhandle=......
Post on 04-Feb-2020
1 Views
Preview:
TRANSCRIPT
Chap #2펌웨어 작성을 위한 C언어 I
http://www.smartdisplay.co.kr
www.smartdisplay.co.kr
강의 계획
Chap1. 강의계획및 디지털 논리 이론Chap2. 펌웨어 작성을 위한 C언어 IChap3. 펌웨어 작성을 위한 C언어 IIChap4. AT89S52 메모리 구조Chap5. SD-52보드 구성과 코드 메모리 프로그래밍 방법Chap6. 어드레스 디코딩(매핑)과 어셈블리어 코딩 방법Chap7. LED, LCD와 7-세그먼트 켜기 및 IIC 통신Chap8. 인터럽트와 타이머Chap9. 직렬통신과 PS2 키보드 인터페이스Chap10. 리모콘 수신과 RTC 및 SpeakerChap11. AD컨버터와 DA컨버터Chap12. OSD (On-Screen Display)
www.smartdisplay.co.kr
1
www.smartdisplay.co.kr
Visual C++ 실행 하기(1/4)
Visual C++ 셋업후 실행 화면
www.smartdisplay.co.kr
Visual C++ 실행 하기(2/4)
File -> New
Win32 Console Application
www.smartdisplay.co.kr
Visual C++ 실행 하기(3/4)
A simple application
www.smartdisplay.co.kr
Visual C++ 실행 하기(4/4)
www.smartdisplay.co.kr
C 프로그램의 구조
#include <stdio.h> //전처리기 명령
void main(void){
// 프로그램 내용}
//Visual C++에서 자동 코딩 되어 나온 함수#include "stdafx.h"int main(int argc, char* argv[]){
// 프로그램 내용return 0;
}
- 대,소 문자를 구별- 함수를 기본- main함수 에서 시작
www.smartdisplay.co.kr
기본 입출력 함수(1/3)
출력 함수 - printf()
#include "stdafx.h"#include "stdio.h"
void main(void){
int num1 = 12; // 0x0C (2진수는 사용 못함)int num2 = 34; // 0x22
printf("안녕하세요. 스마트 디스플레이 입니다. \n");printf("%d %d \n ", num1, num2);
}
%d : 10진수%o : 8진수%x : 16진수%c : 문자 출력%f : 소숫점형태로 출력
www.smartdisplay.co.kr
기본 입출력 함수(2/3)
입력함수 - scanf()
#include "stdafx.h"#include "stdio.h"
void main(void){
int num;
printf("좋아하는 숫자를 입력하세요.. \n");scanf("%d", &num);printf("당신이 좋아하는 숫자는 %d 입니다. \n", num);
}
www.smartdisplay.co.kr
기본 입출력 함수(3/3)문자와 문자열의 입출력
#include "stdafx.h"#include "stdio.h"void main(void){
char ch;char name[20];
printf("알파벳 문자 한개만 입력하세요.\n");scanf("%c", &ch);printf("이름을 써 보아요.\n");scanf("%s", name);printf("%s씨 알파벳 %c를 선택했네요\n",name, ch);
}
char c; // 문자 ‘a’char *s; // 문자열 “smartdisplay”
// name = &name[0]
www.smartdisplay.co.kr
데이터 형 (1/1)
자료형의 크기정수형 : Int , short, long, unsigned int, unsigned short, unsigned long실수형 : float, double, long문자형 : int, unsigned char
#include "stdafx.h"#include "stdio.h"void main(void){
printf("int = %d BYTE\n", sizeof(int));printf("short = %d BYTE\n", sizeof(short));printf("long = %d BYTE\n", sizeof(long));printf("unsigned = %d BYTE\n", sizeof(unsigned));printf("float = %d BYTE\n", sizeof(float));printf("double = %d BYTE\n", sizeof(double));printf("char = %d BYTE\n", sizeof(char));
}
www.smartdisplay.co.kr
연산자 (1/2)
변수나 상수를 어떻게 처리 할 것 인가를 지시하는 기호
산술연산자 : +, -, *, /, %관계연산자 : <. <=, ==, >=, >, !=논리 연산자 : &&, ||증감 연산자 : ++, --비트 연산자 : &, |, ~, <<, >> 포인터 연산자 : &, *
www.smartdisplay.co.kr
연산자 (1/2)산술 연산자2 + 4, A * B, A % B5 % 3 = 2관계 연산자3 < 5, 4 <= 5, 4 <= 4, 4 == 4, 5 > 4, 5 != 4논리 연산자A and B,A or B증감 연산자++A, A++ --A, A--Ex) A = 10(1) B = ++A; // B = 11 (2) B = A++; // B = 10
비트 연산자A=b’10100001B=b’00110011
A & B = b’00100001A | B = b’10110011~A = b’01011110A << 3 = b’00000100A >> 3 = b’00010100
포인터 연산자& : 주소* : 내용
www.smartdisplay.co.kr
제어문(1/9)
프로그램의 처리 순서를 변경시킬 때 사용
- 선택문 : if, switch
- 반복문 : for, while, do while
- 분기문 : break, continue, goto
www.smartdisplay.co.kr
제어문(2/9)선택문 1 : ifType 1)
If (수식)
실행문;If (수식)
실행문;
Type 2)If (수식)
실행문;else
실행문;
#include "stdafx.h"#include "stdio.h"
void main(void){
int num;
printf("1과 2중 하나를 선택하세요....?");scanf("%d", &num);
if(num == 1)printf("1을 선택하셨습니다.\n");
else if(num == 2)printf("2을 선택하셨습니다.\n");
elseprintf("말을 잘 안들으시네요..\n");
}
www.smartdisplay.co.kr
제어문(3/9)
선택문 2 : switch
switch (변수) {case 수식1: 문장1;break;case 수식2: 문장2;break;
default : 문장3;}
#include "stdafx.h"#include "stdio.h"
void main(void){
int num;
printf("1과 2중 하나를 선택하세요....?");scanf("%d", &num);
switch(num){case 1:
printf("1을 선택하셨습니다.\n");break;
case 2:printf("2을 선택하셨습니다.\n");break;
default : printf("말을 잘 안들으시네요..\n");
}}
www.smartdisplay.co.kr
제어문(4/9)
반복문 1 : for
for (초기값; 최종값; 증가 값) {문장;
}
#include "stdafx.h"#include "stdio.h"
void main(void){
int i;int num = 0;
for(i = 0; i <= 100; i++){
num += i; //num = num + i }
printf("0부터 100까지의 합은 %d 입니다.\n", num);}
www.smartdisplay.co.kr
제어문(5/9)
반복문 2 : while
While (수식){문장;
}
#include "stdafx.h"#include "stdio.h"void main(void){
int i = 0;int num;while(i++ < 3){
printf("1과 2중 하나를 선택하세요....?");scanf("%d", &num);switch(num){
case 1:printf("1을 선택하셨습니다.\n");break;
case 2:printf("2을 선택하셨습니다.\n");break;
default : printf("말을 잘 안들으시네요..\n");
}}
}
www.smartdisplay.co.kr
제어문(6/9)
반복문 2 : do ~ while
do {문장;
} while(수식);
#include "stdafx.h"#include "stdio.h"void main(void){
int i = 0;int num;do{
printf("1과 2중 하나를 선택하세요....?");scanf("%d", &num);switch(num){
case 1:printf("1을 선택하셨습니다.\n");break;
case 2:printf("2을 선택하셨습니다.\n");break;
default : printf("말을 잘 안들으시네요..\n");
}
}while(i++ < 3);}
www.smartdisplay.co.kr
제어문(7/9)
분기문 1 : break
break;
#include "stdafx.h"#include "stdio.h"
void main(void){
int i;int num = 0;
for(i = 0; i <= 10; i++){
if(i == 5)break;
printf("i의 값 = %d\n", i);}
}
www.smartdisplay.co.kr
제어문(8/9)
분기문 2 : continue
continue;
#include "stdafx.h"#include "stdio.h"
void main(void){
int i;int num = 0;
for(i = 0; i <= 10; i++){
if(i == 5)continue;
printf("i의 값 = %d\n", i);}
}
www.smartdisplay.co.kr
제어문(9/9)
분기문 3 : goto
goto 레이블:
#include "stdafx.h"#include "stdio.h"
void main(void){
int i;int num = 0;
for(i = 0; i <= 10; i++){
if(i == 5)goto loop1;
printf("i의 값 = %d\n", i);}
loop1:
}
www.smartdisplay.co.kr
숙제
1~1000까지의 숫자중 짝수와 홀수의 합은 ?
구구단 프로그램을 짜세요.
100 팩토리알은 몰까요?
ex) 100*99*98*…*1 = ?
www.smartdisplay.co.kr
다음 강의 내용
“펌웨어 작성을 위한 C언어 나머지 부분“
top related