|
|
如下的單片機程序,p3.4和p1.0分別輸出一串?dāng)?shù)據(jù),定義兩個函數(shù)void LED24show(long byteData)和void LED16show(int byteData)用于驅(qū)動數(shù)碼管和LED,當(dāng) 執(zhí)行 LED24show(0x7fffff); LED16show(0x0202);時數(shù)碼管應(yīng)當(dāng)顯示00,24個LED小燈應(yīng)當(dāng)只有一個亮,但是仿真的結(jié)果如下,沒有實現(xiàn)要求顯示的部分,請大神幫忙看一下。
#include<reg52.h>
#include <intrins.h>
typedef unsigned char uchar;
typedef unsigned char uint;
void delayms(unsigned int xms);
//****************************************74LS595端口定義
sbit SER1 = P3^4; //p3.4腳控制串行數(shù)據(jù)輸入
sbit SCK1 = P3^6; //串行輸入時鐘
sbit RCK1 = P3^5; //存儲寄存器時鐘
sbit SER2 = P1^0; //p1.0腳控制串行數(shù)據(jù)輸入
sbit SCK2 = P1^2; //串行輸入時鐘
sbit RCK2 = P1^1; //存儲寄存器時鐘
sbit key=P1^7;
sbit run=P0^0;
//*********************************************************************
void LED24show(long byteData)
{
char i=0;
for(i=0;i<24;i++)
{
SER1 = byteData<<23; //送出23位數(shù)據(jù)
byteData= byteData>>1;
SCK1 = 0; //上升沿,讓串行輸入時鐘變?yōu)楦唠娖剑⒀訒r2個時鐘周期
_nop_();
_nop_();
SCK1 = 1; //變?yōu)榈碗娖剑瑸橄麓螠?zhǔn)備
}
//位移寄存器數(shù)據(jù)準(zhǔn)備完畢,轉(zhuǎn)移到存儲寄存器
RCK1 = 0; //上升沿,讓存儲寄存器時鐘變?yōu)楦唠娖剑⒀訒r2個時鐘周期
_nop_();
_nop_();
RCK1 = 1;
}
void LED16show(int byteData)
{
char i =0;
for(i=0;i<16;i++)
{
SER2 = byteData>>15; //送出15位數(shù)據(jù)
byteData= byteData<<1;
SCK2 = 0; //上升沿,讓串行輸入時鐘變?yōu)楦唠娖剑⒀訒r2個時鐘周期
_nop_();
_nop_();
SCK2 = 1; //變?yōu)榈碗娖剑瑸橄麓螠?zhǔn)備
}
//位移寄存器數(shù)據(jù)準(zhǔn)備完畢,轉(zhuǎn)移到存儲寄存器
RCK2 = 0; //上升沿,讓存儲寄存器時鐘變?yōu)楦唠娖剑⒀訒r2個時鐘周期
_nop_();
_nop_();
RCK2 = 1;
}
void main()
{
while(1)
{
LED24show(0x7fffff);
delayms(100);
LED16show(0x0202);
}
}
void delayms(unsigned int xms) //延時函數(shù)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
|
|