diff --git a/main.c b/main.c index 83866be..e9050f8 100755 --- a/main.c +++ b/main.c @@ -1,10 +1,9 @@ #include #include -#define CPU_FREQ 16000000L - -unsigned int joystick_lr; -unsigned int joystick_ud; +#define CPU_FREQ 16000000L +#define VAL25 895 +#define VAL105 246 void init_serial(int speed) { @@ -30,36 +29,64 @@ void port_initio(void) { DDRD &= 0xFC; DDRD |= 0x3C; + DDRC = 0x00; DDRB &= 0xFE; PORTD |= 0x3C; } +int analogRead(uint8_t pin) +{ + uint8_t low, high; + + if (pin >= 14) + pin -= 14; // allow for channel or pin numbers + ADMUX = (0x01 << 6) | (pin & 0x07); + ADCSRA|=(1< VAL25) + ftemp = 0; + else if(temp < VAL105) { - if(once) - { - PORTD &= 0xE7; - //_delay_ms(00000); - //PORTD |= 0x18; - //once = 0; - } + ftemp = 255; + opto1 = 0; } else { - once = 1; - PORTD |= 0x18; + temp = (VAL25 - temp) * 255; + ftemp = temp / (VAL25 - VAL105); } + if((opto0 == 1) && ((PIND & 0x40) == 0x40)) + PORTD &= 0xE7; + else + PORTD |= 0x18; if((opto1 == 1) && ((PIND & 0x80) == 0x80)) PORTD &= 0xDB; else @@ -70,14 +97,21 @@ int main(void) opto0 = 1; else if(ser == 'D') opto0 = 0; - send_serial(ser); -/* - if((PINB & 0x01) == 0x01) - send_serial('1'); + else if(ser == 'E') + opto1 = 1; + else if(ser == 'G') + opto1 = 0; + else if(ser == 'H') + send_serial(ftemp); + else if(ser == 'F') + { + if((PINB & 0x01) == 0x01) + send_serial('I'); + else + send_serial('K'); + } else - send_serial('0'); - send_serial('\n'); -*/ + send_serial('J'); } return 0; -- libgit2 0.21.2