Atmega128로 도트 매트릭스 숫자 표현

1초마다 0~9까지의 숫자를 차례대로 표현

1) 디자인

2) 코드
#define F_CPU 16000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

int num0[8][8]={{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},
{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}};
int num1[8][8]={{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},
{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}};
int num2[8][8]={{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},
{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}};
int num3[8][8]={{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},
{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}};
int num4[8][8]={{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},
{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}};
int num5[8][8]={{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},
{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}};
int num6[8][8]={{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},
{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}};
int num7[8][8]={{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},
{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}};
int num8[8][8]={{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},
{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}};
int num9[8][8]={{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},
{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}};

int count=0,flag=0;
volatile unsigned  long timer0 = 0;

ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
if(timer0 % 65 == 0){//1.04초
count++;
if(count % 2 == 0){
flag++;
count=0;
}
}
if(flag % 10==0) flag=0;
}

void display(){
switch(flag){
case 0:
for(int i=0;i<8;i++){
PORTF=num0[i][1];
PORTE=num0[i][0];
_delay_ms(1);
}
break;
case 1:
for(int i=0;i<8;i++){
PORTF=num1[i][1];
PORTE=num1[i][0];
_delay_ms(1);
}
break;
case 2:
for(int i=0;i<8;i++){
PORTF=num2[i][1];
PORTE=num2[i][0];
_delay_ms(1);
}
break;
case 3:
for(int i=0;i<8;i++){
PORTF=num3[i][1];
PORTE=num3[i][0];
_delay_ms(1);
}
break;
case 4:
for(int i=0;i<8;i++){
PORTF=num4[i][1];
PORTE=num4[i][0];
_delay_ms(1);
}
break;
case 5:
for(int i=0;i<8;i++){
PORTF=num5[i][1];
PORTE=num5[i][0];
_delay_ms(1);
}
break;
case 6:
for(int i=0;i<8;i++){
PORTF=num6[i][1];
PORTE=num6[i][0];
_delay_ms(1);
}
break;
case 7:
for(int i=0;i<8;i++){
PORTF=num7[i][1];
PORTE=num7[i][0];
_delay_ms(1);
}
break;
case 8:
for(int i=0;i<8;i++){
PORTF=num8[i][1];
PORTE=num8[i][0];
_delay_ms(1);
}
break;
case 9:
for(int i=0;i<8;i++){
PORTF=num9[i][1];
PORTE=num9[i][0];
_delay_ms(1);
}
break;
default:
break;
}
}

int main(void){
DDRE=0xff;
DDRF=0xff;

TCCR0 = 1<<CS02 | 1<<CS01 | 1<<CS00; // T=(1/16M) *250 * 1024분주 = 0.016초
TIMSK |= 1<<TOIE0;  // 타이머 카운터0 인터럽트 활성화 
sei();//set inturrept

while(1){
display();
}
}

댓글

이 블로그의 인기 게시물

python 에서 resize 이벤트 만들기

PLC와 아두이노 그리고 온도 센서를 이용하여 램프 점등

C언어로 로또 프로그램 만들기