■Stairs_of_infinty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#include<time.h>
#include<stdlib.h>
#include "2450addr.h"
#include "my_lib.h"
#include "macro.h"
void MMU_Init(void);
 
#include "./Images/BLOCK.H"
#include "./Images/CLOUD.H"
#include "./Images/TITLE1.H"
#include "./Images/TITLE2.H"
#include "./Images/ICON.H"
#include "./Images/ENDGAME.H"
 
#include "./Images/RPENGUIN.H"
#include "./Images/LPENGUIN.H"
#include "./Images/RHEDGE.H"
#include "./Images/LHEDGE.H"
#include "./Images/RDINO.H"
#include "./Images/LDINO.H"
 
// Color Define
#define BLACK    0x0000
#define WHITE        0xfffe
#define BLUE        0x003e
#define GREEN    0x07c0
#define RED        0xf800
#define YELLOW    0xffc0
 
// ISR Functions declaration
 
#define LCD_XSIZE         (480)    
#define LCD_YSIZE         (272)
 
// Functions Declaration
 
void HW_Initial(void);
void Show_Welcome(char * msg);
 
// Global Variables Declaration
 
volatile int Touch_pressed = 0;
volatile int ADC_x=0, ADC_y=0;
 
 
volatile int Cal_x1=848;
volatile int Cal_y1=656;
volatile int Cal_x2=186;
volatile int Cal_y2=349
 
 
volatile int Touch_x, Touch_y;
 
volatile unsigned int Touch_config=1;
/**************************************************************************************************/
typedef struct _Block{
    int x;
    int y;
}Block;
 
void Lcd_Make_Bmp_Buffer (int x, int y, const unsigned char *fp);
void Make_Buffer(int x,int y,int color);
 
void Creat_Block(void);
void Print_Block(void);
void touch_block(void);
void CountPrintf(void);
void ScorePrintf(void);
 
unsigned int bmp_buffer[272][480]; 
static unsigned int Fbuf[2= {0x338000000x33c00000};
 
unsigned short bfType;
unsigned int bfSize;
unsigned int bfOffbits;
unsigned int biWidth, biWidth2;
unsigned int biHeight;
/**************************************************************************************************/
void Touch_ISR(void) __attribute__ ((interrupt ("IRQ")));
 
void Touch_ISR()
{
    rINTSUBMSK |= (0x1<<9);
    rINTMSK1 |= (0x1<<31);    
    
    /* TO DO: Pendng Clear on Touch */    
    rSUBSRCPND |= (0x1<<9);
    rSRCPND1 |= (0x1<<31);
    rINTPND1 |= (0x1<<31);
    
    // Touch UP
    if(rADCTSC&0x100)
    {
        rADCTSC&=0xff;
        Touch_pressed = 0;
    }
    // Touch Down
    else 
    {
        rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
        // SADC_ylus Down,Don't care,Don't care,Don't care,Don't care,XP pullup Dis,Auto,No operation
        rADCCON|=0x1;
        while(rADCCON & 0x1);
        while(!(0x8000&rADCCON));
        ADC_x=(int)(0x3ff&rADCDAT0);
        ADC_y=(int)(0x3ff&rADCDAT1);
        // Touch calibration complete
        if(Touch_config)
        {
            Touch_y=(ADC_y-Cal_y1)*(LCD_YSIZE-10)/(Cal_y2-Cal_y1)+5;
            Touch_x=(ADC_x-Cal_x2)*(LCD_XSIZE-10)/(Cal_x1-Cal_x2)+5;
            Touch_x=LCD_XSIZE-Touch_x;
            if(Touch_x<0) Touch_x=0;
            if(Touch_x>=LCD_XSIZE) Touch_x=LCD_XSIZE-1;
            if(Touch_y<0) Touch_y=0;
            if(Touch_y>=LCD_YSIZE) Touch_y=LCD_YSIZE-1;
        }
        // before calibration        
        else
        {
            Touch_x = ADC_x;
            Touch_y = ADC_y;
        }
 
        rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
        // SADC_ylus Up,Don't care,Don't care,Don't care,Don't care,XP pullup En,Normal,Waiting mode
        Touch_pressed = 1
    }
 
    rINTSUBMSK &= ~(0x1<<9);
    rINTMSK1 &= ~(0x1<<31);
}
// Lower Layer Functions
 
void HW_Initial(void)
{
    Exception_Init();
    Uart_Init(115200);    
//    Led_Init();
    Buzzer_Init();
 
    Timer0_Init();
    Graphic_Init();
    
    Touch_Isr_Init(Touch_ISR);
    MMU_Init();
}
/***********************************************************************************************/
void Show_Welcome(char * msg)
{
    Uart_Printf("\n%s\n", msg);
    Lcd_Draw_BMP(0,0, title1);        //Flushing
    Timer0_Delay(3000);            
    Lcd_Draw_BMP(0,0, title2);        
    Timer0_Delay(3000);            
}
 
 
/********** Background Save **************************************************************************/
void Make_Buffer(int x,int y,int color)
{
    bmp_buffer[y][x] = (unsigned short int)color;    
}
void Lcd_Make_Bmp_Buffer (int x, int y, const unsigned char *fp)
{
     int xx=0, yy=0;    
     unsigned int tmp;
     unsigned char tmpR, tmpG, tmpB;
    
 
     bfType=*(unsigned short *)(fp+0);
     bfSize=*(unsigned short *)(fp+2);
     tmp=*(unsigned short *)(fp+4);
     bfSize=(tmp<<16)+bfSize;
     bfOffbits=*(unsigned short *)(fp+10);
     biWidth=*(unsigned short *)(fp+18);    
     biHeight=*(unsigned short *)(fp+22);    
 
     biWidth2=(bfSize-bfOffbits)/biHeight;    
 
     for(yy=0;yy<biHeight;yy++)
     {
         for(xx=0;xx<biWidth;xx++)
         {
             tmpB=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+0);
             tmpG=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+1);
             tmpR=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+2);
             tmpR>>=3
             tmpG>>=3;
             tmpB>>=3;
             
             if(xx<biWidth2) Make_Buffer(x+xx,y+yy,(tmpR<<10)+(tmpG<<5)+(tmpB<<0));
         } 
     }
}
/*************************************************************************************************/
void Lcd_Display_Frame_Buffer(unsigned int id)
{
    Lcd_Set_Address(Fbuf[id]);
}
 
