7 segment 숫자와 알파벳 출력
캐소드 구동방식은 FND의 세그먼트중 켜길 원하는 비트가 0, 끄길 원하는 비트가 1이 된다.
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
unsigned char fnd[16] =
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xd8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
volatile unsigned char i;
DDRF=0xFF;
while(1)
{
for(i=0; i<16; i++)
{
_delay_ms(20);
PORTF = fnd[i];
}
}
} |
// PORTF = 0b1000000; //0
// PORTF = 0b1111001; //1
// PORTF = 0b0100100; //2
// PORTF = 0b0110000; //3 B0
// PORTF = 0b0011001; //4 99
// PORTF = 0b0010010; //5 92
// PORTF = 0b0000010; //6 82
// PORTF = 0b1011000; //7 E8
// PORTF = 0b0000000; //8 80
// PORTF = 0b0010000; //9 90
// PORTF = 0b0001000; //A 88
// PORTF = 0b0000011; //b 83
// PORTF = 0b1000110; //c c6
// PORTF = 0b0100001; //d a1
// PORTF = 0b0000110; //e 86
// PORTF = 0b0001110; //f 8e
애노드 구동방식은 FND의 세그먼트중 켜길 원하는 비트가 1, 끄길 원하는 비트가 0이 된다.
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
unsigned char fnd[10] = // 0~9
{0xC0, 0xF9, 0xA4, 0xB0, 0x99,
0x92, 0x82, 0xd8, 0x80, 0x90};
unsigned char n10;
unsigned char n1;
unsigned char num=0;
DDRH=0xFF; // 7 Segment의 Data Line
DDRJ=0xFF; // 7 Segment의 자릿수 ON/OFF
while(1)
{
n10 = num / 10; // 십의 자리
n1 = num % 10; // 일의 자리
PORTJ = 0x00; // ON
PORTH = fnd[n10]; // Data
PORTJ = 0x01; // OFF
_delay_ms(2);
PORTJ = 0x00;
PORTH = fnd[n1];
PORTJ = 0x02;
_delay_ms(2);
PORTJ = 0x00;
num++;
num = num % 100;
}
return 0;
} |
C#
static/instance
-Field
-Method
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calcurator
{
class Program
{
//+,- 연산기(2개 값 입력받아 +,- 연산실행)
// class op의 plus()와 minus() 구현하고 이를 활용한 class Program의 Main() 구현
static void Main(string[] args)
{
int a;
int b;
int result;
Console.Write("첫번째 정수 입력-> ");
a = int.Parse(Console.ReadLine());
Console.Write("두번째 정수 입력-> ");
b = int.Parse(Console.ReadLine());
result = op.plus(a, b);
Console.WriteLine("{0} + {1} = {2}", a, b, result);
result = op.minus(a, b);
Console.WriteLine("{0} - {1} = {2}", a, b, result);
return;
}
}
class op
{
public static int plus(int a, int b)
{
return a + b;
}
public static int minus(int a, int b)
{
return a - b;
}
}
} |
Output :
출력전용 매개변수 (out 키워드)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UsingOut
{
class MainApp
{
static void Divide(int a, int b, out int quotient, out int remainder) // 몫과 나머지
{
quotient = a / b;
remainder = a % b;
}
static void Main(string[] args)
{
int a = 20;
int b = 3;
int c; //quotient 몫
int d; // remainder 나머지
Divide(a, b, out c, out d);
Console.WriteLine("a:{0}, b:{1}:, a/b:{2}, a%b:{3}", a, b, c, d);
}
}
} |
Output :
a:20, b:3:, a/b:6, a%b:2
square 메소드 구현
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ex6_1
{
class Program
{
static double Square(double arg)
{
return arg * arg;
}
static void Main(string[] args)
{
Console.Write("수를 입력하세요: ");
string input = Console.ReadLine();
double arg = Convert.ToDouble(input);
Console.WriteLine("결과: {0}", Square(arg));
}
}
} |
Output :
'코스웨어 > 16년 스마트컨트롤러' 카테고리의 다른 글
이름 (0) | 2016.05.20 |
---|---|
2016-05-19_조재찬_업무일지_ AVR-LCD출력 & C#-성적관리 프로그램 (0) | 2016.05.20 |
2016-05-18_조재찬_스터디일지_ C#-설문조사 APP, 기초복습 (0) | 2016.05.19 |
2016-05-18_조재찬_업무일지_ C#-OOP와 클래스 (0) | 2016.05.18 |
2016-05-16_조재찬_업무일지_AVR 입출력/ C#기초 (0) | 2016.05.16 |
칸 아카데미 암호학 강좌 (2) | 2016.05.14 |
아마존 딥러닝 라이브러리 DSSTNE 발표 (0) | 2016.05.14 |
2016-05-03_조재찬_스터디일지_C언어 기초 문제풀이 (0) | 2016.05.04 |