C程序
// PORTD轮流输出0~9,显示到LED上// PIC16F877 11.0592MHZ 晶振,PICMATE2002 IDE,WDT关
#include
void delayms(unsigned char settime);const chartable[]={0x21,0x5d,0x32,0x18,0x6c,0x88,0xa0,0x1d,0x20,0x08};
unsigned char i,j;
unsigned char DELAYH,DELAYL;
main()
{
TRISC=0X00;
TRISD=0X00;
for(i=0;i<10;++i)
{
PORTC=table;
PORTD=table;
for(j=0;j<2;j++)
{
delayms(200);
}
}
}
void delayms(unsigned char settime) //延时x ms
{
DELAYH=settime; //延时参数设置
#asm
DELAY2: MOVLW 0xFA //这一小段汇编程序延时1ms
MOVWF _DELAYL
DELAY1: NOP
DECFSZ_DELAYL,F
GOTO DELAY1
DECFSZ _DELAYH,F
GOTO DELAY2
#endasm
}
const chartable[]={0x21,0x5d,0x32,0x18,0x6c,0x88,0xa0,0x1d,0x20,0x08};
unsigned char i,j; //不要动辄使用全局变量
unsigned char DELAYH,DELAYL; //同上
main() //要养成编程的好习惯,这样的简写不妥当
{
TRISC=0X00;
TRISD=0X00;
for(i=0;i<10;++i)
{
PORTC=table;
PORTD=table; //查表操作重复
for(j=0;j<2;j++)
{
delayms(200); //简单延时,没必要传递参数
}
}
}
void delayms(unsigned char settime) //延时x ms
{
DELAYH=settime; //延时参数设置
#asm
DELAY2: MOVLW 0xFA //这一小段汇编程序延时1ms
MOVWF _DELAYL
DELAY1: NOP
DECFSZ_DELAYL,F
GOTO DELAY1
DECFSZ _DELAYH,F
GOTO DELAY2
#endasm
}
void delayms();
const unsigned chartable[]={0x21,0x5d,0x32,0x18,0x6c,0x88,0xa0,0x1d,0x20,0x08};
void main(void)
{
unsigned char i;
TRISC=0X00;
TRISD=0X00;
for(i=0;i<10;++i)
{
PORTC=PORTD=table;
delayms();
}
}
void delayms()
{
unsigned int DELAYH=10000; //延时参数设置,用IDE调试
while(--DELAYH);
}
页:
[1]