#include <mega128.h>
#include <io.h>
#include <interrupt.h>
#include <stdio.h>
int D_time=1;
int SS_data[10]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
int SS_PORTC[5]={0, 0x01, 0x02, 0x04, 0x08};
int what=3232;
int where[4]={0,0,0,0};
void init_port(void)
{
PORTA = 0x00;
DDRA = 0xff;
PORTB = 0x00;
DDRB = 0xff;
PORTC = 0x00;
DDRC = 0xff;
PORTD = 0x00;
DDRD = 0xff;
PORTE = 0x00;
DDRE = 0xff;
PORTF = 0x00;
DDRF = 0xff;
PORTG = 0x00;
DDRG = 0xff;
}
void init_devices(void)
{
TIMSK = 0x41; //타이머0,2 오버플로우 사용
sei(); //re-enable interrupts
}
void delay(int times)
{
int i,j;
for (i=0; i<times; i++) {
for (j=0;j<i;j++);
}
}
void SS_val(int PC, int PA, int D_time)
{
PORTC = ~PC;
PORTA = PA;
delay(D_time);
}
//
void main(void)
{
where[3] = what/1000;
where[2] = (what - where[3]*1000)/100;
where[1] = (what - where[3]*1000 - where[2]*100)/10;
where[0] = (what - where[3]*1000 - where[2]*100 - where[1]*10);
/*------------------------------------------------------------------*/
init_devices();
init_port();
//insert your functional code here...
while(1) {
SS_val(SS_PORTC[1], SS_data[where[3]], D_time);
SS_val(SS_PORTC[2], SS_data[where[2]], D_time);
SS_val(SS_PORTC[3], SS_data[where[1]], D_time);
SS_val(SS_PORTC[4], SS_data[where[0]], D_time);
}
}
'프로그래밍 > AVR Atmega' 카테고리의 다른 글
Atmega 온도센서 및 세그먼트 표시 (0) | 2017.10.19 |
---|---|
NTSF4 써미스터 온도센서 (0) | 2017.10.19 |
atmega128 인터럽트 (0) | 2017.10.19 |