51程序
仿真成功,4位数码正常显示
#include <regx52.h>
#include<intrins.h>
sbit SH_CP=P2^0;
sbit DS=P2^1;
sbit ST_CP=P2^2;
sbit SHU1=P2^3;
sbit SHU2=P2^4 ;
sbit SHU3=P2^5;
sbit SHU4=P2^6;
int tab[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void delay()
{
int i,j;
for(i=0;i<50;i++)
for(j=0;j<10;j++);
}
void Ser_IN(unsigned char Data)
{
unsigned char i;
for(i = 0; i < 8; i++)
{
SH_CP = 0;
DS = Data & 0x80;
Data <<= 1;
SH_CP = 1;
}
}
void Par_OUT(void)
{
ST_CP = 0;
;
ST_CP = 1;
}
void ShuMa(int BianMa)
{
int i=0;
SHU4=1;
i=BianMa/1000;
SHU1=0;
Ser_IN(tab[i]);
Par_OUT();
delay();
SHU1=1;
i=BianMa/100%10;
SHU2=0;
Ser_IN(tab[i]);
Par_OUT();
delay();
SHU2=1;
i=BianMa/10%10;
SHU3=0;
Ser_IN(tab[i]);
Par_OUT();
delay();
SHU3=1 ;
i=BianMa%10;
SHU4=0;
Ser_IN(tab[i]);
Par_OUT();
delay();
}
main()
{
int k;
k=4192 ;
while(1)
{
ShuMa(k);
}
}
AVR162的程序,可以显示但是乱码。
#include <avr/io.h>
#include <stdio.h>
int SH_CP=0,DS=1,ST_CP=2,shu1=3,shu2=4,shu3=5,shu4=6;
int tab[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void fc0(int a)
{
PORTC&=~(1<<a);
}
void fc1(int b)
{
PORTC|=(1<<b);
}
void delay()
{
int i,j,k;
for(k=0;k<1000;k++)
for(i=0;i<280;i++)
for(j=0;j<100;j++);
}
void Ser_IN(unsigned char Data)
{
int i;
unsigned char j;
for(i = 0; i < 8; i++)
{
fc0(SH_CP);
j=Data&0x80;
if(j==0x00)
fc0(DS);
else
fc1(DS);
Data<<=1;
fc1(SH_CP);
}
}
void Par_OUT(void)
{
fc0(ST_CP);
;
fc1(ST_CP);
}
void ShuMa(int BianMa)
{
int i=0;
fc1(shu1);
fc1(shu4);
fc1(shu2);
fc1(shu3);
i=BianMa/1000;
fc0(shu1);
Ser_IN(tab[i]);
Par_OUT();
delay();
fc1(shu1);
fc1(shu3);
fc1(shu4);
i=BianMa/100%10;
fc0(shu2);
Ser_IN(tab[i]);
Par_OUT();
delay();
fc1(shu2);
fc1(shu1);
fc1(shu4);
i=BianMa/10%10;
fc0(shu3);
Ser_IN(tab[i]);
Par_OUT();
delay();
fc1(shu3);
fc1(shu1);
fc1(shu2);
i=BianMa%10;
fc0(shu4);
Ser_IN(tab[i]);
Par_OUT();
delay();
}
main()
{
DDRC=0xff;
int k=5132;
PORTC=0xff;
while(1)
{
ShuMa(k);
}
}
因为仿真
电路上肯定没问题
还有特意问如果不加晶振protues的 设置的是多少hz
一周热门 更多>