void Lcd_Set_Address(unsigned int fp)
{
    rVIDW00ADD0B0 = fp;
    rVIDW00ADD1B0 = 0;
    rVIDW00ADD2B0 = (0<<13)|((LCD_XSIZE*4*2)&0x1fff);
 
    rVIDW00ADD1B0 = 0+(LCD_XSIZE*LCD_YSIZE);
}
/*************************************************************************************************/
int random;
int icon_flag=0;
int game_enable =1;
int Survival_count=20;//Survival time
int character_pose = 0;//0 : Right, 1 : Left
 
int size = 15;        //init block count
Block block_ary[15];
int blockS_x = 390, blockS_y = 120;    //start point
int block_cnt = 0;
 
 
void Creat_Block(void)    //height : 28 , width : 48 ; block
{
 
    int i;
    int position_x,position_y;
 
    block_ary[0].x=blockS_x;
    block_ary[0].y=blockS_y;
 
    position_x = blockS_x;
    position_y = blockS_y;
 
    for(i=1;i<size;i++)
    {
    random =rand()%5;
 
    if(random>2)
        {
            block_ary[i].x = position_x-28;
            block_ary[i].y = position_y-48;
            position_x = block_ary[i].x;
            position_y = block_ary[i].y;
        }
    else
        {
            block_ary[i].x = position_x-28;
            block_ary[i].y = position_y+48;
            position_x = block_ary[i].x;
            position_y = block_ary[i].y;
        }
    }
}
 
 
 
void Print_Block(void)
{
    int i;
 
    Lcd_Select_Frame_Buffer(0);
 
    for(i=0;i<size;i++)
    Lcd_Draw_BMP(block_ary[i].x,block_ary[i].y, block);    
 
    Lcd_Draw_BMP(432,0, icon);        
 
    if(icon_flag==0){
    if(character_pose== 0)
    Lcd_Draw_BMP(362,130, Rpenguin);
    else
    Lcd_Draw_BMP(362,130, Lpenguin);
    }
 
    if(icon_flag==1){
    if(character_pose== 0)
    Lcd_Draw_BMP(362,130, Rhedge);    
    else
    Lcd_Draw_BMP(362,130, Lhedge);    
    }
 
    if(icon_flag==2){
    if(character_pose== 0)
    Lcd_Draw_BMP(362,130, Rdino);    
    else
    Lcd_Draw_BMP(362,130, Ldino);    
    }
}
 
void touch_block(void)
{
    int i;
    int x,y;
 
    
    if(!game_enable && Touch_pressed)        //game end
    {
        block_cnt = 0;
        Survival_count=20;
 
 
        for(i=0;i<size;i++)
            for(x=block_ary[i].x;x<block_ary[i].x+28;x++)
                for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++)
                    Lcd_Put_Pixel(x,y,bmp_buffer[y][x]);
 
        Creat_Block();
        /*clear end bar, score bar*******************/
 
            for(x=150;x<150 +32;x++)
                for(y=0 ;y<272;y++)
                    Lcd_Put_Pixel(x,y,bmp_buffer[y][x]);
 
            for(x=450;x<450 +32;x++)
                for(y=0 ;y<272 + 10;y++)
                    Lcd_Put_Pixel(x,y,bmp_buffer[y][x]);
 
 
        /*************************************/
        game_enable =1;    //game restart
 
    }
 
    else if(game_enable&&Touch_pressed)    //game start
    {
        Uart_Printf("\nX:%d, Y:%d", Touch_x, Touch_y); 
 
        Jumpsound();    //buzzer
 
        /*difficulty control*************************/
        if(block_cnt <10)
        Survival_count=20;
        else
        Survival_count=14;    //2sec..
        /*************************************/
        if(Touch_x>200 &&Touch_x<450&& Touch_y>140){
 
        block_cnt++;
 
        /*clear block image from background*******************/
        for(i=0;i<size;i++)
            for(x=block_ary[i].x;x<block_ary[i].x+28;x++)
                for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++)
                    Lcd_Put_Pixel(x,y,bmp_buffer[y][x]);
        /************************************************/
 
            Uart_Printf("<<<<<<<<Left Click ... <<<<<<<<<<<<\n"); 
            for(i=0;i<size;i++)
            {
                block_ary[i].x+=28;
                block_ary[i].y-=48;
            }
 
            /*first block delete and create end block*******************/
            for(i=0;i<size-1;i++)
            {
                block_ary[i].x = block_ary[i+1].x;
                block_ary[i].y = block_ary[i+1].y;
            }
                random =rand()%5;
 
                if(random>2)
                {
                    block_ary[size-1].x = block_ary[size-2].x - 28;
                    block_ary[size-1].y = block_ary[size-2].y - 48;
                }
                else
                {
                    block_ary[size-1].x = block_ary[size-2].x - 28;
                    block_ary[size-1].y = block_ary[size-2].y + 48;
                }
        
 
            /*get off the block ***********************************/
            if(blockS_x != block_ary[0].x || blockS_y != block_ary[0].y){
                    Lcd_Draw_BMP(150,0, endgame);
                    game_enable=0;
                }
            /************************************************/
            character_pose = 1;
 
        }
        else if(Touch_x>200 &&Touch_x<450&& Touch_y<140){
 
        block_cnt++;
 
        for(i=0;i<size;i++)
            for(x=block_ary[i].x;x<block_ary[i].x+28;x++)
                for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++)
                    Lcd_Put_Pixel(x,y,bmp_buffer[y][x]);
        
            Uart_Printf(">>>>>>>>>Right Click ... >>>>>>>>>>>>>\n"); 
            
            for(i=0;i<size;i++)
            {
                block_ary[i].x+=28;
                block_ary[i].y+=48;
            }
            /*first block delete and create end block*******************/
            for(i=0;i<size-1;i++)
            {
                block_ary[i].x = block_ary[i+1].x;
                block_ary[i].y = block_ary[i+1].y;
            }
                random =rand()%5;
 
                if(random<3)
                {
                    block_ary[size-1].x = block_ary[size-2].x - 28;
                    block_ary[size-1].y = block_ary[size-2].y - 48;
                }
                else
                {
                    block_ary[size-1].x = block_ary[size-2].x - 28;
                    block_ary[size-1].y = block_ary[size-2].y + 48;
                }
            /*get off the block ***********************************/
            if(blockS_x != block_ary[0].x || blockS_y != block_ary[0].y){
                    Lcd_Draw_BMP(150,0, endgame);
                    game_enable=0;
                }
            /************************************************/
            character_pose= 0;
 
        }
        /*character change icon ***********************************/
        else if(Touch_x>430 &&Touch_x<480&& Touch_y<100)
        {
            icon_flag++;
            icon_flag = (icon_flag ==3) ? (icon_flag%3) : icon_flag;
        }
    }
}
 
