임베디드 프로그래밍  

         
전체 기타 | WinCE | Delphi | VisualC | ARM | Media | SE | 마리오네트 | Java | wdm | JTAG | 영상처리 | 인증 | 질문/답변 | H/W | 알고리즘 | Platform | .net | VB | PPC | Network | android | QT | WWW | Linux |
S3C2410 Keyboard와 LCD 제어하기 예제
하창호03-17 15:20 | HIT : 4,338

UPLOAD 1 ::Ex19)keyboardGraphic.zip (132.6 KB) | DOWN : 145
// S3C2410 Keyboard와 LCD 제어하기 예제
#include <stdlib.h>
#include <string.h>

#include "def.h"
#include "option.h"
#include "s3c2410x.h"
#include "selib.h"
#include "selib_a.h"
#include "graphics.h"

char Ascii_NoShift[7][14]= {
//                           0    1     2     3     4     5     6     7     8     9    10    11    12    13
/*0*/                {LAlt,  '`',  0  ,LCtrl,  FN , ESC , '1' , '2' , '9' , '0' , '-' , '=' ,  0  , '\b'  },
/*1*/                {  0 , '\\', LSft,  0  ,  0  , Del ,  0  , 't' , 'y' , 'u' , 'i' ,Enter, RSft, PgDn  },
/*2*/                {  0 , '\t',  0  ,  0  ,  0  , 'q' , 'w' , 'e' , 'r' , 'o' , 'p' , '[' ,  0  , ']'   },
/*3*/                {  0 , 'z' ,  0  ,  0  ,  0  ,CapLk,  0  ,  0  , 'k' , 'l' , ';' ,  39 ,  0  , PgUp  },
/*4*/                {  0 , 'a' ,  0  ,  0  ,  0  , 's' , 'd' , 'f' , 'g' , 'h' , 'j' , '/' ,  0  , Home  },
/*5*/                {  0 , 'x' ,  0  ,  0  ,  0  , 'c' , 'v' , 'b' , 'n' , 'm' , ',' , '.' ,  0  , ' '   },
/*6*/                {  0 ,  0  ,  0  ,  0  ,  0  , '3' , '4' , '5' , '6' , '7' , '8' , Prog,  0  , End   }

};                                                        

char Ascii_Shift[7][14]= {
//                           0    1     2     3     4     5     6     7     8     9    10    11    12    13
/*0*/                {LAlt,  0  , '~' ,LCtrl,  0  , ESC , '!' , '@' , '(' , ')' , '_' , '+' ,  0  , '\b'  },
/*1*/                {  0 , '|' ,  0  ,  0  ,  0  , Del ,  0  , 'T' , 'Y' , 'U' , 'I' ,Enter,  0  , PgDn  },
/*2*/                {  0 ,  0  ,  0  ,  0  ,  0  , 'Q' , 'W' , 'E' , 'R' , 'O' , 'P' , '{' ,  0  , '}'   },
/*3*/                {  0 , 'Z' ,  0  ,  0  ,  0  ,CapLk,  0  ,  0  , 'K' , 'L' , ':' , '"' ,  0  , PgUp  },
/*4*/                {  0 , 'A' ,  0  ,  0  ,  0  , 'S' , 'D' , 'F' , 'G' , 'H' , 'J' , '?' ,  0  , Home  },
/*5*/                {  0 , 'X' ,  0  ,  0  ,  0  , 'C' , 'V' , 'B' , 'N' , 'M' , '<' , '>' ,  0  , ' '   },
/*6*/                {  0 ,  0  ,  0  ,  0  ,  0  , '#' , '$' , '%' , '^' , '&' , '*' , Prog,  0  , End   }

};

volatile int ShiftFlag=0, CapFlag=0, FNFlag=0, AltFlag=0, StrPtr, CursorFlag=1;
volatile int  Lcd_X=0, Lcd_Y=0 ;

char buffer[256];


//===================================================================
void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception.\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception.\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception.\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception.\n");
    while(1);
}
//===================================================================

void Timer0_Init(void)
{
     rTCFG0=(rTCFG0&0xffffff00)|(250);                // Prescaler=1/256 for Timer0
     rTCFG1=(rTCFG1&0xfffffff0)|0x01;                // Mux=1/2 for Timer0
     rTCNTB0=25920-1;                                // Timer0=((202800000/4)/128/2)/25920
     rTCMPB0=rTCNTB0-1;
     rTCON|=0x02;    
     rTCON=(rTCON&0xfffffff0)|0x09;                // Interval Mode, Inverter Off, Update        
        
} // end of Timer0_Init(...)        

