單片機(jī)--數(shù)碼管顯示模塊(C51)
#include < reg52.h >
#define uchar unsigned char
#defind uintunsigned int
sbit seg_oe=P1^3;//數(shù)碼管顯示使能端,低電平有效
sbit duanxuan=P1^4;//數(shù)碼管的段選端
sbit weixuan=P1^5;//數(shù)碼管的位選端
uchar code smg_duan[30]={//數(shù)碼管段選碼表,我們的數(shù)碼管是共陰極數(shù)碼管
0x3F,0x06,0x5B,0x4F,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71, }; //這是共陰極數(shù)碼管0-E的顯示碼表
uchar code smg_wei[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//選擇亮哪一個(gè)數(shù)碼管,也就是數(shù)碼管的位選信號(hào)
void seg_disp(uchar wei,uchar duan)//單個(gè)數(shù)碼管的顯示
{
weixuan=1;
P0=smg_wei[wei];
weixuan=0;
duanxuan=1;
P0=smg_duan[duan];
duanxuan=0;
seg_oe=0;
delay10ms();?
seg_oe=1;
}
void delay10ms() //延時(shí)子程序
{
uchari,j;
for(i=1;i<40;i++)
for(j=1;j<40;j--);
}
評(píng)論