7월19일 Mango-m32(7-segment) java(FileInputStrem,문자스트림)
2010. 7. 19. 11:14ㆍ2010년/7월
역시 기본은 회로도부터 볼줄 알아야한다.! mango-m32에 회로도를 보면 7-segment에서는 총 9개의 연결통로가 필요하다. VOD_3v3 을 보니깐 PC8를 통해서 전류가 통하는것 같고 R129 10K의 그라운드가 있다. PC0는=>A PC1=>B PC2=>C PC3=>D PC4=>E PC5=>F PC6=>C_DP PC7=>G 로 하나씩 연결되어있다.
전에 배운 아트메가 DK-128경우는 FND로 화면에 찍을때 데이터값에다가 0을 넣어주면 0이 출력이 되었고 1을 넣으면 1일 출력이 되었지만 여기서는 그 방식이 아니라 총 8개에 대해서 하나씩 찍어줘야한다. 가령 숫자 1을 나타내고 싶으면 B와 C를 불들어오게하고 전부 불을 키면 DP인 점까지 다 켜지게 된다.
일단 Port C를 사용한다는 점을 알게되었고 Port C중에서도 총 9핀을 사용한다는 점을 알게 되었다. 그중에서 PC8이 전원이며 나머지에 출력에 따라서 각각 값이 켜진다.
일단 RCC에서 PortC를 열어야한다.
RCC에서 4002 1018번지에 Port Enable에 대해서 나와있다 C를 사용하기 위해서는 4번비트에 값을 넣어줘야한다. 그렇기 때문에 (*(volatile unsigned *) 0x40021018)|=16을 넣어버리면된다. 그러면 바로
PORT C의 사용이 가능하다
MODE부분에 각각 값을 전부 11넣고 CNF부분에서 00을 넣어서 output모드로 만든다.
9PIN까지 사용하기때문에
값을 넣게 되면 모든 7-segment에 불이 다들어 오게된다.
BS0~BS8까지 넣게 되면 reset으로 다 꺼버리고 BR0~BR8까지 넣으면 다시 켜진다
그럼 이제 0부터 9까지 찍을수 있다..
#define RCC_PORT (*(volatile unsigned *) 0x40021018)
#define PORTC_LOW (*(volatile unsigned *) 0x40011000)
#define PORTC_HIGH (*(volatile unsigned *)0x40011004)
#define PORTC_BSRR (*(volatile unsigned *)0x40011010)
static void delay(volatile double a)
{
for(;a>0;--a)
{
;
}
}
void segment() //전부 불켜기
{
PORTC_LOW |= 0x3<<0; //0 A
PORTC_LOW |= 0x3<<4; //1 B
PORTC_LOW |= 0x3<<8; //2 C
PORTC_LOW |= 0x3<<12; //3 D
PORTC_LOW |= 0x3<<16; //4 E
PORTC_LOW |= 0x3<<20; //5 F
PORTC_LOW |= 0x3<<24; //6 .
PORTC_LOW |= 0x3<<28; //7 G
PORTC_HIGH |= 0x3<<0; //0 power
}
void reset() //전부 리셋
{
PORTC_BSRR |= 0xFF;
}
void set() //전부 세
{
PORTC_BSRR |= 0xFF<<16;
}
void zero()
{
PORTC_BSRR |= 0x3F<<16;
}
void one()
{
PORTC_BSRR |= 0x6<<16;
}
void two()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<20;
PORTC_BSRR |= 0x1<<19;
PORTC_BSRR |= 0x1<<17;
PORTC_BSRR |= 0x1<<16;
}
void three()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<19;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<17;
PORTC_BSRR |= 0x1<<16;
}
void four()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<17;
}
void five()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<19;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<16;
}
void six()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<20;
PORTC_BSRR |= 0x1<<19;
PORTC_BSRR |= 0x1<<18;
}
void seven()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<17;
PORTC_BSRR |= 0x1<<16;
}
void eight()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<20;
PORTC_BSRR |= 0x1<<19;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<17;
PORTC_BSRR |= 0x1<<16;
}
void nine()
{
PORTC_BSRR |= 0x1<<24;
PORTC_BSRR |= 0x1<<23;
PORTC_BSRR |= 0x1<<21;
PORTC_BSRR |= 0x1<<18;
PORTC_BSRR |= 0x1<<17;
PORTC_BSRR |= 0x1<<16;
}
int main(void)
{
RCC_PORT |= 0x1<<4; //포트 C 열기
while(1)
{
segment();
delay(30000);
reset();
zero();
delay(30000);
reset();
one();
delay(30000);
reset();
two();
delay(30000);
reset();
three();
delay(30000);
reset();
four();
delay(30000);
reset();
five();
delay(30000);
reset();
six();
delay(30000);
reset();
seven();
delay(30000);
reset();
eight();
delay(30000);
reset();
nine();
}
=======================================================================================
=======================================================================================
import java.io.*;
public class StandardStream
{
public static void main(String args[])throws IOException
{
int n;
char ch;
boolean quit = false;
while(false==quit)
{
System.out.print("Please enter a letter or digit <'q' to quit> :");
n = System.in.read();
System.in.skip(2);
ch = (char)n;
if(ch=='q') quit=true;
else if(Character.isDigit(ch))System.out.println(ch+"is the digit you typed.\n");
else if(Character.isLetter(ch))System.out.println(ch +"is the letter you typed.\n");
else System.err.println("Please enter a letter or digit.\n");
}
}
}
====================================================================
====================================================================
import java.io.*;
import java.util.*;
public class SimpleFile
{
public static void main(String args[])throws IOException
{
FileInputStream inFile = null;
FileOutputStream outFile = null;
try{
inFile = new FileInputStream(".\\dataFile\\infile2.txt");
outFile = new FileOutputStream(".\\dataFile\\outfile2.txt");
}catch(FileNotFoundException fileNotFound)
{
System.out.println("Could not open file.");
System.exit(0);
}
int data;
while((data = inFile.read())!=-1)
{
outFile.write(data);
}
inFile.close();
outFile.close();
}
}
====================================================================
====================================================================
import java.io.*;
import java.util.*;
public class SimpleFileReadLine
{
static FileReader inFile;
static BufferedReader inBuffer;
static FileWriter outFile;
static BufferedWriter outBuffer;
public static void main(String arags[] )throws IOException
{
try
{
inFile = new FileReader(".\\dataFile\\infile4.txt");
inBuffer = new BufferedReader(inFile);
outFile = new FileWriter(".\\dataFile\\outfile4.txt");
outBuffer = new BufferedWriter(outFile);
}catch(FileNotFoundException fileNotFound)
{
System.out.println("Could not open file");
System.exit(0);
}
String aLine;
while((aLine=inBuffer.readLine())!=null)//\n는 읽지않는다.
{
System.out.println(aLine);
outBuffer.write(aLine,0,aLine.length());
outBuffer.newLine(); //한줄씩 write한후에 \n를 추가
}
inBuffer.close();
outBuffer.close();
}
}
=======================================================================================
=======================================================================================
'2010년 > 7월' 카테고리의 다른 글
7월21일 JAVA(동기화) ARM(7-segment,USART1) (0) | 2010.07.21 |
---|---|
7월20일 JAVA(Thread),ARM( (0) | 2010.07.20 |
7월16일 Mango-M32(LED 켜기,7-segment) (0) | 2010.07.16 |
7월15일 STM32F103RBT6 (Mango-M32)설치및 설명 (0) | 2010.07.15 |
7월14일 그래픽2(Flow,Border,Grid)빌어먹을계산기 (0) | 2010.07.14 |