/*
void Timer1_Init(void)
{
     rTCFG0=(rTCFG0&0xffffff00)|(128-1);                // Prescaler=1/128 for Timer0
     rTCFG1=(rTCFG1&0xffffff0f)|(0x0<<4);        // Mux=1/2 for Timer0
     rTCNTB1=25920/2-1;                                // Timer1=((202800000/4)/128/2)/25920
     rTCMPB1=rTCNTB1-1;
     rTCON|=(0x02<<8);    
     rTCON=(rTCON&0xfffff0ff)|(0x09<<8);        // Interval Mode, Inverter Off, Update        
        
} // end of Timer1_Init(...)        
*/

void PrintToBuffer(char ch) {

        buffer[StrPtr++]=ch;
        buffer[StrPtr]='\0';
}


void SPI1_Init(void) {

         rSPPRE1=249;                        // baud rate = 100KHz  (baud rate < 500KHz)
         rSPCON1=(rSPCON1 & ~(0x78)) | 0x38;        // interrupt mode, SCK enable, Master,

//         Uart_Printf("rGPBCON : %x\n", rGPBCON);
         rGPBCON=(rGPBCON & ~(0x3<<12)) | 0x01<<12;        // GPB6 : output
//         Uart_Printf("rGPBCON : %x\n", rGPBCON);

//         rGPBUP=(rGPBUP & ~(0x1<<6));                // GPB6 pullup

         rGPBDAT |= 0x40;        // initial nSS_KBD : High

} // end of SPI1_Init()

void __irq Rx_ISR(void)
{
     rSRCPND=BIT_UART0;                                // Clear pending bits  
     rINTPND=BIT_UART0;  
         rSUBSRCPND=BIT_SUB_RXD0;


//         Lcd_Printf(Lcd_X,Lcd_Y,BLUE,WHITE,1,1,"%s","PC : ");
//         Lcd_X += 40;
         if (rUTRSTAT0 & 0x01) {
//                  Lcd_Y +=17; Lcd_X=0;
//                  Lcd_X=0;
                 if (Lcd_X > 231) { Lcd_X =0; Lcd_Y +=17; }
                 if (Lcd_Y > 300) { Lcd_Y =0; Lcd_Clrscr(); Lcd_Bar(1,1,239,319, WHITE);}
                 Lcd_Printf(Lcd_X,Lcd_Y,BLUE,WHITE,1,1,"%c",rURXH0);
                 Lcd_X += 9;
         }


//         if ((data !='\b')&(data !=Enter)) { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",data); Lcd_X +=9;}

//         Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",'*');
//         Lcd_X +=9;
        
} // end of __irq Timer0_Isr(...)



