Embedded System/Project

[project] 도트매트릭스 테스트

임베지수 2017. 4. 2. 14:48

인터넷에 돌아다니는 소스코드 그대로 돌려보았다. 그랬더니... 우왕ㅋ굳ㅋ 잘 되네. 이제 소스 분석해서 만들어야겠다~

 

인터넷에 돌아다니는 소스는 옛날에 만들어진거라서 winAVR에서 지원안하는 놈들이 좀 있다.

그럴땐 <compat/deprecated.h>라는 헤더파일을 추가해주면 된다.

 

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
//------------------------------------------------------------------------------
//  LED MODULE TEST PROGRAM  SamSung SLM1608
//------------------------------------------------------------------------------                                                       
 
//  MPU: ATmega128-16au
//  Clock: 16Mhz
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <compat/deprecated.h>
 
#define red_on         sbi(PORTC,0)
#define red_off     cbi(PORTC,0)
#define green_on    sbi(PORTC,1)
#define green_off   cbi(PORTC,1)
#define clock_on     sbi(PORTC,2)
#define clock_off     cbi(PORTC,2)
#define bright_on     sbi(PORTC,3)
#define bright_off     cbi(PORTC,3)
#define reset_on     sbi(PORTC,4)
#define reset_off     cbi(PORTC,4)
#define select_on     sbi(PORTC,5)
#define select_off     cbi(PORTC,5)
 
volatile unsigned char reset_count;
volatile unsigned char data_count;
volatile unsigned int  cursor_count;
volatile unsigned int  cursor;
 
void display(void);
void port_init(void);
void timer0_init(void);
 
unsigned int const led_red[]={
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x3fec,0x060c,0x060c,0x0f3c,0x0f3c,0x198c,0x30cc,
                0x606c,0x000c,0x000c,0x180c,0x1800,0x1ffc,0x0ffc,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x7fec,0x7fec,0x198c,0x198c,0x198f,0x198f,0x7fec,
                0x7fec,0x000c,0x0000,0x3000,0x3000,0x3ffc,0x1ffc,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
 };
unsigned int const led_green[]={
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x3fcc,0x006c,0x006c,0x0c6c,0x0ccf,0x0c0c,0x7ffc,
                0x000c,0x000c,0x07f0,0x1c1c,0x180c,0x1c1c,0x07f0,0x0000,
                0x0000,0x7fec,0x7fec,0x198c,0x198c,0x198f,0x198f,0x7fec,
                0x7fec,0x000c,0x0000,0x3000,0x3000,0x3ffc,0x1ffc,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
                0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};
 
//----------- Timer0(8bit) Interrupt service  ----------------------------------
SIGNAL(SIG_OVERFLOW0){
    TCCR0 = 0x04;        // CLK/64 prescale
    TCNT0 = 0x06;        // 1msec
 
    cursor_count++;
    if(cursor_count>70){
      cursor_count=0;
      cursor++;
      if(cursor>64){
        cursor=0;
      }
    }
 
  display();
}
//-----------Port Initialize ---------------------------------------------------
void port_init(void){
  PORTC=0x00;
  DDRC=0xff;
 
  red_off;
  green_off;
  clock_off;
  bright_on;
  reset_off;
  reset_count=0;
  cursor_count=0;
  cursor=0;
  select_on;
}
//----------- Timer0(8bit) Initialize ------------------------------------------
void timer0_init(void){
  TIMSK=0x01;   // T0 overflow interrupt Enable
  TCCR0 = 0x04;        // CLK/64 prescale
  TCNT0 = 0x06;        // 1msec
}
//--------- system_Initialize routine ------------------------------------------
void system_initialize(void){
  cli();          // Global interrup Disable
  port_init();
  timer0_init();
  sei();          // Global Interrup Enable
}
//------------------------------------------------------------------------------
void display(void){
unsigned char i;
unsigned int red_buf;
unsigned int green_buf;
  bright_on;
  if(reset_count==0){
    reset_on;
    reset_count=1;
    reset_off;
    data_count=0;
  }
  red_buf=led_red[data_count+cursor];
  green_buf=led_green[data_count+cursor];
  for(i=0; i<16; i++){
    if(red_buf&0x8000){
      red_on;
    }
    else{
      red_off;
    }
    if(green_buf&0x8000){
      green_on;
    }
    else{
      green_off;
    }
    clock_on;
    clock_off;
    red_buf<<=1;
    green_buf<<=1;
  }
  data_count++;
  if(data_count>=16){
    data_count=0;
    reset_count=0;
  }
  bright_off;
}
//--------- mian program routine -----------------------------------------------
int main(void)
{
  system_initialize();
  while(1){
 
  }
}

 

 

동작영상ㅋ

 

ㅋ.ㅋ