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