void ScorePrintf()
{
    Lcd_Printf(170,450, RED, BLACK, 1,1,"Score : %d", block_cnt);
}
 
void CountPrintf()
{
        Survival_count--;
        if(Survival_count<0)// 3sec..
        {
            Survival_count++;
            Lcd_Draw_BMP(150,0, endgame);
            game_enable = 0 ;//gram end
        }
        Lcd_Printf(200,430, RED, BLACK, 1,1,"Survival time : %d",Survival_count/7);
}
 
void Main(void)
{
    Uart_Init(115200);
    HW_Initial();    
    Show_Welcome("Stairs of infinity");
 
    Creat_Block();
 
    Lcd_Select_Frame_Buffer(1);
    Lcd_Draw_BMP(0,0, cloud);
    Lcd_Copy(1,0);
    Lcd_Display_Frame_Buffer(0);
 
    srand(time(NULL));                
 
    Lcd_Make_Bmp_Buffer(0,0,cloud);
 
 
 
    while(1){    
        CountPrintf();
        Touch_ISR_Enable(1);
        touch_block();
        if(game_enable)
        Print_Block();
        ScorePrintf();
    }
    
}
cs



Stairs_of_infinity.tar.gz



Touch Screen

#Touch.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "2450addr.h"
 
void Touch_Init(void);
 
 
void Touch_Init(void)
{
    rADCDLY = (50000); 
     /* TO DO : prescaler enable, prescaler value=39, Analog no input, 
      *         Normal operation mode, Disable start, No operation */
        rADCCON |= (0x1<<14);
        rADCCON |= (39<<6);
        rADCCON &= ~(0x1<<3);
        rADCCON &= ~(0x1<<2);
        rADCCON &= ~(0x1<<1);
        rADCCON &= ~(0x1);
 
      
     
     /* TO DO :  For Waiting Interrupt Mode rADCTSC=0xd3 */
        rADCTSC &= ~(0x1<<8);
        rADCTSC |= (0x1<<7);
        rADCTSC |= (0x1<<6);
        rADCTSC &= ~(0x1<<5);
        rADCTSC |= (0x1<<4);
        rADCTSC &= ~(0x1<<3);
        rADCTSC &= ~(0x1<<2);
        rADCTSC |= (0x1<<1);
        rADCTSC |= (0x1);
 
}
 
cs


#Main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "2450addr.h"
#include "option.h"
 
#define EXAMPLE 610
 
#if EXAMPLE == 610
//**ISR Declaration
void Touch_ISR(void) __attribute__ ((interrupt ("IRQ")));
 
volatile  int ADC_x, ADC_y;
volatile  int Touch_Pressed=0;
 
void Touch_ISR()
{
    /* 인터럽트 허용하지 않음 on Touch */
    rINTSUBMSK |= (0x1<<9);
    rINTMSK1 |= (0x1<<31);    
    
    /* TO DO: Pendng Clear on Touch */    
    rSUBSRCPND |= (0x1<<9);
    rSRCPND1 |= (0x1<<31);
    rINTPND1 |= (0x1<<31);
 
    if(rADCTSC & 0x100)
    {
        rADCTSC &= (0xff); 
        Touch_Pressed = 0;
        Uart_Send_String("Detect Stylus Up Interrupt Signal \n");
    }
    
    else
    {
        Uart_Send_String(" ISR 내부  \n");
        
        rADCTSC &=~(0x1<<8);                //detect stylus down
        rADCTSC &= ~(0x1<<7);                //set bit for x position measurement
        rADCTSC |= (0x1<<6);                //YM=Hi-z, YP=Hi-z
        rADCTSC |= (0x1<<5);        
        rADCTSC &= ~(0x1<<4);                //XM=VSS,XP=VDD
        rADCTSC &= ~(0x1<<3);                //pull-up EN
        rADCTSC &= ~(0x1<<2);                //Normal-ADC
        rADCTSC &= ~(0x3);
        rADCTSC |= (0x1);                    //X-position = 1
 
 
        /* TO DO : ENABLE_START */        
        rADCCON |= (0x1);
        
        /* wait until End of A/D Conversion */
        while(!(rADCCON & (1<<15)));
        rADCCON &= ~(0x1);                    //Stop Conversion
 
        /*Set ADCTSC reg for Y Conversion*/ 
        ADC_x = (rADCDAT0 & 0x3ff);            //Store X value
        
        rADCTSC |= (0x1<<7);                //YM=VSS, YP=VDD
        rADCTSC &= ~(0x1<<6);
        rADCTSC &= ~(0x1<<5);                //XM=Hi-z, XP=Hi-z
        rADCTSC |= (0x1<<4);
        /* clear and then set  ADCTSC [1:0] for Y Conversion*/
        rADCTSC &= ~(0x3);
        rADCTSC |= (0x2);
    
        rADCCON |= (0x1);                //StartConversion
        while(!(rADCCON & (1<<15)));    //wait untill End of A/D Conversion
 
        ADC_y = (rADCDAT1 & 0x3ff);        //Store y value
        
        Touch_Pressed = 1;
        
        /* TO DO : change to Waiting for interrupt mode 
         *           Stylus Up, YM_out Enable, YP_out Disable, XM_out Disable, XP_out disable
         */
        rADCTSC |= (0x1<<8);
        rADCTSC |= (0x1<<7);
        rADCTSC |= (0x1<<6);
        rADCTSC &= ~(0x1<<5);
        rADCTSC |= (0x1<<4);
        rADCTSC &= ~(0x1<<3);
        rADCTSC &= ~(0x1<<2);
        rADCTSC |= (0x1<<1);
        rADCTSC |= (0x1);
             
    }
    
    /* 인터럽트 다시 허용  on Touch */
    rINTSUBMSK &= ~(0x1<<9);
    rINTMSK1 &= ~(0x1<<31);
    
}
 
