#define uchar unsigned char
#define uint unsigned int
#include<iom16v.h>
#include"74hc595.h"
#pragma data:code //共阳数码管码表
const table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void main(void)
{
uchar aa,cc=0x0;
uint bb;
DDRA=0xff; //初始化端口A
PORTA=0xef;
while(1)
{
PORTA|=(1<<7); //74ls138使能
for(aa=0;aa<=16;aa++) //循环发送0-f的数字
{
in_595(table[aa]);
out_595();
//向74hc595写入数据
for(bb=0;bb<1600;bb++) //每个数字扫描2000次,每个数码管200次
{
PORTA&=~cc; //74hc138依次输出
cc=cc+0x01; //这里可能不好理解,138的ABC在A口的567位,每加0x20就是进一位,加到溢出就回到000;
delay(15);
PORTA|=0xe0;
}
}
}
}
|