这是数码管的电路
数码管的显示步骤:
1、通过138译码器来选择指定IC,要选择某一个数码管,然后显示数字
#include <STC15F2K60S2.H>
#include <Nixie.h>
unsigned char NixieNum[18]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void HC138_select(unsigned char channel)
{
switch(channel)
{
case 4:
P2 = (P2 & 0x1f) | 0x80;
break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;
break;
case 6:
P2 = (P2 & 0x1f) | 0xc0;
break;
case 7:
P2 = (P2 & 0x1f) | 0xe0;
break;
}
}
/*
function:选择指定数码管显示数字
@param:指定数码管,值为0-7
@param:显示数字、A-F、-、.
*/
void Nixie_SetNum(unsigned char pos, unsigned char num)
{
P0 = 0xff;
HC138_select(6);
P0 = 0x01 << pos;
HC138_select(7);
P0 = num;
}
void delay_(unsigned int t)
{
while(t--);
while(t--);
}
void main()
{
Nixie_SetNum(1, NixieNum[7]);
delay_(6000);
}
问题
如果在数码管显示函数后面不加延时函数,会产生微弱的红光,所以要加延时函数来消影,或者用其他方法来消影