假設P0 P2口接數碼管 程式如下
include
#define uchar unsigned char
#define uint unsigned int
uchar num=0;
//共陰數碼管七段碼
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延時程式
{
uint j;
for(;i>0;i--)
for(j=0;j
{;}
}
void main(void )//主程式
while(1)
delay_ms(1000);
num++;
if(num==100)num=0;
P0=table[num/10];
P2=table[num%10];
假設P0 P2口接數碼管 程式如下
include
#define uchar unsigned char
#define uint unsigned int
uchar num=0;
//共陰數碼管七段碼
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延時程式
{
uint j;
for(;i>0;i--)
{
for(j=0;j
{;}
}
}
void main(void )//主程式
{
while(1)
{
delay_ms(1000);
num++;
if(num==100)num=0;
P0=table[num/10];
P2=table[num%10];