專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

51單片機(jī)+74HC595驅(qū)動(dòng)數(shù)碼管程序

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年08月07日   【字體:
這里是電路圖:

完整的源碼和圖紙下載地址: http://www.torrancerestoration.com/bbs/dpj-20392-1.html
下面是51單片機(jī)驅(qū)動(dòng)74hc595芯片的程序:     
#include <reg52.h>                           //包含51單片機(jī)的頭文件
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char

//sbit sin_595    =P1^0;
//sbit rclk_595   =P1^1;
//sbit sclk_595   =P1^2;
//sbit s_clr      =P1^3;
sbit  a_cp_595   =P2^4;      //串行移位時(shí)鐘脈沖  sh_cp_595
sbit  b_cp_595   =P2^3;      //輸出鎖存器控制脈沖 st_cp_595
//sbit  _oe_595    =P1^5;      //8位并行輸出使能/禁止(高阻態(tài))
sbit  ds_595    =P2^2;      //串行數(shù)據(jù)輸入
extern uchar  datas[6];    //存放6個(gè)數(shù)碼管的顯示數(shù)字
 
uchar  ledcode[]={
 0xC0,  // 0
 0xF9,  // 1
 0xA4,  // 2
 0xB0,  // 3
 0x99,  // 4
 0x92,  // 5
 0x82,  // 6
 0xF8,  // 7
 0x80,  // 8
 0x90,  // 9
 0x88,  // A
 0x83,  // B
 0xC6,  // C
 0xA1,  // D
 0x86,  // E
 0x8E  // F
};
 
void delay(uint z)
{
 uint t1,y;
 for(t1=z;t1>0;t1--)
  for(y=110;y>0;y--);
}
 
void led_display(void)

   uchar i,j;
   bit testb;
   uchar bdata movebit[6];
   uchar bdata test;
    //_oe_595=0;                         //選中數(shù)碼管
   for(i=0;i<6;i++)
   movebit[i]=ledcode[datas[i]];
  // P1=0;
   delay(1);
   for(i=0;i<6;i++)                         //數(shù)據(jù)移位
   {
   test=movebit[i];
   for(j=0;j<8;j++)
   {
   testb=test&0x80;
   test=test<<1;
   if(testb)
   {
    ds_595=1;
   }
   else
   {
 ds_595=0;
   }
 a_cp_595=1;
   a_cp_595=0;
   }                                //數(shù)據(jù)移位 
   }
   b_cp_595=0;
   b_cp_595=1;
   b_cp_595=0;
       
}

 
 
關(guān)閉窗口

相關(guān)文章