728x90
반응형
ARM 프로젝트 두번째 날.
#define PMC_PCER (*(volatile unsigned int*)0xFFFFFC10)
#define MASTERCLOCK 48000000
#define PIO_PUER (*(volatile unsigned int*)0xFFFFF464)
#define PIO_PUDR (*(volatile unsigned int*)0xFFFFF460)
#define PIO_PER (*(volatile unsigned int*)0xFFFFF400)
#define PIO_PDR (*(volatile unsigned int*)0xFFFFF404)
#define PIO_OER (*(volatile unsigned int*)0xFFFFF410)
#define PIO_ODR (*(volatile unsigned int*)0xFFFFF414)
#define PIO_IER (*(volatile unsigned int*)0xFFFFF440)
#define PIO_IFER (*(volatile unsigned int*)0xFFFFF420)
#define PIO_IMR (*(volatile unsigned int*)0xFFFFF420)
#define PIO_ISR (*(volatile unsigned int*)0xFFFFF44C)
#define PIO_ASR (*(volatile unsigned int*)0xFFFFF470)
#define PIO_BSR (*(volatile unsigned int*)0XFFFFF474)
#define PIO_SODR (*(volatile unsigned int*)0xFFFFF430)
#define PIO_CODR (*(volatile unsigned int*)0xFFFFF434)
#define AIC_IECR (*(volatile unsigned int*)0xFFFFF120)
#define AIC_SMR ( (volatile unsigned int*)0xFFFFF000)
#define AIC_SVR ( (volatile unsigned int*)0XFFFFF080)
#define AIC_IDCR (*(volatile unsigned int*)0XFFFFF124)
#define AIC_ICCR (*(volatile unsigned int*)0XFFFFF128)
#define DBGU_CR (*(volatile unsigned int*)0XFFFFF200)
#define DBGU_MR (*(volatile unsigned int*)0XFFFFF204)
#define DBGU_SR (*(volatile unsigned int*)0XFFFFF214)
#define DBGU_RHR (*(volatile unsigned int*)0XFFFFF218)
#define DBGU_THR (*(volatile unsigned int*)0XFFFFF21C)
#define DBGU_BRGR (*(volatile unsigned int*)0XFFFFF220)
#define DBGU_IER (*(volatile unsigned int*)0XFFFFF208)
#define DBGU_IMR (*(volatile unsigned int*)0XFFFFF210)
#define TC0_CCR (*(volatile unsigned int*)0XFFFA0000)
#define TC0_CMR (*(volatile unsigned int*)0XFFFA0004)
#define TC0_CV (*(volatile unsigned int*)0XFFFA0010)
#define TC0_RA (*(volatile unsigned int*)0XFFFA0014)
#define TC0_RB (*(volatile unsigned int*)0XFFFA0018)
#define TC0_RC (*(volatile unsigned int*)0XFFFA001C)
#define TC2_CCR (*(volatile unsigned int*)0XFFFA0080)
#define TC2_CMR (*(volatile unsigned int*)0XFFFA0084)
#define TC2_CV (*(volatile unsigned int*)0XFFFA0090)
#define TC2_RA (*(volatile unsigned int*)0XFFFA0094)
#define TC2_RB (*(volatile unsigned int*)0XFFFA0098)
#define TC2_RC (*(volatile unsigned int*)0XFFFA009C)
#define PIT_MR (*(volatile unsigned int*)0XFFFFFD30)
#define PIT_SR (*(volatile unsigned int*)0XFFFFFD34)
#define PIT_PIVR (*(volatile unsigned int*)0XFFFFFD38)
#define PIT_PIIR (*(volatile unsigned int*)0XFFFFFD3C)
#define ADC_CR (*(volatile unsigned int*)0XFFFD8000)
#define ADC_MR (*(volatile unsigned int*)0XFFFD8004)
#define ADC_CHER (*(volatile unsigned int*)0XFFFD8010)
#define ADC_CHSR (*(volatile unsigned int*)0XFFFD8018)
#define ADC_SR (*(volatile unsigned int*)0XFFFD801C)
#define ADC_LCDR (*(volatile unsigned int*)0XFFFD8020)
#define ADC_CDR ( (volatile unsigned int*)0XFFFD8030)
#include<math.h>
const char password[6] = {'1','2','3','4','5','6'};
char dh[6] = {'0','0','0','0','0','0'};
unsigned int cnt = 0;
int flag = 0;
///////////딜레이 함수/////////////////////////////
void Delayms(unsigned int ms)
{
volatile unsigned int count, countmax = (MASTERCLOCK / 10000) * ms;
for(count = 0; count < countmax; count++);
}
///////////////숫자를 char 형으로 바꾸기 함수//////////////////////
char* Numtochar(int data)
{
int i=0;
int cnum=0;
int knum;
char arr[5];
knum = data;
while(knum!=0)
{
knum=knum/10;
cnum++;
}
for(i=cnum; i>=1; i--)
{
if(cnum==i-1)
{
arr[cnum-i] = (data/(pow(10,i)))+48;
}
else if(i==1)
{
arr[cnum-i] = (data%10)+48;
}
else
{
arr[cnum-i] = ((data%(int)(pow(10,i))/(pow(10,i-1))))+48;
}
}
arr[cnum]=0;
return arr;
}
////////////////////////////////////////////
void adc_processor()
{
unsigned int clear;
int data;
char* arr;
int i;
ADC_CR = 1<<1;
data = ADC_SR;
if(ADC_SR & (1<<4))
{
data = ADC_CDR[4];
Delayms(1000);
arr = Numtochar(data);
for(i=0;arr[i]!=0;i++)
{
DBGU_THR = arr[i];
Delayms(10);
}
Delayms(1000);
}
clear = ADC_SR;
}
////////////////////PMC함수////////////////////////////////////
void pmc()
{
PMC_PCER = 1<<2 | 1<<4 | 1<<14;
}
///////////////////PIO함수/////////////////////////////////////
void pio()
{
PIO_PER = 0xFF;
PIO_OER = 0xFF;
PIO_PDR = 0xFFFFFF00;
PIO_ASR = 0x00000600;
PIO_BSR = 1<<26 | 1<<27;
//PIO_PUER = 1<<13;
//PIO_IER = 1<<13;
//PIO_IFER = 1<<13;
}
//////////////DBGU 함수//////////////////////////////////////////
void dbgu()
{
DBGU_CR = 1<<6 | 1<<4; // DBGU 제어 레지스터
DBGU_BRGR = 26; // DBGU 보 레이트 발생 레지스터 : 115200
DBGU_MR = 1<<11; // DBGU 모드 레지스터 - ch:정상모드(00), parity 사용안함
DBGU_IER = 1<<0;//rx 인터럽트 허용
}
//////////인터럽트 함수 ///////////////////////////////////////////
void interrupt()
{
int clear;
if(DBGU_SR & (1<<0))
{
dh[cnt] = DBGU_RHR;
cnt++;
}
clear = PIO_ISR;
}
/////////////////////////////////////////////////
void swinterrupt()
{
adc_processor();
}
/////////////////////AIC 함수////////////////////////////////////
void aic()
{
AIC_IECR = 1<<1 | 1<<2;
AIC_SMR[1] = 5;
AIC_SVR[1] = (unsigned int)interrupt;
AIC_SMR[2] = 6;
AIC_SVR[2] = (unsigned int)swinterrupt;
}
//////////////////ADC 함수/////////////////////////////////////
void adc()
{
ADC_MR = 1<<4 | 1<<8 | 1<<9;
ADC_CHER = 1<<4;
}
/////////////////TC2함수//////////////////////////////////
void tc2()
{
TC2_CCR = 5;
TC2_CMR = 1<<15 | 1<<0 | 1<<19 | 1<<16 | 1<<27 | 1<<24 | 1<<10;
TC2_RA = 100;
TC2_RB = 100;
TC2_RC = 60000;
}
///////////text LCD 명령 함수/////////////////////////////////
void LCD_Instruction(int data)
{
PIO_CODR = 0xffff;
PIO_CODR = 1<<0 | 1<<1;
Delayms(1);
PIO_SODR = 1<<2;
PIO_SODR = data<<3;
Delayms(1);
PIO_CODR = 1<<2;
Delayms(1);
PIO_CODR = data<<3;
PIO_SODR = 1<<0 | 1<<1;
}
///////////text LCD 표시함수///////////////////////////////////
void LCD_Display(int val)
{
PIO_CODR = 0xffff;
PIO_SODR = 1<<0;
PIO_CODR = 1<<1;
Delayms(1);
PIO_SODR = 1<<2;
PIO_SODR = val<<3;
Delayms(1);
PIO_CODR = 1<<2;
Delayms(1);
PIO_CODR = val<<3;
PIO_CODR = 1<<0;
PIO_SODR = 1<<1;
}
/////////////병렬입출력 모드 함수//////////////////////
void io()
{
PIO_ASR = 0x00000000;
PIO_PER = 0x00000FFF;
PIO_OER = 0x00000FFF;
PIO_PUDR = 0x00000FFF;
PIO_CODR = 0x00000FFF;
}
/////////////////LCD 제어 함수///////////
void LCD_out()
{
LCD_Instruction(0x38); //Function Set 2 line, 8bit
LCD_Instruction(0x06); //Entry Mode set
LCD_Instruction(0x1C); //Cursor or Display shift
LCD_Instruction(0x0C); //Set Display
LCD_Instruction(0x01); //Clear Display
}
////////타이머카운터를 이용한 LED1 밝기 조정 함수 ////////////
void LED_bright1()
{
if( flag == 0)
{
TC2_RA += 200;
TC2_RB = 60000;
Delayms(10);
if(TC2_RA > TC2_RC)
{
flag = 1;
}
}
if(flag == 1)
{
TC2_RA -= 200;
TC2_RB = 60000;
Delayms(10);
if(100 > TC2_RA)
{
flag = 0;
}
}
}
////////타이머카운터를 이용한 LED2 밝기 조정 함수 ////////////
void LED_bright2()
{
if( flag == 0)
{
TC2_RA = 60000;
TC2_RB += 200;
Delayms(10);
if(TC2_RB > TC2_RC)
{
flag = 1;
}
}
if(flag == 1)
{
TC2_RA = 60000;
TC2_RB -= 200;
Delayms(10);
if(100 > TC2_RB)
{
flag = 0;
}
}
}
/////////////////비교함수////////////////////
void compare()
{
int a;
int b = 0;
int err = 0;
for(a=0;a<6;a++)
{
if( dh[a] == password[a] )
{
b++;
if( b == 6 )
{
io();
LCD_out();
LCD_Display('L');
LCD_Display('o');
LCD_Display('g');
LCD_Display(0x20);
LCD_Display('I');
LCD_Display('n');
LCD_Display('!');
Delayms(500);
pio();
dbgu();
adc();
while(1)
{
LED_bright2();
adc_processor();
}
}
}
else if(dh[a] != password[a] )
{
err++;
}
}
if(err>0)
{
cnt = 0;
for(a=0;a<6;a++)
{
dh[a] = '0';
}
io();
LCD_out();
LCD_Display('W');
LCD_Display('r');
LCD_Display('o');
LCD_Display('n');
LCD_Display('g');
LCD_Display(0x20);
LCD_Display('P');
LCD_Display('a');
LCD_Display('s');
LCD_Display('s');
LCD_Display('w');
LCD_Display('o');
LCD_Display('r');
LCD_Display('d');
LCD_Display('!');
Delayms(1000);
LCD_out();
LCD_Display('I');
LCD_Display('n');
LCD_Display('p');
LCD_Display('u');
LCD_Display('t');
LCD_Display(0x20);
LCD_Display('P');
LCD_Display('a');
LCD_Display('s');
LCD_Display('s');
LCD_Display('w');
LCD_Display('o');
LCD_Display('r');
LCD_Display('d');
pio();//디버그유닛 쓸때
dbgu();//
}
}
/////////////////////////메인함수///////////////////////////////
int main(void)
{
Delayms(30);
pmc();
io();//엘시디 쓸때
LCD_out();
LCD_Display('I');
LCD_Display('n');
LCD_Display('p');
LCD_Display('u');
LCD_Display('t');
LCD_Display(0x20);
LCD_Display('P');
LCD_Display('a');
LCD_Display('s');
LCD_Display('s');
LCD_Display('w');
LCD_Display('o');
LCD_Display('r');
LCD_Display('d');
pio();//디버그유닛 쓸때
dbgu();//
aic();
tc2();
while(1)
{
LED_bright1();
if( cnt == 6)
{
compare();
cnt = 0;
}
}
return 0;
}
대략적인 구성은 간단한 로그인 시스템을 만들었는데 ARM과 터미널이 통신이 되고 있는데 로그인을 하지 않은 상태에서는 타이머/카운터를 사용한 LED 두개중 한개가 밝기 조정을 하면서 켜졌다 꺼졌다 하고 있다. 로그인이 되지 않았다는것을 나타내기 위해 붉은색 LED를 썼다.
그리고 Text LCD에는 Input Password를 출력하고있다. 이때 사용자는 터미널에서 암호 6자리를 입력하는데 키보드에서 한자리씩 입력할때마다 인터럽트를 썼다. 미리 지정된 암호 6자리와 사용자가 입력한 암호 6자리가 맞지 않으면 Text LCD 에는 Wrong Password 라는 메세지가 나오고 다시 Input Password 메세지를 날린다.
지정된 암호 6자리와 입력한 6자리 암호가 맞으면 Text LCD에 로그인이 되었다는 메세지가 나오고 로그인이 되면서 타이머/카운터를 사용한 붉은색 LED는 꺼지고 나머지 LED한개가 반응한다. 로그인이 되었다는 것을 나타내기 위해서 초록색 LED를 썼다.
그리고 로그인이 되는 동시에 장착되어 있던 조도센서에서 ADC를 이용해서 일정시간동안 값을 읽어와 터미널로 그 값을 뿌리는 것까지 구현을 해놓았다.
내일은 PIT기능을 추가 하고 잔잔한 버그등을 수정할 예정이다.
728x90
'코스웨어 > 10년 스마트폰BSP' 카테고리의 다른 글
[BSP]박노준_7월20일 작업일지 (0) | 2010.07.21 |
---|---|
[BSP]업무일지-이상구-20100719 (0) | 2010.07.19 |
[BSP] 업무일지 -김기찬- (0) | 2010.07.16 |
[BSP]업무일지-정호영-20100715 (0) | 2010.07.15 |
[BSP]업무일지-서동준-20100713 (0) | 2010.07.15 |
[BSP]업무일지-강혜정-20100712 (0) | 2010.07.12 |
[BSP]업무일지 - 김강수 - 20100708 (0) | 2010.07.12 |
[BSP]업무일지 - 김병찬 - 20100707 (0) | 2010.07.08 |