void Main(void)
{    
    Uart_Init(115200);
    Touch_Init();    
    
    Uart_Printf("*** Touch Test *** \n");
    
    /* TO DO : 인터럽트 벡터에 Touch_ISR 함수 등록 */
    pISR_ADC = (unsigned int)Touch_ISR;
    
    /* TO DO :  인터럽트 허용 on Touch */
    rINTSUBMSK &= ~(0x1<<9);
    rINTMSK1 &= ~(0x1<<31);    
    
    while(1)
    {
        if(Touch_Pressed)
        {
            Uart_Printf("X : %d, Y: %d \n", ADC_x, ADC_y);    
        }
    }
}
 
#endif 
cs



********************************Touch_Init***************************


ADCDLY : ADC 간격 딜레이를 설정 (5000)

=====================================================================

ECFLG[15] : A/D 변환이 끝났는지 확인하는 비트.

PRSCEN[14] : prescaler 활성화 비트.

PRSCVL[13:6] : A/D 변환기 클럭  prescaler  값. ADC 주파수는 PCLK의 1/5보다 적은 주파수로 할당되어야 한다. 

RESSEL[3] : conversion 되는 디지털 값을 선택(10bit/12bit)

STDBM[2] : Standby mode 선택 비트. Standby 모드가 활성화 되면 현재 진행중인 A/D변환은 멈추게 되고, ADCDAT0와 ADCDAT1은 변환 이전의 데이타를 가지게 된다.

READ_START[1] : A/D변환을 시작시키는 비트이며, 변환 데이터가 읽혀 졌을 때 자동으로 다음 변환을 시작한다. 

ENABLE_START[0] : A/D 변환시작 비트이며 시작 이후에는 클리어된다.  A/D변환 방법은 2가지 방법이 있는데,  만약 READ_START 비트를 사용할 경우에는 이 비트는 의미가 없게 된다. 

=====================================================================



prescaler(프리스케일러) 란?


prescaler는 타이머에 공급하는 입력 클럭의 속도를 조절하는 분주기이다.

분주기라는 말 자체가 의미하듯이 클럭을 쪼갠다는, 즉 속도를 느리게 한다는 말이다.

예를 들어 8MHz의 입력 클럭을 2분주 하면 4MHz가 된다.




==================ADCCON=====================


[14] prescaler (Enalbe) (1)

[13:6] prescaler value를 39 (39)

[3] 10bit resolution (0)

[2] no standby mode (0) //동작 가능

[1] A/D conversion start (0) 

[0] Enable_start no setting (0)


==============================================


==================ADCTSC=====================


[8] Stylus Down (0)

[7] Y- (ON) (1)

[6] Y+ (OFF) (1)

[5] X- (OFF) (0)

[4] X+ (OFF) (1)

[3] Pull-up (ON) (0) //누설전류 방지 ->sleep/stop mode->pull-up스위치 활성화

[2] AUTO_PST(OFF) (0) //ADC conversion 사용을위해 normal ADC conversion

[1:0] Waiting for interrupt mode (1,1)


==============================================




********************************Touch_ISR***************************

start.

rINTSUBMSK(TC)

rINTMSK1(ADC)

비활성화


1. ADCTSC[8]이 stylus up이면 실행 x ,Touch_Pressed =0 설정(출력 x)



2.아니면 stylus down(pen을 종이에 쓸준비)이면 

Y- (OFF) :연결 X

Y+ (OFF) :ADC에 연결

X- (ON) :GND에 연결

X+ (ON) :VCC에 연결


==>X_POSITION 측정


3.rADCCON 0번 bit로 start


4.rADCCON 15번 bit로 A/D 끝났는지 확인(폴링)


5.끝났으면 rADCCON 0번 bit로 stop

X의 position 값은 ADCDAT0에 저장되어 있으므로 변수에 저장


6.

Y- (ON)

Y+ (ON)

X- (OFF)

X+ (OFF)



==>Y_POSITION 측정


3.rADCCON 0번 bit로 start


8.rADCCON 15번 bit로 A/D 끝났는지 확인(폴링)



9.끝났으면 rADCCON 0번 bit로 stop

Y의 position 값은 ADCDAT1에 저장되어 있으므로 변수에 저장


10. Touch_Pressed =1 설정 (출력)


11.

stylus up(pen을 종이에서 땐다)설정

Y-값 측정(ON)

Y+ (OFF)

X- (OFF)

X+ (OFF)

PULL-UP (ON)

Waiting for interrupt mode로 전환


end.

rINTSUBMSK(TC)

rINTMSK1(ADC)

다시 활성화

■DMA +Timer

#Main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
#if EXAMPLE == 370
void MemFill(unsigned long ptr, unsigned long pattern, int size)
{
    int i;
    unsigned long *data;
    data = (unsigned long *)ptr;
 
    for (i=0; i<size;i++)
        *data++ = pattern;
}
 
