单片机程序

#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intuchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};//延时void DelayMS(uint x){uchar t;while(x--) for(t=0;t<120;t++);}//主程序void main(){uchar i=0;P0=0x00;while(1){P0=~DSY_CODE[i];i=(i+1)%10;DelayMS(300);}}主函数中的P0=~DSY_CODE[i];i=(i+1)%10;DelayMS(300);是什么意思?
2026年09月19日 21:47
有3个网友回答
网友(1):

P0=~DSY_CODE[i];
DSY_CODE[i]中定义的7段数码管的段码值,好像是共阳极的;你的硬件要使用共阴极的段码所以要取反送显;
i=(i+1)%10;
类似于:i++;完成查表变量的更新;
DelayMS(300);
延时,用于模拟人眼的视觉暂留便于观察数字显示

网友(2):

就是一个取余数 等i+1=10 的时候取余数以后 i的值等于0 达到了循环目的

网友(3):

DelayMS(300);是什么意思?
答:就是延时300ms的意思。
下面是写程序时用的延时子程式,你可以作为参考。

//***************************************
//函数名:Delay_us/ms()
//描 述:延时函数。
//***************************************
#define Delay_1us() asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop")
void Delay_us(unsigned int n)
{
unsigned int i=0;
for (i=0; i {
Delay_1us();
}
}
void Delay_1ms(void)
{
unsigned int i;
for (i=1; i<(unsigned int)(osc*21-6); i++) ;//21-2
}
void Delay_ms(unsigned int n)
{
unsigned int i=0;
for (i=0; i {
Delay_1ms();
}
}
//“单片机高手团”为您解答。