#include <htc.h>
#define But PORTEbits.RE0
#define Vcc PORTEbits.RE1
#define Qg PORTDbits.RD2
#define Delay_1us() asm("nop")
//********************************************
#define Delay_10us()
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop")
#define Level_Low 1
#define Level_High 0
void init_IO(void);
void Delay_ms(unsigned int);
void delay_100us(int);
main()
{
init_IO();
while(1)
{
if(But==Level_Low)
{Qg=Level_High;
Delay_ms(1500);
Vcc=Level_High;}
else
{Vcc=Level_Low;
Delay_ms(1500);
Qg=Level_Low;}
}
}
void init_IO(void)
{
PORTD = 0xff;
TRISD = 0xfb;
PORTE = 0xff;
TRISE = 0xfd;
}
void Delay_100us()
{
Delay_10us(); //1
Delay_10us(); //2
Delay_10us(); //3
Delay_10us(); //4
Delay_10us(); //5
Delay_10us(); //6
Delay_10us(); //7
Delay_10us(); //8
Delay_10us(); //9
Delay_1us(); //6us
Delay_1us();
Delay_1us();
Delay_1us();
Delay_1us();
Delay_1us();
}
//*******************************************
void Delay_ms(unsigned int ms)
{
unsigned int j;
for(j=ms;j>0;j--)
{
Delay_100us(); //1
Delay_100us(); //2
Delay_100us(); //3
Delay_100us(); //4
Delay_100us(); //5
Delay_100us(); //6
Delay_100us(); //7
Delay_100us(); //8
Delay_100us(); //9
Delay_10us(); //86us
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
Delay_1us();
Delay_1us();
Delay_1us();
Delay_1us();
Delay_1us();
Delay_1us();
}
}
按钮按下去,汽缸压下,2s后上电,按钮按下去,电压下降,2s后,汽缸升起。
这个程序有问题吗\? |