//主函数
#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#include"encoder.h"
#include"74hc595"
main()
{
DDRA=0XFF;
PORTA=0XEF;
while()
{
uchar a,b,c=0x00;
PORTA|=BIT(4);
for(a=0;a<=9;a++)
{
sendbyte(a);
for(b=0;b<2000;b++)
{
PORTA&=~c;
c=c+0x20;
delay(7);
PORTA|=0xe0;
}
}
}
}
//子函数1
void delay(uchar ms)
{
for(;ms>0;ms--)
for(t=0;t<1141;t++);
}
void sendbyte(uchar byte)
{
uint i,tem;
byte=encoder(byte);
for(i=0;i<8;i++)
{
PORTA&=~BIT(1);
tem=byte&0x80;
if(tem==0)
{
PORTA&=~BIT(3);
}
else
PORTA|=BIT(3);
byte=byte<<1;
PORTA|=BIT(1);
}
PORTA&=~BIT(2);
PORTA|=BIT(2);
}
//子函数2
uchar encoder(uchar num)
{
uchar code;
switch(num)
{
case 0x00:
code=0xc0;break;
case 0x01:
code=0xf9;break;
case 0x02:
code=0xa4;break;
case 0x03:
code=0xb0;break;
case 0x04:
code=0x99;break;
case 0x05:
code=0x92;break;
case 0x06:
code=0x82;break;
case 0x07:
code=0xf8;break;
case 0x08:
code=0x80;break;
case 0x09:
code=0x90;break;
}
return(code);
}
后面这两个函数如何以库函数的形式被主函数调用?
请教~~~~ |