|
2#
楼主 |
发表于 2009-3-24 16:41:49
|
只看该作者
const char table[]={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[i];
PORTD=table[i]; //查表操作重复
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 char table[]={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[i];
delayms();
}
}
void delayms()
{
unsigned int DELAYH=10000; //延时参数设置,用IDE调试
while(--DELAYH);
} |
|