void MemDump(unsigned long ptr, int size)
{
    int i;
    unsigned long *data;
    data = (unsigned long *)ptr;
 
    Uart_Printf("\n");
    Uart_Printf("*** Dump Memory from [0x%08x] to [0x%08x] : \n",ptr, (unsigned long *)ptr+size);
    for (i=0; i<size;i++) {
        if ( !(i%4) )
            Uart_Printf("\n  [0x%08x] : ",data);
        Uart_Printf("0x%08x ",*data++);
    }
    Uart_Printf("\n");
}
 
 
 
 
#define pISR_DMA0        (*(unsigned *)(0x33ffff64))
static unsigned long src = 0x33000000;
static unsigned long dst = 0x33100000;
static unsigned int size = 12//word size
unsigned long pattern;
 
static void DMA0_interrupt()
{
    
    rINTSUBMSK |=(0<<18);
    rINTMSK1 |=(1<<17);
    
    rSUBSRCPND |= 0x1<<18;
    rSRCPND1|=(1<<17);    //clear
    rINTPND1 |=(1<<17);    //clear
 
    Uart_Send_String("\n###DMA0 START ...!!");
    MemDump(dst,size);
 
    //    rDMASKTRIG0 |= 0x1 <<2;            이부분을 주석처리 해주면 single mode 
 
    rINTSUBMSK &=~(1<<18);
    rINTMSK1 &=~(1<<17);
 
}
 
