#include<p18f4520.h>
#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF, LVP=OFF
void delay(unsigned int value);
#define IN1 PORTCbits.RC0
#define IN2 PORTCbits.RC2
#define start PORTCbits.RC3
#define stop PORTCbits.RC7
#define rw PORTCbits.RC4
#define inc PORTCbits.RC5
#define dec PORTCbits.RC6
unsigned int i=0;
void main()
{
CCP2CON=0x0C;
PR2=155;
T2CON=0x05;
CCPR2L=0xff;
ADCON1=0x0f;
TRISCbits.TRISC0=0;
TRISCbits.TRISC1=0;
TRISCbits.TRISC2=0;
TRISCbits.TRISC3=1;
TRISCbits.TRISC4=1;
TRISCbits.TRISC5=1;
TRISCbits.TRISC6=1;
TRISCbits.TRISC7=1;
IN1=IN2=0;
while(1)
{
if(start==0 )
{
IN1=0;
IN2=1;
CCPR2L=0x4b;
i=2;
}
if((rw==0 & i==2))
{
IN1=1;
IN2=0;
CCPR2L=0x4B;
}
if(inc==0 &(CCPR2L!=0xff)& i==2)
{
CCPR2L=CCPR2L+1;
delay(10);
}
if(dec==0 &(CCPR2L!=0x00) & i==2)
{
CCPR2L=CCPR2L-1;
delay(10);
}
if(stop==0)
{
CCPR2L=0x00;
i=0;
}
}
}
void delay(unsigned int value)
{
int ii,j;
for(ii=0;ii<=value;ii++)
for(j=0;j<=900;j++);
}
Comments
Post a Comment