微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 点阵调试(附程序)

点阵调试(附程序)

时间:11-28 来源:互联网 点击:



#include
#include

#define uchar unsigned char
#define uint unsigned int

//端口定义;

sbit DS = P1^0;
sbit OE = P1^1;
sbit ST_CP = P1^2;
sbit SH_CP= P1^3;
sbit MR = P1^4;
uchar time=0;
uchar flag=0;

uchar codetableHng[8]={0x00,0x00,0x7E,0x42,0x7E,0x00,0x00,0x00};
uchar codetable1[8]={0x00,0x00,0x20,0x7E,0x00,0x00,0x00,0x00};
uchar codetable2[8]={0x00,0x00,0x66,0x4A,0x72,0x00,0x00,0x00};
uchar codetable3[8]={0x00,0x24,0x42,0x52,0x2C,0x00,0x00,0x00};
uchar codetable4[8]={0x00,0x0C,0x14,0x7E,0x04,0x00,0x00,0x00};
uchar codetable5[8]={0x00,0x00,0x72,0x52,0x5C,0x00,0x00,0x00};
uchar codetable6[8]={0x00,0x3C,0x52,0x52,0x4C,0x00,0x00,0x00};
uchar codetable7[8]={0x00,0x00,0x40,0x5C,0x60,0x00,0x00,0x00};
uchar codetable8[8]={0x00,0x00,0x7E,0x52,0x7E,0x00,0x00,0x00};
uchar codetable9[8]={0x00,0x30,0x4A,0x4A,0x3C,0x00,0x00,0x00};

uchar codetableLie[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

void delayS(uchar ms)
{
uchar x,y;
for(x=ms;x--;x>0)
for(y=110;y>0;y--);
}

static void timer0_initialize(void)
{
EA=0;
TR0=0;
TMOD=TMOD&0xf0;
TMOD=TMOD|0x01;

TL0=(0X78);
TH0=(0X0C);
PT0=0;////
ET0=1;
TR0=1;
EA=1;
}

//函数声明;

void HC595_CD(uint Value); //595驱动函数;

void main()
{

uint i = 0;
//P2=tableLie[0];
//HC595_CD(tableHng[0]);
//uint Value;
//P2=0xfd;
//Value = 0x01;
//HC595_CD(Value);
timer0_initialize();
while(1)
{
if(flag==0)
{
for(i=0;i<8;i++)
{
HC595_CD(tableHng[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==1)
{
for(i=0;i<8;i++)
{
HC595_CD(table1[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==2)
{
for(i=0;i<8;i++)
{
HC595_CD(table2[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==3)
{
for(i=0;i<8;i++)
{
HC595_CD(table3[i]);
P2=tableLie[i];
delayS(3);
}
}


if(flag==4)
{
for(i=0;i<8;i++)
{
HC595_CD(table4[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==5)
{
for(i=0;i<8;i++)
{
HC595_CD(table5[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==6)
{
for(i=0;i<8;i++)
{
HC595_CD(table6[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==7)
{
for(i=0;i<8;i++)
{
HC595_CD(table7[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==8)
{
for(i=0;i<8;i++)
{
HC595_CD(table8[i]);
P2=tableLie[i];
delayS(3);
}
}

if(flag==9)
{
for(i=0;i<8;i++)
{
HC595_CD(table9[i]);
P2=tableLie[i];
delayS(3);
}
}

}

}
static void timer0_isr(void) interrupt 1 //定时器里避免放大的延时函数 以免发生错误
{
time++;
TR0=0;
TL0=(0X78);
TH0=(0X0C);
TR0=1;
if(time==50)
{
time=0;
flag++;
if(flag==10)
flag=0;
}

}

//74HC595驱动函数;
//功能:把输入的数据输出到对应的引脚上;
//输入函数:Value

void HC595_CD(uint Value)
{
uinti = 0 ;
OE = 1; //芯片输出关闭;
MR = 0; //IC复位;
MR = 1; //复位结束;
for(i = 0; i < 8; i++) //传送8位数据;
{
DS = Value&0x01; //并行数据转串行;
SH_CP = 0; //移位寄存器时钟为0;
ST_CP = 0; //存储寄存器时钟为0;
_nop_();
_nop_();
_nop_(); //短延时;
_nop_();
Value >>= 1; //数据移位;
SH_CP = 1; //产生移位脉冲;
ST_CP = 1;
}
OE= 0; //数据输出;
}

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

网站地图

Top