您的位置 首页 开关

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

includeiom128vh>includemacrosh>defineucharunsignedchardefineuintunsignedintvoidtimer1_init(voi

#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++);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/dianyuan/kaiguan/262318.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部