void Main(void)
{    
 
    //interrupt handler set
    pISR_DMA0= (unsigned int)DMA0_interrupt;
 
    rINTSUBMSK &=~(0<<18);
    rINTMSK1 &=~(1<<17);
 
    rDMASKTRIG0=0x0;
 
    //src , dest init
    rDISRC0 = src;
    rDIDST0 = dst;
 
    //disrcc , didstc init
    rDISRCC0 &= ~0x3;
    rDIDSTC0    &= ~0x7;
 
    //dcon    init 
    rDCON0 = (1<<31| (1<<30| (1<<29|(0<<28| (1<<27)| (1<<24| (0<<23)|(0<<22| (0<<20)|(size*4<<0);
 
    
    //H/W request mode;1
    rDMAREQSEL0|= (0x1<<0);    
 
 
 
    rDMAREQSEL0|= (0x9<<1);                            //Hard ware mode로 설정
 
 
 
 
    Timer_Init(0);
 
    MemFill(src,0x00000000,size);
    MemFill(dst,0x00000000,size);
 
    pattern = 0x5555aaaa;
 
    MemFill(src,pattern,size);    //src malloc;
    MemDump(src,size);
 
    Timer_Delay(1000,0);
 
    rDMASKTRIG0 = (1<<1| (1<<0);
 
 
}
# endif 
cs

#Timer.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "2450addr.h"
#include "option.h"
#include "libc.h"
 
//Function Declaration
void Timer_Init(int k);
void Timer_Delay(int msec,int k);
 
 
 
 
void Timer_Init(int k)
{
    rTCFG0=0xffff;
    rTCFG1 |= (0x3 <<(4*k));
 
 
 
 
 
    rTCFG1 |= (0x1 <<20);        //DMA    requst    channel
 
 
 
    if(k==0)
    rTCON|= 0x1 <<3;
    else if(k==4)
    rTCON|= 0x1 <<22;
    else
    {
        rTCON|= 0x80 << (4*k);
 
    }
    *(&rTCNTB0 + (k *0xc)) = 0;
    *(&rTCMPB0 + (k *0xc)) = 0;
 
  
}
 
void Timer_Delay(int msec,int k)
{
 
    switch(k)
    {
        case 0: rTCNTB0= 16.113*msec; break;
        case 1: rTCNTB1= 16.113*msec; break;
        case 2: rTCNTB2= 16.113*msec; break;
        case 3: rTCNTB3= 16.113*msec; break;
        case 4: rTCNTB4= 16.113*msec; break;
    }
 
    if(k==0)
    {
    rTCON |= (1<<1| (0);
    rTCON &= ~(1<<1);
    rTCON |= 1;
    }    
    else
    {
        rTCON |= (0x20 <<(4 * k)) | (0);
        rTCON &= ~(0x20 <<(4 *k));
        rTCON |= (0x10<<(4 *k));
    }
 
}
cs

1. TCFG1 설정
rTCFG1 |= (0x1 <<20);


2. 하드웨어 인터럽트로 설정

rDMAREQSEL0|= (0x1<<0);

rDMAREQSEL0|= (0x9<<1);



#결과


■DMA +Uart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
static    unsigned long src=0x33000000;
static    unsigned long dst=0x33100000;
static    unsigned int size = 12/* word size */
static    unsigned long pattern;
 
void DMA0_UART_Init(void)
{
    /* Init DMASKTRIG on DMA0*/
    rDMASKTRIG0 = 0x0;
    
    /* TODO : Select Base Address of Source and Destination*/
    rDISRC0 =src;
    rDIDST0 =dst;
    
    /* TO DO : Init Source & Destination Control Register on DMA0 
     * (memory -> AHB bus, INC mode, CHK_INT -> after auto-reload )
     */
    
    rDISRCC0 &= ~0x3;
    rDIDSTC0 &=~(0x7);
    
    /* TO DO : setting for H/W DMA request
     * DCON0 : Handshake[31-1], HCLK[30-1], INT mode[29-1], Single Unit[28-0], Whole service[27-1], 
     * H/W trigger[23-1], Auto Reload ON[22-0], Byte size[21:20](Note: Word size<->Byte size)
     * DMAREQSEL0 : Uart1[5:1], SWHW_SEL[0-1]
     */
    rDCON0 =(unsigned int)(0<<31)+(1<<30)+(1<<29)+(0<<28)+(1<<27)+(1<<24)+(1<<23)+(0<<22)+(0<<20)+size*4;
    rDMAREQSEL0    = (21<<1)+(0x1<<0);
     /* TO DO : Turn on Trigger*/
    rDMASKTRIG0 |= (0x1<<1);
        
}
 
void DMA0_HW_Start(void)
{    
    MemFill(src, 0x00000000size);
    MemFill(dst, 0x00000000size);    
    Uart_Printf("\nStart Memory copy test With DMA\n");    
    
    /* memory copy test with DMA */
    pattern = 0x5555aaaa;
    Uart_Printf("Fill pattern [0x%08x] to [0x%08x]\n",pattern, src);
    MemFill(src, pattern, size);
    MemDump(src, size);
    Uart_Printf("\nCopy from [0x%08x] to [0x%08x] by DMA\n",src, dst);
            
}
 
 
void Main(void)
{    
    char value;
 
    Uart_DMA_Init(115200);    
    DMA0_UART_Init();
 
    Uart_Send_Byte('\n');
    Uart_Send_Byte('A');    
    Uart_Send_String("Hello Uart Test...!!!\n");
    
    /* TO DO : 인터럽트 벡터에 DMA0_ISR 함수 등록 */
        pISR_DMA0 = (unsigned int)DMA0_ISR;
    
        
    /* TO DO : 인터럽트 허용 on DMA0 */    
        rINTSUBMSK &= ~(0x1<<18);
    rINTMSK1 &= ~(0x1<<17);
    
    DMA0_HW_Start();
    
    while(1){
        Uart_Printf("Input Value = : ");    
        value = Uart_Get_Char();
        Uart_Printf("value=%c \n", value);                                
    }
}
cs


■DMA Interrupt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
 
#if EXAMPLE == 360
void MemFill(unsigned long ptr, unsigned long pattern, int size)
{
    int i;
    unsigned long *data;
    data = (unsigned long *)ptr;
 
    for (i=0; i<size;i++)
        *data++ = pattern;
}
 
void MemDump(unsigned long ptr, int size)
{
    int i;
    unsigned long *data;
    data = (unsigned long *)ptr;
 
    Uart_Printf("\n");
    Uart_Printf("*** Dump Memory from [0x%08x] to [0x%08x] : \n",ptr, (unsigned long *)ptr+size);
    for (i=0; i<size;i++) {
        if ( !(i%4) )
            Uart_Printf("\n  [0x%08x] : ",data);
        Uart_Printf("0x%08x ",*data++);
    }
    Uart_Printf("\n");
}
 
 
 
 
#define pISR_DMA0        (*(unsigned *)(0x33ffff64))
static unsigned long src = 0x33000000;
static unsigned long dst = 0x33100000;
static unsigned int size = 12//word size
unsigned long pattern;
 
static void DMA0_interrupt()
{
    
    rINTSUBMSK |=(0<<18);
    rINTMSK1 |=(1<<17);
    
    rSUBSRCPND |= 0x1<<18;
    rSRCPND1|=(1<<17);    //clear
    rINTPND1 |=(1<<17);    //clear
 
    Uart_Send_String("\n###DMA START ...!!");
    MemDump(dst,size);
 
    rDMASKTRIG0 |= 0x1 <<2;
 
    rINTSUBMSK &=~(1<<18);
    rINTMSK1 &=~(1<<17);
 
}
 
void Main(void)
{    
    rDMASKTRIG0=0x0;
 
    //src , dest init
    rDISRC0 = src;
    rDIDST0 = dst;
 
    //disrcc , didstc init
    rDISRCC0 &= ~0x3;
    rDIDSTC0 &= ~0x7;
 
    //dcon    init 
    rDCON0 = (1<<31| (1<<30| (1<<29|(0<<28| (1<<27)| (1<<24| (0<<23)|(0<<22| (0<<20)|(size*4<<0);
 
    
    //S/W request mode;0
    rDMAREQSEL0= (0x0<<0);    
 
    
    MemFill(src,0x00000000,size);
    MemFill(dst,0x00000000,size);
 
    pattern = 0x5555aaaa;
 
    MemFill(src,pattern,size);    //src malloc;
    MemDump(src,size);
 
 
    //on_off mode ; sw trigger(start)
    rDMASKTRIG0 = (1<<1| (1<<0);
 
 
    //interrupt handler set
    pISR_DMA0= (unsigned int)DMA0_interrupt;
 
 
    rINTSUBMSK &=~(0<<18);
    rINTMSK1 &=~(1<<17);
 
}
# endif 
cs



1.시작지점과 목적지점의 주소를 입력

 rDISRC0 = src;

 rDIDST0 = dst; 


 rDISRCC0 &= ~0x3; 

 rDIDSTC0 &= ~0x7;



2. DCON0 설정

/*setting for S/W DMA request

DCON0 : Handshake[31-1], HCLK[30-1], INT mode[29-1], Single Unit[28-0], Whole service[27-1],

HW_select[26:24],  S/W trigger[23-0], Auto Reload ON[22-0], Byte size[21:20](Note: Word size<->Byte size)*/

3. 소프트웨어 인터럽트로 설정

rDMAREQSEL0 = (0x0<<0);


4. 트리거 설정, start    =>소프트웨어 인터럽트

rDMASKTRIG0 = (1<<1) | (1<<0);


5.

rINTSUBMSK    DMA모드로 설정

rINTMSK1 &=~(1<<17);    interrupt 허용






Key Interrupt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#if EXAMPLE == 350
 
#define     pISR_EINT2        (*(unsigned *)(0x33ffff28))
#define     pISR_EINT3        (*(unsigned *)(0x33ffff2c))
#define     pISR_EINT4_7        (*(unsigned *)(0x33ffff30))
 
static void EINT2_ISR(void)
{
    rINTMSK1 |=(0xf<<2);
//init    submask    4~8
    rEINTMASK  |=(0x1f<<4);
 
    //init    padding    2~8
    rSRCPND1 |= (0xf <<2);
    rINTPND1  |= (0xf <<2);
    //init    padding    4~8
    rEINTPEND |= (0x1f <<4);
 
    Uart_Send_String("EINT2 .. !!\n\n");
 
    rINTMSK1 &=~(0xf<<2);
    rEINTMASK  &=~(0x1f<<4);
}
static void EINT3_ISR(void)
{
    rINTMSK1 |=(0xf<<2);
//init    submask    4~8
    rEINTMASK  |=(0x1f<<4);
 
    //init    padding    2~8
    rSRCPND1 |= (0xf <<2);
    rINTPND1  |= (0xf <<2);
    //init    padding    4~8
    rEINTPEND |= (0x1f <<4);
 
    Uart_Send_String("EINT3 .. !!\n\n");
 
    rINTMSK1 &=~(0xf<<2);
    rEINTMASK  &=~(0x1f<<4);
}
static void EINT4_7_ISR(void)
{
    if(rEINTPEND&(1<<4)){
    rINTMSK1 |=(0xf<<2);
    rEINTMASK  |=(0x1f<<4);
 
    rSRCPND1 |= (0xf <<2);
    rINTPND1  |= (0xf <<2);
 
    rEINTPEND |= (0x1f <<4);
 
    Uart_Send_String("EINT4 .. !!\n\n");
 
    rINTMSK1 &=~(0xf<<2);
    rEINTMASK  &=~(0x1f<<4);
    }
    else if(rEINTPEND&(1<<5)){
    rINTMSK1 |=(0xf<<2);
    rEINTMASK  |=(0x1f<<4);
 
    rSRCPND1 |= (0xf <<2);
    rINTPND1  |= (0xf <<2);
 
    rEINTPEND |= (0x1f <<4);
 
    Uart_Send_String("EINT5 .. !!\n\n");
 
    rINTMSK1 &=~(0xf<<2);
    rEINTMASK  &=~(0x1f<<4);
    }
else if(rEINTPEND&(1<<6)){
    rINTMSK1 |=(0xf<<2);
    rEINTMASK  |=(0x1f<<4);
 
    rSRCPND1 |= (0xf <<2);
    rINTPND1  |= (0xf <<2);
 
    rEINTPEND |= (0x1f <<4);
 
    Uart_Send_String("EINT6 .. !!\n\n");
 
    rINTMSK1 &=~(0xf<<2);
    rEINTMASK  &=~(0x1f<<4);
    }
}
void Main(void)
{    
    //init    eint[n]    mode(2~6 , 7)
    rGPFCON &= ~(0xfff <<4); 
    rGPFCON |= (0x6aa <<4);
    
    rGPFDAT &= ~(0xff);
    //init    gpgcon0 
    rGPGCON &= ~(0x3);
    rGPGCON |= (0x1);
    
    //EXTINT    falling edge triggered
    rEXTINT0 &= ~(0xffffff <<8); 
    rEXTINT0 |= (0x2 <<8);
    rEXTINT0 |= (0x2 <<12);
    rEXTINT0 |= (0x2 <<16);
    rEXTINT0 |= (0x2 <<20);
    rEXTINT0 |= (0x2 <<24);    
    rEXTINT0 |= (0x2 <<28);
 
    pISR_EINT2 = (unsigned int)EINT2_ISR;
    pISR_EINT3 = (unsigned int)EINT3_ISR;
    pISR_EINT4_7 = (unsigned int)EINT4_7_ISR;
 
//init    mask    2~8
    rINTMSK1 &=~(0xf<<2);
            
}
# endif 
cs
#결과



■Uart Interrupt


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#if EXAMPLE == 340
 
#define     pISR_UART1        (*(unsigned *)(0x33ffff7c))
 
void UART_ISR()
{
    unsigned char ch ;
    rINTMSK1 |=(1<<23);
    rINTSUBMSK |= (0x5 <<3);
 
    rSUBSRCPND |=(1<<3);
    rSRCPND1|=(1<<23);
    rINTPND1 |=(1<<23);
 
    rINTMSK1 &=~(1<<23);
 
    
    Uart_Send_String("Uart Chracter Receive Ok .. !!\n");
    Uart_Printf("intput data : %d\n",RdURXH1());
 
    rINTSUBMSK &= ~(0x5 <<3);
 
}
void Main(void)
{    
 
    rINTSUBMSK &= ~(0x5 <<3);
 
    rINTMSK1 &=~(1<<23);
 
    
    Uart_Init(115200);
    
    /*Uart_Send_Byte('\n');
    Uart_Send_Byte('A');    
    Uart_Send_String("##Start     \n");*/
    pISR_UART1 = (unsigned int)UART_ISR;    
    
}
# endif 
cs
#결과




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "2450addr.h"
#include "option.h"
#include "libc.h"
 
//Function Declaration
void Timer_Init(int k);
void Timer_Delay(int msec,int k);
 
void Timer_Init(int k)
{
    /* 
    * TO DO :    Timer0 Init 
    * Prescaler value : 255, dead zone length = 0
    * Divider value : 1/16, no DMA mode
    * New frequency : (PCLK/(Prescaler value+1))*Divider value = (66Mhz/(256))*(1/16)
    *                = 16.113Khz(16113Hz)
    */
 
 
 
    rTCFG0=0xffff;
    rTCFG1 |= (0x3 <<(4*k));
    /* TO DO :   TCON설정 :Dead zone disable,  auto reload on, output inverter off
    *  manual update no operation, timer0 stop, TCNTB0=0, TCMPB0 =0
    */
    if(k==0)
    rTCON|= 0x1 <<3;
    else if(k==4)
    rTCON|= 0x1 <<22;
    else
    {
        rTCON|= 0x80 << (4*k);
 
    }
    *(&rTCNTB0 + (k *0xc)) = 0;
    *(&rTCMPB0 + (k *0xc)) = 0;
 
  
}
 
void Timer_Delay(int msec,int k)
{
    /*  TO DO :
    * 1) TCNTB0설정 : 넘겨받는 data의 단위는 msec이다.
    *                  따라서 msec가 그대로 TCNTB0값으로 설정될 수는 없다.
    * 2) manual update후에  timer0를 start시킨다. 
    *      note : The bit has to be cleared at next writing.
    * 3) TCNTO0값이 0이 될때까지 기다린다.     
    */
    /* YOUR CODE HERE */    
 
    switch(k)
    {
        case 0: rTCNTB0= 16.113*msec; break;
        case 1: rTCNTB1= 16.113*msec; break;
        case 2: rTCNTB2= 16.113*msec; break;
        case 3: rTCNTB3= 16.113*msec; break;
        case 4: rTCNTB4= 16.113*msec; break;
    }
 
    if(k==0)
    {
    rTCON |= (1<<1| (0);
    rTCON &= ~(1<<1);
    rTCON |= 1;
    }    
    else
    {
        rTCON |= (0x20 <<(4 * k)) | (0);
        rTCON &= ~(0x20 <<(4 *k));
        rTCON |= (0x10<<(4 *k));
    }
 
 
}
cs
Touch Screen

#Main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#if EXAMPLE == 330 
#define pISR_TIMER0         (*(unsigned *)(0x33ffff48))
#define pISR_TIMER1         (*(unsigned *)(0x33ffff4c))
#define pISR_TIMER2         (*(unsigned *)(0x33ffff50))
#define pISR_TIMER3         (*(unsigned *)(0x33ffff54))
#define pISR_TIMER4         (*(unsigned *)(0x33ffff58))
void Timer0_ISR()
{
    rINTMSK1 |=(1<<10);    //masking
    rSRCPND1 |= (0xffffffff);    //clear
    rINTPND1 |=(0xffffffff);    //clear
    Uart_Send_String("Timer ISR0\n");
    rINTMSK1 &=~(1<<10);    //timer0 enable
}
 
void Timer1_ISR()
{
 
    rINTMSK1 |=(1<<11);    //masking
    rSRCPND1 |= (0xffffffff);    //clear
    rINTPND1 |=(0xffffffff);    //clear
    Uart_Send_String("    Timer ISR1\n");
    rINTMSK1 &=~(1<<11);    //timer0 enable
}
void Timer2_ISR()
{
 
    rINTMSK1 |=(1<<12);    //masking
    rSRCPND1 |= (0xffffffff);    //clear
    rINTPND1 |=(0xffffffff);    //clear
    Uart_Send_String("        Timer ISR2\n");
    rINTMSK1 &=~(1<<12);    //timer0 enable
}
void Timer3_ISR()
{
 
    rINTMSK1 |=(1<<13);    //masking
    rSRCPND1 |= (0xffffffff);    //clear
    rINTPND1 |=(0xffffffff);    //clear
    Uart_Send_String("            Timer ISR3\n");
    rINTMSK1 &=~(1<<13);    //timer0 enable
}
void Timer4_ISR()
{
 
    rINTMSK1 |=(1<<14);    //masking
    rSRCPND1 |= (0xffffffff);    //clear
    rINTPND1 |=(0xffffffff);    //clear
    Uart_Send_String("                Timer ISR4\n");
    rINTMSK1 &=~(1<<14);    //timer0 enable
}
void Main()
{
 
    Uart_Init(115200);
    
    Uart_Send_Byte('\n');
    Uart_Send_Byte('A');    
    Uart_Send_String("##Start     \n");
 
    
    pISR_TIMER0 = (unsigned int)Timer0_ISR;
    pISR_TIMER1 = (unsigned int)Timer1_ISR;
    pISR_TIMER2 = (unsigned int)Timer2_ISR;
    pISR_TIMER3 = (unsigned int)Timer3_ISR;
    pISR_TIMER4 = (unsigned int)Timer4_ISR;
 
    Timer_Init(0);
    Timer_Init(1);        
    Timer_Init(2);
    Timer_Init(3);
    Timer_Init(4);
 
 
    rINTMSK1 &=~(1<<10);
    rINTMSK1 &=~(1<<11);
    rINTMSK1 &=~(1<<12);
    rINTMSK1 &=~(1<<13);
    rINTMSK1 &=~(1<<14);
 
 
    Timer_Delay(1000,0);
    Timer_Delay(2000,1);
    Timer_Delay(3000,2);
    Timer_Delay(4000,3);
    Timer_Delay(5000,4);
 
    
}
#endif
cs

#Timer.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "2450addr.h"
#include "option.h"
#include "libc.h"
 
//Function Declaration
void Timer_Init(int k);
void Timer_Delay(int msec,int k);
 
void Timer_Init(int k)
{
    /* 
    * TO DO :    Timer0 Init 
    * Prescaler value : 255, dead zone length = 0
    * Divider value : 1/16, no DMA mode
    * New frequency : (PCLK/(Prescaler value+1))*Divider value = (66Mhz/(256))*(1/16)
    *                = 16.113Khz(16113Hz)
    */
 
 
 
    rTCFG0=0xffff;
    rTCFG1 |= (0x3 <<(4*k));
    /* TO DO :   TCON설정 :Dead zone disable,  auto reload on, output inverter off
    *  manual update no operation, timer0 stop, TCNTB0=0, TCMPB0 =0
    */
    if(k==0)
    rTCON|= 0x1 <<3;
    else if(k==4)
    rTCON|= 0x1 <<22;
    else
    {
        rTCON|= 0x80 << (4*k);
 
    }
    *(&rTCNTB0 + (k *0xc)) = 0;
    *(&rTCMPB0 + (k *0xc)) = 0;
 
  
}
 
void Timer_Delay(int msec,int k)
{
    /*  TO DO :
    * 1) TCNTB0설정 : 넘겨받는 data의 단위는 msec이다.
    *                  따라서 msec가 그대로 TCNTB0값으로 설정될 수는 없다.
    * 2) manual update후에  timer0를 start시킨다. 
    *      note : The bit has to be cleared at next writing.
    * 3) TCNTO0값이 0이 될때까지 기다린다.     
    */
    /* YOUR CODE HERE */    
 
    switch(k)
    {
        case 0: rTCNTB0= 16.113*msec; break;
        case 1: rTCNTB1= 16.113*msec; break;
        case 2: rTCNTB2= 16.113*msec; break;
        case 3: rTCNTB3= 16.113*msec; break;
        case 4: rTCNTB4= 16.113*msec; break;
    }
 
    if(k==0)
    {
    rTCON |= (1<<1| (0);
    rTCON &= ~(1<<1);
    rTCON |= 1;
    }    
    else
    {
        rTCON |= (0x20 <<(4 * k)) | (0);
        rTCON &= ~(0x20 <<(4 *k));
        rTCON |= (0x10<<(4 *k));
    }
 
 
}
cs

#결과




+ Recent posts