|
【跪求】现有程序已经可以接收到两片74LS165的数据;只求能显示出数据中高电平数量只和;显示在数码管上即可【源程序及仿真图纸已上传】
#include<reg51.h>
#include<intrins.h>
/**************************************************
** Marcos define
**************************************************/
#define uint unsigned int
#define uchar unsigned char
#define MotorTabNum 5
//IO设置
sbit QH = P3^0; //输出端
sbit CLK74 = P3^1; //时钟输入端(上升沿有效)
sbit SPL = P3^2; //移位控制/置入控制(低电平有效)
//数码管
sbit SMG1 = P2^0; //数码管第一位定义
sbit SMG2 = P2^1; //数码管第二位定义
sbit SMG3 = P2^2; //数码管第三位定义
sbit SMG4 = P2^3; //数码管第四位定义
signed char temp = 0;
int table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //共阴极数码管段值
void Display(void);
void delayms(xms);
void mDelay(unsigned int DelayTime); //延时函数
/***************************************************
* Function Name : read_int165
* Description : 接收数据
* Input : None
* Output : None
* Return : None
****************************************************/
uint read_int165(void)
{
uchar i = 0;
uint read_data = 0;
SPL = 0; //置数,读入并行输入口数据
_nop_();
SPL = 1; //移位,并口输入被封锁,串行转换开始
_nop_();
for(i=0;i<16;i++) //16位数据
{
read_data <<= 1;
if(QH)
{
read_data|=QH;
}
CLK74=0; //下降沿
_nop_();
CLK74=1; //上升沿
_nop_();
}
return read_data;
}
/************************************************
* Function Name : main
* Description : 主函数
* Input : None
* Output : None
* Return : None
*************************************************/
void main()
{
unsigned char i;
//初始化值
uint temp = 0;
uchar tempH = 0;
uchar tempL = 0;
CLK74=0;
while(1)
{
temp = read_int165();
tempH = (uchar) (temp>>8);//获取高8位,存放置tempH
tempL = (uchar) temp; //获取低8位,存放置tempL
for(i=0; i<10; i++)
Display();
}
}
/***********************************************
* Description : 数码管显示
* Input : None
* Output : None
* Return : None
************************************************/
void Display(void)
{
unsigned char B1,B2,B3,B4; //定义数码管的每一位
B1=temp/1000; //取g_MotorNum的千位
B2=temp%1000/1000; //取g_MotorNum的百位
B3=temp%100/10; //取g_MotorNum的十位
B4=temp%10; //取g_MotorNum的个位
//显示千位
P0=table[B1];
SMG1=0;
delayms(3);
SMG1=1;
//显示百位
P0=table[B2];
SMG2=0;
delayms(3);
SMG2=1;
//显示十位
P0=table[B3];
SMG3=0;
delayms(3);
SMG3=1;
//显示个位
P0=table[B4];
SMG4=0;
delayms(3);
SMG4=1;
}
/************************************************
* Function Name : delayms
* Description : 延时函数
* Input : None
* Output : None
* Return : None
**************************************************/
void delayms(xms)
{
unsigned int x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
}
/***************************************************
** End Of File
***************************************************/
|
|