数码管动态显示C语言程序

发布网友 发布时间:2022-04-22 00:49

我来回答

3个回答

热心网友 时间:2022-07-08 03:28

记得给分哦!
我这个程序是在ICCVC FOR AVR 那个编译器里编译成功的
//ICC-AVR application builder : 2010-3-15 11:14:29
// Target : M8
// Crystal: 4.0000Mhz

#include <iom8v.h>
#include <macros.h>

unsigned char const seg_table[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

void port_init(void)
{
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

/* 微秒级延时程序 */
void delay_us(int time)
{
do
{
time--;
} while (time>1);
}
/* 毫秒级延时程序 */
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(1000);
time--;
}
}

void main()
{
unsigned char i;
init_devices();
while (1)
{
for (i=0;i<10;i++)
{
PORTB=seg_table[i];
delay_ms(100);
}
}
}

热心网友 时间:2022-07-08 03:29

void CMyClockDlg::DrawSingleNumber(int nNum, int nLeft)
{
switch (nNum)
{
case 0:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
break;
case 1:
DrawSection2(nLeft);
DrawSection3(nLeft);
break;
case 2:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection7(nLeft);
break;
case 3:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection7(nLeft);
break;
case 4:
DrawSection2(nLeft);
DrawSection3(nLeft);

DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 5:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 6:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 7:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
break;
case 8:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 9:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection2(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
default;
}
}
}
void CMyClockDlg::DrawSection1(int nLeft)
{
if (m_memDC.m_hDC!=NULL)

{

CPoint point[4];

point[0].x=nLeft+(int)(0.1*m_nWidth);

point[0].y=m_nYmargin;

point[1].x=nLeft+(int)(0.9*m_nWidth);

point[1].y=m_nYmargin;

point[2].x=nLeft+(int)(0.7*m_nWidth);

point[2].y=(int)(0.2*m_nWidth)+m_nYmargin;

point[3].x=nLeft+(int)(0.3*m_nWidth);

point[3].y=(int)(0.2*m_nWidth)+m_nYmargin;

CBrush br(m_crText);

CRgn rgn;

rgn.CreatePolygonRgn(point,4,ALTERNATE);

m_memDC.FillRgn(&rgn,&br);

br.DeleteObject();

rgn.DeleteObject();

m_memDC.MoveTo(point[0]);

m_memDC.LineTo(point[1]);

m_memDC.MoveTo(point[1]);

m_memDC.LineTo(point[2]);

m_memDC.MoveTo(point[2]);

m_memDC.LineTo(point[3]);

m_memDC.MoveTo(point[3]);

m_memDC.LineTo(point[0]);
}
}
void CMyClockDlg::Draw2Dot(int nLeft)
{
if (m_memDC.m_hDC!=NULL)

{

CBrush br(m_crText);

CRect rect;

rect.SetRect(nLeft+(int)(0.3*m_nWidth),(int)(0.4*m_nWidth)+m_nYmargin,nLeft+(int)(0.6*m_nWidth),(int)(0.7*m_nWidth)+m_nYmargin);

m_memDC.Ellipse(rect);

CRgn rgn1;

rgn1.CreateEllipticRgn(rect.left,rect.top,rect.right,rect.bottom);

m_memDC.FillRgn(&rgn1,&br);

rect.OffsetRect(0,(int)(0.8*m_nWidth)+m_nYmargin);

m_memDC.Ellipse(rect);

CRgn rgn2;

rgn2.CreateEllipticRgn(rect.left,rect.top,rect.right,rect.bottom);

m_memDC.FillRgn(&rgn2,&br);

br.DeleteObject();

rgn1.DeleteObject();

rgn2.DeleteObject();

}

热心网友 时间:2022-07-08 03:29

不知道是单片机还是FPGA

int a[100][2] //int to bcd
byte b[10]={...,...,...,....};bcd to 数码,视共阴共阳而定
int ge,shi;
ge=0;
shi = 0;
//初始化a
for(int i = 0; i < 100; i++)// int to bcd
{
a[i][1]=shi;
a[i][0]=ge;
ge++
if(ge >= 9)
{
ge = 0;
shi++;
}
}

int j = 0;
while(时钟触发)
{
shi = a[j][1];
ge = a[j][0];
74(1)的信号线 = b[shi]; //十位译码
74(2)的信号线 = b[ge]; //个位译码
j++; //或者说时钟在这儿触发
if(j>99)
{
j=0;
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com