volatile int count=255;
volatile char *outF;
volatile char *dirF,*dirK,*inputK;
void setup() {
// put your setup code here, to run once:
outF=0x31;
dirF=0X30;
*dirF=0x01;
dirK=0x107;
*dirK=0x00;
inputK=0x106;
init_timer1();
while(1){
while (TCNT1<count){
//pulse low
*outF=0x00;
increase();
mydelay();
decrease();
mydelay();
}
while(TCNT1>count)
{
//pulse high
*outF=0x01;
increase();
mydelay();
decrease();
mydelay();
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}
void init_timer1(){
TCCR1A=0;
TCNT1=0;
TCCR1B=0;
OCR1A=0xFF; // maximum counter value
TCCR1B=0X0C;//Selecting prescaller
TIMSK1=0X02;// enabling local interrupt
}
ISR(TIMER1_COMPA_vect){
// count--;
// if(count<0){
// count=255;
// }
}
void increase()
{
if(*inputK==0x01)
{
count=count-1;
if(count<0)
{
count=0;
}
}
}
void decrease()
{
if(*inputK==0x02){
count=count+1;
if(count>255)
{
count=255;
}
}
}
void mydelay(){
for(volatile int i=0;i<500;i++);
}