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

試驗(yàn)數(shù)碼管上顯示數(shù)字( 單片機(jī)直接實(shí)現(xiàn)位選 共陰極)

作者:玉另符   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年12月03日   【字體:


 

/**********************************************************************************
*  標(biāo)題:                  試驗(yàn)數(shù)碼管上顯示數(shù)字( 單片機(jī)直接實(shí)現(xiàn)位選 共陰極)        *
*      *
*  連接方法:P0與J12 用8PIN排線連接 P1與JP16 用排線連接    *
***********************************************************************************
*                                        *
* 用573鎖存器控制和單片機(jī)腳直接位選控制(非譯碼器控制)數(shù)碼管 *
***********************************************************************************/
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
unsigned int code dbit[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};   
unsigned int code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
void main()
{
while(1)
{
P1=dbit[4];
P0=num[9];
}
}


位定義

#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
while(1)
{
LSA=0;
LSB=0;
LSC=0;
P0=num[6];
delay(2);
LSA=1;
LSB=0;
LSC=0;
P0=num[6];
delay(2);
}
}

 


//讓八個(gè)數(shù)碼管全部亮并且從0~9循環(huán)

#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段選,選擇要顯示的數(shù)字
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//八位數(shù)碼管   
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}

關(guān)閉窗口

相關(guān)文章