- 静态显示
#include <STC15F2K60S2.H>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
void Delay1s();
uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
uchar wei[]={0x01,0x02,0x40,0x80,0x10,0x20,0x40,0x80};
sbit beer=P0^6;
void main()
{
uint i;
P2=0xa0;beer=0;P2=0X00;
P2=0xc0;P0=0XFF;P2=0X00;
P2=0XF0;P0=0XFF;
while(1)
{
for(i=0;i<10;i++)
{
P0=table[i];
Delay1s();
}
}
}
void Delay1s()
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 43;
j = 6;
k = 203;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
- 动态显示
#include <STC15F2K60S2.H>
#include<intrins.h>
void delay_ms(int n);
void display_num(unsigned char w,unsigned char n);
unsigned char which[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char num[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay_ms(int n)
{
int i,j;
for(i=n;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
int j;
while(1)
{
for(j=0;j<9;j++)
{
display_num(j,j);
}
}
}
void display_num(unsigned char w,unsigned char n)
{
P2 = (P2&0x1f)|0xc0;
P0 = which[w-1];
P2 = (P2&0x1f)|0xe0;
P0 = num[n];
delay_ms(5);
P0 = 0xFF;
P2 &= 0x1f;
}