Добавил:
Andrejjavd
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Примеры решения лабораторных работ / Лаба3Таймер
.txt#include <iom8535v.h>
#include <macros.h>
void port_init(void)
{
DDRC=0xFF;
PORTD = 0x0f;
DDRD = 0xFF;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void Delay(int i)
{
unsigned int p;
for (p=0;p<i;p++)
{
int tiks=1000;
while (tiks>0)
tiks--;
}
}
void main(void)
{
//int t[10]={0xF6,0xFE,0xE0,0xBE,0xB6,0x66,0xF2,0xDA,0x60,0xFC}; //massiv obratnogo otscheta
int t[10]={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
int i=0;
int j=9;
int g=9;
int h=9;
int aqum=0;
int aqum2=0;
int aqum3=0;
init_devices();
while (1)
{
if (i>8)
{
aqum=1;
i=0;
}
else i++;
Delay(5);
//hg1
if (aqum==1)
{
PORTC=t[j];
PORTD=0x01;
if (j>8)
{
j=0;
aqum2=1;
}
else j++;
aqum=0;
}
else
{
PORTC=t[j];
PORTD=0x01;
}
Delay(5);
//hg2
if (aqum2==1)
{
PORTC=t[g];
PORTD=0x02;
if (g>8)
{
aqum3=1;
g=0;
}
else g++;
aqum2=0;
}
else
{
PORTC=t[g];
PORTD=0x02;
aqum2=0;
}
Delay(5);
//hg3
if (aqum3==1)
{
PORTC=t[h];
PORTD=0x04;
if (h>8)
{
h=0;
}
else h++;
aqum3=0;
}
else
{
PORTC=t[h];
PORTD=0x04;
aqum3=0;
}
}
}