微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR128的程序——数码管时钟显示

AVR128的程序——数码管时钟显示

时间:11-22 来源:互联网 点击:
#include

#include

#define uchar unsigned char

#define uintunsigned int

void timer1_init(void);

void display1(uchar FirstBit,uchar Num);

void display2(uchar FirstBit,uchar Num);

void display3(uchar FirstBit,uchar Num);

void display4(uchar FirstBit,uchar Num);

void Delayms(uint MS);

uchar TempData1[8];

uchar TempData2[8];

uchar TempData3[8];

uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,

0x92,0x82,0xf8,0x80,0x90,0xff};

uchar temp=0x01;

uint num=0,fen=19,shi=20;

void main(void)

{

uchar i,temp;

DDRA=0XFF;

PORTA=0XFF;

DDRC=0XFF;

PORTC=0XFF;

DDRF|=0X0E;

PORTF|=0X0E;

PORTF&=0xF7;

DDRB |=0X10;

PORTB|=0X10;

timer1_init();

SEI();

while(1)

{

TempData1[1] = led_discode[num];

TempData1[0] = led_discode[num/10];

TempData2[1] = led_discode[fen];

TempData2[0] = led_discode[fen/10];

TempData3[1] = led_discode[shi];

TempData3[0] = led_discode[shi/10];

display1(6,2);

display2(3,2);

display3(0,2);

display4(2,1);

display4(5,1);

}

}

void timer1_init(void)

{

TCNT1H = 0xE1;

TCNT1L = 0x7C;

TCCR1A = 0x00;

TCCR1B = 0x05;

TIMSK = 0x04;

}

#pragma interrupt_handler timer1_ovf_isr:15

void timer1_ovf_isr(void)

{

TCNT1H = 0xE1;

TCNT1L = 0x7C;

num++;

if(num==60)

{

num=0;

fen++;

if(fen==60)

{

fen=0;

shi++;

if(shi==24)

{

shi=0;

}

}

}

}

void display1(uchar FirstBit,uchar Num)

{

unsigned char i;

for(i=0;i

{

PORTC=led_discode[10];

PORTA=WeiMa[i+FirstBit];

PORTC=TempData1[i];

Delayms(2);

}

}

void display2(uchar FirstBit,uchar Num)

{

unsigned char i;

for(i=0;i

{

PORTC=led_discode[10];

PORTA=WeiMa[i+FirstBit];

PORTC=TempData2[i];

Delayms(2);

}

}

void display3(uchar FirstBit,uchar Num)

{

unsigned char i;

for(i=0;i

{

PORTC=led_discode[10];

PORTA=WeiMa[i+FirstBit];

PORTC=TempData3[i];

Delayms(2);

}

}

void display4(uchar FirstBit,uchar Num)

{

unsigned char i;

for(i=0;i

{

PORTC=led_discode[10];

PORTA=WeiMa[i+FirstBit];

PORTC=0XBF;

Delayms(2);

}

}

void Delayms(uint MS)

{

uint i,j;

for( i=0;i

for(j=0;j<1141;j++);

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top