在8051單片機應(yīng)用系統(tǒng)中,可以利用串行接口來擴展并行i/o口(假定串行口工作在移位寄存器、方式0的狀態(tài)下)。串行移位輸出接輸出移位寄存器74ls164可擴展一個8位并行輸出口,用以連接一個led數(shù)碼管作靜態(tài)顯示。
如圖所示。由6個共陽極led數(shù)碼管,編程使其顯示200304。
c51軟件設(shè)計:
# include <stdio.h> //預(yù)處理
# include <reg51.h>
unsigned char code ledcode[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88}; //字型編碼
unsigned char code buf[6]={0x2,0x00,0x00,0x03,0x00,0x04}; //200304
void main(void) //主函數(shù)
{
unsigned char idata i,k;
scon=0x00; //串行口初始化
es=0;
ea=0; //關(guān)閉中斷
for(i=0;i<6;i++)
{
ti=0;
k=buf[i];
k=ledcode[k];
sbuf=k;
while(ti==0);
}
while(1);
}