void __irq Timer0_Isr(void)
{
     rSRCPND=BIT_TIMER0;                                // Clear pending bits  
     rINTPND=BIT_TIMER0;  

//         Uart_Printf("CursorFlag : %d\n", CursorFlag);
         if (CursorFlag==1)  { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",'_'); CursorFlag=0; }
         else if (CursorFlag==0)  { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",' '); CursorFlag=1; }
//         Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",'*');
//         Lcd_X +=9;
        
} // end of __irq Timer0_Isr(...)

/*
void __irq Timer1_Isr(void)
{
     rSRCPND=BIT_TIMER1;                                // Clear pending bits  
     rINTPND=BIT_TIMER1;  

} // end of __irq Timer1_Isr(...)
*/

void __irq SPI1_ISR() {

        volatile int column, row, data;


        rSRCPND = BIT_SPI1;                // source pending register
        rINTPND =        BIT_SPI1;                // interrupt pending register

        while(!(rSPSTA1 & 0x1));
//        Uart_Printf("%d \n", rSPRDAT1);

        if ((rSPRDAT1==RSft) | (rSPRDAT1==LSft)) ShiftFlag=1;
        if (rSPRDAT1==LAlt) AltFlag=1;
        if (rSPRDAT1==FN) FNFlag=1;
        if (rSPRDAT1==CapLk)  {
                CapFlag=(CapFlag+1) % 2;
//                Uart_Printf("CapFlag : %d\n",CapFlag);
        }

        if (rSPRDAT1 == 105) {
                PrintToBuffer('\b');        // if Back Space, printf("\b \b")
                PrintToBuffer(' ');

                Lcd_X -= 9;
                Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",' ');
        }

        if (rSPRDAT1 == 90) {                // if enter key pressed, send buffer[256] to Uart...
                Uart_SendString("\nARM ->   \b\b\b\t");
                Uart_SendString(buffer);
                StrPtr = 0;

                Lcd_X=0; Lcd_Y +=17;
                Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",' ');                
        }


        if ((rSPRDAT1 < 128) & (rSPRDAT1 != CapLk) & (rSPRDAT1 != RSft) & (rSPRDAT1 != LSft)) {
                if (( ShiftFlag==0 & CapFlag==0 ) | (ShiftFlag==1 & CapFlag==1)) {        // Normal Key pressed
                        column=(int)((rSPRDAT1-1)/8);
                        row=(rSPRDAT1-1) % 8;
                        data=Ascii_NoShift[row][column];
                        PrintToBuffer(data);

                        if (Lcd_X > 231) { Lcd_X =0; Lcd_Y +=17; }
                        if (Lcd_Y > 300) { Lcd_Y =0; Lcd_Clrscr(); Lcd_Bar(1,1,239,319, WHITE);}
                        if ((data !='\b')&(data !=Enter)) { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",data); Lcd_X +=9;}

                }        // end if (.......)
                else if (ShiftFlag==1 & CapFlag==0)  {        
                        column=(int)((rSPRDAT1-1)/8);
                        row=(rSPRDAT1-1) % 8;
                        data=Ascii_Shift[row][column];
                        PrintToBuffer(data);

                        if (Lcd_X > 231) { Lcd_X =0; Lcd_Y +=17; }
                        if (Lcd_Y > 300) { Lcd_Y =0; Lcd_Clrscr(); Lcd_Bar(1,1,239,319, WHITE);}
                        if ((data !='\b')&(data !=Enter)) { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",data); Lcd_X +=9;}

                }        // end if (ShiftFlag)
                else if (ShiftFlag==0 & CapFlag==1) {        
                        column=(int)((rSPRDAT1-1)/8);
                        row=(rSPRDAT1-1) % 8;
                        data=Ascii_NoShift[row][column];                
                        if (data > 96 & data < 123)                        // change lower alphabet to Capital....
                                data=Ascii_Shift[row][column];
                        PrintToBuffer(data);

                        if (Lcd_X > 231) { Lcd_X =0; Lcd_Y +=17; }
                        if (Lcd_Y > 300) { Lcd_Y =0; Lcd_Clrscr(); Lcd_Bar(1,1,239,319, WHITE);}
                        if ((data !='\b')&(data !=Enter)) { Lcd_Printf(Lcd_X,Lcd_Y,BLACK,WHITE,1,1,"%c",data); Lcd_X +=9;}

                }        // end if (ShiftFlag)
        }        // end if (rSPRDAT1 < 128)
        else if (rSPRDAT1 >= 128) {                // Key Unpressed
                if ((rSPRDAT1==(RSft|0x80)) | (rSPRDAT1==(LSft|0x80))) ShiftFlag=0;
                if (rSPRDAT1==(LAlt|0x80)) AltFlag=0;
                if (rSPRDAT1==(FN|0x80)) FNFlag=0;
        }
}

void __irq EINT1_Isr(void)
{
     rSRCPND=BIT_EINT1;                                // Clear pending bits  
     rINTPND=BIT_EINT1;  

//        ClearPending(BIT_EINT1);
         // Receive data from KBD Controller
         rGPBDAT &= ~(0x40);                // nSS_KBD set to 0

//        Uart_Printf("E");

         rSPTDAT1 = 0xff;

         Delay(1);

        rGPBDAT |= 0x40;                // nSS_KBD set 1

} // end of __irq Timer1_Isr(...)
//===================================================================


void Isr_Init(void)
{
     pISR_UNDEF  = (unsigned)HaltUndef;
     pISR_SWI    = (unsigned)HaltSwi;
     pISR_PABORT = (unsigned)HaltPabort;
     pISR_DABORT = (unsigned)HaltDabort;

        

     pISR_TIMER0 =(unsigned)Timer0_Isr;         //pISR_FIQ,pISR_IRQ must be initialized
//     pISR_TIMER1 =(unsigned)Timer1_Isr;
     pISR_EINT1 =(unsigned)EINT1_Isr;
         pISR_SPI1=(unsigned)SPI1_ISR;
     pISR_UART0=(unsigned)Rx_ISR;            //pISR_FIQ,pISR_IRQ must be initialized


     rINTMOD     = 0x0;                             //All=IRQ mode
     rINTMSK     = BIT_ALLMSK;                      //All interrupt is masked.
     rINTSUBMSK  = BIT_SUB_ALLMSK;                  //All sub-interrupt is masked. <- April 01, 2002 SOP
     rINTMSK     = ~(BIT_TIMER0|BIT_EINT1|BIT_SPI1|BIT_UART0);           //Enable UART0 Default value=0xffffffff    
     rINTSUBMSK  = ~(BIT_SUB_RXD0);         //Enable Rx0 Default value=0x7ff


        rEXTINT0 = (rEXTINT0 & ~(7<<4)) | 0x2<<4 ; //EINT1=falling edge

//    rEXTINT1 = (rEXTINT1 & ~(0x7000)) | 0x2000;
//    rEXTINT2 = (rEXTINT2 & ~(0xf000)) | 0xa000;

}



void Main(void)
{
     int i;        
        
     Port_Init();    
     MMU_Init();
     ChangeClockDivider(1,1);          // 1:2:4        
     ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz  

     Delay(0);        //calibrate Delay()    
     Uart_Init(0,115200);
     Uart_Select(0);


     Graphic_Init();
         Lcd_Clrscr();

         Uart_Printf("KBD test\n");

     Lcd_Bar(1,1,239,319, WHITE);
         Lcd_Printf(Lcd_X,Lcd_Y,BLUE,WHITE,2,2,"Chatting !");
         Lcd_X=0;Lcd_Y=40;

     Timer0_Init();

        SPI1_Init();
           Isr_Init();
         while(1) ;
        
}


36  ARM :: 인터럽트 핸들링    하창호 2007·08·29 4423
35  ARM :: CC 와 Slick Editer & T32 를 연동 프로젝트...    하창호 2007·02·15 4229
34  ARM :: T32 매크로 팁 중 현재 디렉토리 가져오는 방법    하창호 2007·02·08 3773
33  ARM :: 플레쉬에 대해서    하창호 2006·04·12 3846
32  ARM :: 삼성 반도체 홈페이지 Flash S/W 및 PocketStore I...    하창호 2006·04·12 4239
31  ARM :: MMU (memory management unit)    하창호 2005·03·10 4179
30  ARM :: ARM 프로세스이해 교육완수 예제    하창호 2004·03·23 4411
29  ARM :: S3C2410 터치스키린 이용한 그림판 제작 예제    하창호 2004·03·22 5666
28  ARM :: 이종수 박사 ADS, SDT, GCC 를 이용한 예제    하창호 2004·03·22 4850
27  ARM :: S3C2410 LCD에 아날로그 시계 출력하기 (숙제 3)    하창호 2004·03·22 5937
26  ARM :: S3C2410 LCD에 이미지 출력하기 예제    하창호 2004·03·19 6448
25  ARM :: [ASM] 1부터 10 까지 더하기 GCC 사용    하창호 2004·03·19 3995
24  ARM :: [ASM] LOOP 를 이용한 메모리간 복사 GCC 사용  …3  하창호 2004·03·19 4212
23  ARM :: 이종수 박사 ARM 이론강의 요약    하창호 2004·03·18 6557
22  ARM :: ARM Down, GCC 를 받을 수 있는 곳    하창호 2004·03·18 3615
21  ARM :: SMDK2410(S3C2410) Board Reference    하창호 2004·03·18 3791
20  ARM :: S3C2410X USER'S MANUAL    하창호 2004·03·18 3466
19  ARM :: SDT 관련문서    하창호 2004·03·18 3309
18  ARM :: GCC 관련문서    하창호 2004·03·18 3431
17  ARM :: ARM명령어요약    하창호 2004·03·18 3633
16  ARM :: 이종수 박사 ARM 뛰어넘기 교재    하창호 2004·03·18 4972
15  ARM :: ARM Architecture Reference Manual  …1  하창호 2004·03·18 3492
14  ARM :: 에디터 (숙제 2)    하창호 2004·03·17 3520
13  ARM :: S3C2410 IIS를 이용한 사운드 출력 예제    하창호 2004·03·17 4354
 ARM :: S3C2410 Keyboard와 LCD 제어하기 예제    하창호 2004·03·17 4338
11  ARM :: S3C2410 Keyboard 제어하기 예제    하창호 2004·03·17 4168
10  ARM :: DNW 시리얼을 사용하여 프로그램을 다운로드 및 실행하...    하창호 2004·03·17 5582
9  ARM :: APM DownLoader 방식과 DNW DownLoader ...  …1  하창호 2004·03·17 3825
8  ARM :: S3C2410 간단한 알람 시계 예제 (숙제1)    하창호 2004·03·16 4970
7  ARM :: S3C2410 Watch Dog Timer 사용 예제    하창호 2004·03·16 4457
6  ARM :: S3C2410 타이머와 인터럽트로 LED 불켜기    하창호 2004·03·16 4304
5  ARM :: ARM 프로세스의 이해 강의 자료    하창호 2004·03·16 4919
4  ARM :: S3C2410 시리얼로 값 입력받는 계산기 만들기    하창호 2004·03·16 4188
3  ARM :: CPU 최대 주파수를 가지고 최소 타이머 주기 알아내기  …36  하창호 2004·03·16 2906
2  ARM :: S3C2410 버튼 입력받아 LED 불켜기 예제    하창호 2004·03·15 4555
1  ARM :: S3C2410 LED 불켜기 예제    하창호 2004·03·15 4451
1
   
Copyright 1999-2018 Zeroboard / skin by GGAMBO
....