英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流
标题:
C程序
[打印本页]
作者:
winnie
时间:
2009-3-24 16:41
标题:
C程序
// PORTD轮流输出0~9,显示到LED上
// PIC16F877 11.0592MHZ 晶振,PICMATE2002 IDE,WDT关
#include
void delayms(unsigned char settime);
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
;
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
}
作者:
winnie
时间:
2009-3-24 16:41
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);
}
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/)
Powered by Discuz! X3.2