|
/***************************************
*********74LS138譯碼器應(yīng)用******************
*****************************************/
#include "reg51.h" //此文件中定義了單片機(jī)的一些特殊功能寄存器
#include "intrins.h"
typedef unsigned int u16; //對(duì)數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
/*************************************
********* 延時(shí)子函數(shù) *************
**************************************/
void delayms(u16 ms)
{
u8 i;
while(ms--)
{
for(i=0; i<120; i++);
}
}
/*******************************************************
***********************************************************/
void main()
{
P1=0xff;
while(1)
{
P1=(P1+1)%16; //低4位在0~15取值,使154譯碼器輸入4位為0000~1111
delayms(500); //經(jīng)譯碼器輸出0~15中對(duì)應(yīng)引腳輸出0,
}
}
|
|