Atmega128로 도트 매트릭스 숫자 표현(slide)
저번 포스트에서 숫자를 매 일정 시간마다 바꾸는게 아닌 연결되어 흐르도록 설계
1) 회로도
2) 코드
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][8]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=1;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
int show[8][8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<7 ; i++){
show[i][0] = show[i+1][0];
}
show[7][0]=num[sector][flag][0];
flag++;
if(flag == 8){
sector++;
flag=0;
}
}
}
if(sector == 10) sector=0;
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
show[i][j]=num[pattern][i][j];
}
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
slideDisplay(pattern);
}
}
* 원래의도는 오른쪽에서 왼쪽으로 흐르도록 하려 했으나 아래에서 위로 흐르기에 수정이 필요하다.
+)수정
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][8]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=0;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
//int show[16][8];
int show[8][8];//완료
int buffer[8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
//완료
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<8 ; i++){//완료
show[i][0] = show[i][0]>>1;
}
flag++;
if(flag == 8){
sector++;
setDisplay(sector);
//sector++;
flag=0;
}
}
}
if(sector == 10){
sector=0;
setDisplay(sector);
}
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){//완료
for(int j=0;j<8;j++){
show[i][j]=num[pattern][i][j];
}
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
//pattern = ++pattern % numPattern;
//setDisplay(pattern);
slideDisplay(pattern);
}
}
1) 회로도
2) 코드
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][8]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=1;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
int show[8][8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<7 ; i++){
show[i][0] = show[i+1][0];
}
show[7][0]=num[sector][flag][0];
flag++;
if(flag == 8){
sector++;
flag=0;
}
}
}
if(sector == 10) sector=0;
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
show[i][j]=num[pattern][i][j];
}
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
slideDisplay(pattern);
}
}
* 원래의도는 오른쪽에서 왼쪽으로 흐르도록 하려 했으나 아래에서 위로 흐르기에 수정이 필요하다.
+)수정
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][8]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=0;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
//int show[16][8];
int show[8][8];//완료
int buffer[8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
//완료
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<8 ; i++){//완료
show[i][0] = show[i][0]>>1;
}
flag++;
if(flag == 8){
sector++;
setDisplay(sector);
//sector++;
flag=0;
}
}
}
if(sector == 10){
sector=0;
setDisplay(sector);
}
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){//완료
for(int j=0;j<8;j++){
show[i][j]=num[pattern][i][j];
}
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
//pattern = ++pattern % numPattern;
//setDisplay(pattern);
slideDisplay(pattern);
}
}
--오른쪽에서 왼쪽으로 흐르는것은 완료했으나 매끄럽지 않아 아직 수정이 필요함
++)최종 수정
-- 오른쪽 끝에서 부터 차례대로 없어지도록 수정 완료
1) 회로
2) 코드
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][2]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=0;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
long int show[8][2];
//int show[8][8];//완료
int buffer[8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
//최종 완료
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<8 ; i++){//완료
show[i][0] = show[i][0]>>1;
}
flag++;
if(flag == 16){
sector++;
setDisplay(sector);
//sector++;
flag=0;
}
}
}
if(sector == 10){
sector=0;
setDisplay(sector);
}
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){//최종 완료
for(int j=0;j<2;j++){
show[i][j]=num[pattern][i][j];
}
}
for(int i=0;i<8;i++){//완료
show[i][0]=show[i][0]<<8;
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
//pattern = ++pattern % numPattern;
//setDisplay(pattern);
slideDisplay(pattern);
}
}
++)최종 수정
-- 오른쪽 끝에서 부터 차례대로 없어지도록 수정 완료
1) 회로
2) 코드
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int num[10][8][2]={
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x24,0xf7},{0x24,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x10,0xfe},{0x18,0xfd},{0x14,0xfb},{0x10,0xf7},{0x10,0xef},{0x10,0xdf},{0x10,0xbf},{0x3c,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x20,0xf7},{0x10,0xef},{0x08,0xdf},{0x04,0xbf},{0x3c,0x7f}},
{{0x1c,0xfe},{0x22,0xfd},{0x20,0xfb},{0x10,0xf7},{0x10,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x20,0xfe},{0x30,0xfd},{0x28,0xfb},{0x24,0xf7},{0x22,0xef},{0xfe,0xdf},{0x20,0xbf},{0x20,0x7f}},
{{0x3e,0xfe},{0x02,0xfd},{0x02,0xfb},{0x1e,0xf7},{0x20,0xef},{0x20,0xdf},{0x22,0xbf},{0x1c,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x04,0xfb},{0x04,0xf7},{0x1c,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x3e,0xfe},{0x20,0xfd},{0x20,0xfb},{0x10,0xf7},{0x08,0xef},{0x08,0xdf},{0x08,0xbf},{0x08,0x7f}},
{{0x00,0xfe},{0x18,0xfd},{0x24,0xfb},{0x24,0xf7},{0x18,0xef},{0x24,0xdf},{0x24,0xbf},{0x18,0x7f}},
{{0x18,0xfe},{0x24,0xfd},{0x24,0xfb},{0x38,0xf7},{0x20,0xef},{0x20,0xdf},{0x24,0xbf},{0x18,0x7f}}
};
int count=0,flag=0,sector=0;
int pattern=0,numPattern=10;
volatile unsigned long timer0 = 0;
long int show[8][2];
//int show[8][8];//완료
int buffer[8];
ISR(TIMER0_OVF_vect){
timer0++;//0.016마다 발생, 0.016384
//최종 완료
if(timer0 % 1 == 0){//1.04초 //18.3105로 할시 0.3초
count++;
if(count == 8){
count=0;
for(int i =0; i<8 ; i++){//완료
show[i][0] = show[i][0]>>1;
}
flag++;
if(flag == 16){
sector++;
setDisplay(sector);
//sector++;
flag=0;
}
}
}
if(sector == 10){
sector=0;
setDisplay(sector);
}
}
void setDisplay(int pattern){
for(int i=0;i<8;i++){//최종 완료
for(int j=0;j<2;j++){
show[i][j]=num[pattern][i][j];
}
}
for(int i=0;i<8;i++){//완료
show[i][0]=show[i][0]<<8;
}
}
void slideDisplay(int pattern){
for(int j=0;j<8;j++){
PORTF=show[j][1];
PORTE=show[j][0];
_delay_ms(1);
}
}
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
setDisplay(pattern);//show에 numPattern[0][][]저장
while(1){
//pattern = ++pattern % numPattern;
//setDisplay(pattern);
slideDisplay(pattern);
}
}
댓글
댓글 쓰기