rendered paste bodydnl ################################################################################
dnl # This program is free software; you can redistribute it and/or modify it #
dnl # under the terms of the GNU General Public License (either version 2 or #
dnl # version 3) as published by the Free Software Foundation. #
dnl # #
dnl # This program is distributed in the hope that it will be useful, #
dnl # but WITHOUT ANY WARRANTY; without even the implied warranty of #
dnl # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
dnl # GNU General Public License for more details. #
dnl # #
dnl # You should have received a copy of the GNU General Public License #
dnl # along with this program; if not, write to the Free Software #
dnl # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
dnl # #
dnl # For more information on the GPL, please go to: #
dnl # http://www.gnu.org/copyleft/gpl.html #
dnl # #
dnl # #
dnl # Programm Erstellung: #
dnl # Copyright (c) 08/2009 - Michael Schultz <ethersex@keyb.de> #
dnl # #
dnl ################################################################################
dnl
uint8_t delay = 0;
#include <hardware/lcd/hr20.h>
uint8_t counter;
CONTROL_START
ECMD_GLOBAL(pos, 0, uint16_t);
ECMD_GLOBAL(dir, 0, uint8_t); dnl Drehrichtung
ECMD_GLOBAL(move, 0, uint8_t);
ECMD_GLOBAL(speed, 0, uint8_t);
ECMD_GLOBAL(coun, 0, uint16_t); dnl Counter fr timer0 interrupt berlauf durchgnge
THREAD(update_temp)
dnl HR20_SHOW_TEMP(hr20_temp_get());
dnl WAIT(2)
dnl HR20_SHOW_VOLTAGE(HR20_GET_BATT());
dnl WAIT(1)
HR20_SHOW_VOLTAGE(counter);
WAIT(1)
THREAD_END(update_clock)
THREAD(motor)
WAIT(60);
DEBUG(`"ich lebe noch... :-)"');
THREAD_END(motor)
ON STARTUP DO
dnl TCCR0A CS02 CS01 CS00 Datenblatt Seite 44
dnl 0 0 0 No clock source (Timer/Counter stopped)
dnl 0 0 1 clkI/O/(No prescaling)
dnl 0 1 0 clkI/O/8 (From prescaler)
dnl 0 1 1 clkI/O/64 (From prescaler)
dnl 1 0 0 clkI/O/256 (From prescaler)
dnl 1 0 1 clkI/O/1024 (From prescaler)
dnl 1 1 0 External clock source on T0 pin. Clock on falling edge.
dnl 1 1 1 External clock source on T0 pin. Clock on rising edge.
TCCR0A &= ~_BV(CS02); dnl TCCR0A(CS02) = 0 counter0 prescaler = 0
TCCR0A &= ~_BV(CS01); dnl TCCR0A(CS01) = 0 counter0 prescaler = 0
TCCR0A |= _BV(CS00); dnl TCCR0A(CS00) = 1 counter0 prescaler = 0
TIMSK0 |= _BV(TOIE0); dnl TIMSK0(TOIE0) = 1 Timer0 Interrupt Aktivieren
PCMSK0 |= _BV(PCINT4); dnl Interrupt aktivierung fr Lichtschranke
dnl Gendertes Layout !!!!!
DDRB &= ~_BV(PB0); dnl switch pin for Input DDRB(PB0) = 0
DDRB &= ~_BV(PB1); dnl switch pin for Input DDRB(PB1) = 0
DDRB &= ~_BV(PB2); dnl switch pin for Input DDRB(PB2) = 0
DDRB &= ~_BV(PB4); dnl switch pin for Input DDRB(PB4) = 0
DDRB &= ~_BV(PB5); dnl switch pin for Input DDRB(PB5) = 0
PORTB |= _BV(PB0); dnl PORTB(PB0) = 1 seite 56 und 57
PORTB |= _BV(PB1); dnl PORTB(PB1) = 1 seite 56 und 57
PORTB |= _BV(PB2); dnl PORTB(PB2) = 1 seite 56 und 57
PORTB &= ~_BV(PB4); dnl PORTB(PB4) = 0 seite 56 und 57
PORTB &= ~_BV(PB5); dnl PORTB(PB5) = 0 seite 56 und 57
PCMSK1 |= _BV(PCINT8); dnl Interrupt aktivierung fr Taste1
PCMSK1 |= _BV(PCINT9); dnl Interrupt aktivierung fr Taste2
PCMSK1 |= _BV(PCINT10); dnl Interrupt aktivierung fr Taste3
PCMSK1 |= _BV(PCINT12); dnl Interrupt aktivierung fr wahlrad
PCMSK1 |= _BV(PCINT13); dnl Interrupt aktivierung fr wahlrad
EIMSK |= _BV(PCIE1);
DDRE &= ~_BV(PE4); dnl Eingang Schalten
PORTE &= ~_BV(PE4); dnl Pullup deaktivieren
PCMSK1 |= _BV(PCINT4); dnl interrupt fr den pin aktivieren
EIMSK |= _BV(PCIE0); dnl interrupt generell fr pereferie 0 aktivieren
DDRE |= _BV(PE2); dnl Lichtschranken pinne, vorbereiten, aber aus
DDRE |= _BV(PE3); dnl Lichtschranken pinne, vorbereiten, aber aus
dnl PORTE &= ~_BV(PE2); dnl Lichtschranken pinne, vorbereiten, aber aus
dnl PORTE &= ~_BV(PE3); dnl Lichtschranken pinne, vorbereiten, aber aus
PORTE |= _BV(PE2); dnl Lichtschranke aktivieren ( port output and high )
PORTE |= _BV(PE3); dnl Lichtschranke aktivieren ( port output and high )
dnl hr20_lcd_putchar (2, 4); dnl 4 an stelle 2 schreiben
hr20_lcd_putchar (0, HR20_LCD_CHAR_DEG); dnl 0 an stelle 0 schreiben
dnl PB0 / PCINT8 Taste PCINT1 out pullup
dnl PB1 / PCINT9 Taste PCINT1 out pullup
dnl PB2 / PCINT10 Taste PCINT1 out pullup
dnl PB4 / PCINT12 Rad PCINT1 out pullup
dnl PB5 / PCINT13 Rad PCINT1 out pullup
dnl PG3 T1 Motor Ansteuerung
dnl PG4 T0 Motor Ansteuerung
dnl PE2 Lichtschranke LED Out out pullup
dnl PE3 Lichtschranke LED Out / Spannungs versorgung Input out pullup
dnl PE4 Lichtschranke Input !!!gendert!!! Pin Change Interrupt4 PCINT4 in
DEBUG("Startup C6");
dnl PCINT0 Pin Change Interrupt Request 0
dnl PCINT1 Pin Change Interrupt Request 1
dnl INT0 External Interrupt Request 0
dnl TIMER0 OVF Timer/Counter0 Overflow
THREAD_START(motor)
THREAD_START(update_temp)
END
CONTROL_END
#include <avr/interrupt.h>
ISR(TIMER0_OVF_vect)
{
coun ++;
if ( move >= 1 ) {
delay ++;
if ( delay >= speed ) {
if ( dir == 1 ) {
PORTG &= ~_BV(PG3) ; dnl PORTG(PG3) = 0
PORTG &= ~_BV(PG4) ; dnl PORTG(PG4) = 0
} else {
PORTG &= ~_BV(PG3) ; dnl PORTG(PG3) = 0
PORTG &= ~_BV(PG4) ; dnl PORTG(PG4) = 0
}
} else {
if ( dir == 1 ) {
PORTG |= _BV(PG3) ; dnl PORTG(PG3) = 1
PORTG &= ~_BV(PG4) ; dnl PORTG(PG4) = 0
} else {
PORTG &= ~_BV(PG3) ; dnl PORTG(PG3) = 0
PORTG |= _BV(PG4) ; dnl PORTG(PG4) = 1
}
}
}
}
dnl uint8_t delay = 0;
dnl ECMD_GLOBAL(pos, 0, uint16_t);
dnl ECMD_GLOBAL(dir, 0, uint8_t);
dnl ECMD_GLOBAL(move, 0, uint8_t);
dnl ECMD_GLOBAL(speed, 0, uint8_t);
ISR(PCINT0_vect)
{
DEBUG("pcint0");
if ( PORTE & ( 1 << 4 ) ) { DEBUG("pcint0 4"); }
if ( dir == 1 ) {
pos ++ ;
DEBUG("pcint0 pos +");
} else {
pos -- ;
DEBUG("pcint0 pos -");
}
}
static uint8_t pin0;
static uint8_t pin1;
static uint8_t pin2;
static uint8_t pin4;
static uint8_t pin5;
static uint8_t pin4_prev;
static uint8_t pin5_prev;
static uint8_t pinb_tmp;
ISR(PCINT1_vect)
{
DEBUG("pcint1 +");
pinb_tmp = PINB;
pin0 = pinb_tmp & (1<<0);
pin1 = pinb_tmp & (1<<1);
pin2 = pinb_tmp & (1<<2);
pin4 = pinb_tmp & (1<<4);
pin5 = pinb_tmp & (1<<5);
if ( pin0 == 0) { DEBUG("pcint1 0"); }
if ( pin1 == 0 ) { DEBUG("pcint1 1"); }
if ( pin2 == 0) { DEBUG("pcint1 2"); }
if ( pin4 != pin4_prev) { DEBUG("pcint1 4"); }
if ( pin5 != pin5_prev) { DEBUG("pcint1 5"); }
if ( (pin5 != pin5_prev) ^ (pin4 != pin4_prev) ){counter++;DEBUG("Rad nach rechts")}else{counter--;DEBUG("Rad nach links")}
pin4_prev=pin4;
pin5_prev=pin5;
}
dnl if (! (PORTB & _BV(PB0) ) ) { DEBUG("pcint1 0"); }
dnl if (! (PORTB & _BV(PB1) ) ) { DEBUG("pcint1 1"); }
dnl if (! (PORTB & _BV(PB2) ) ) { DEBUG("pcint1 2"); }
dnl if ( PORTB & _BV(PB4) ) { DEBUG("pcint1 4"); }
dnl if ( PORTB & _BV(PB5) ) { DEBUG("pcint1 5"); }
dnl if ( PIN_LOW (PORTB(PB0))) { DEBUG("pcint1 0"); }
dnl if ( PIN_LOW (PORTB(PB1))) { DEBUG("pcint1 1"); }
dnl if ( PIN_LOW (PB2)) { DEBUG("pcint1 2"); }
dnl if ( PIN_LOW (PB4)) { DEBUG("pcint1 4"); }
dnl if ( PIN_LOW (PB5)) { DEBUG("pcint1 5"); }
dnl if (PIN_HIGH (pinname )) ...
dnl
dnl THREAD(output_data)
dnl DEBUG("test");
dnl WAIT(10);
dnl THREAD_END(output_data)
dnl
dnl THREAD_START(output_data)
dnl
dnl
dnl PINB &= ~_BV(PINB0);
dnl PINB &= ~_BV(PINB1);
dnl PINB &= ~_BV(PINB2);
dnl PINB &= ~_BV(PINB4);
dnl PINB &= ~_BV(PINB5);
dnl
dnl MCUCR &= ~_BV(PUD);
dnl
dnl
dnl struct key_press key;
dnl
dnl CONTROL_START
dnl ON STARTUP DO
dnl TCP_LISTEN(1332, message_handler);
dnl END
dnl TCP_HANDLER_PERSIST(message_handler)
dnl for (;;) {
dnl key = PS2_GET();
dnl if (key.keycode != 0) {
dnl TCP_SEND("%c", key.data)
dnl }
dnl }
dnl TCP_HANDLER_END();
dnl CONTROL_END
dnl
dnl PT_WAIT_UNTIL ((key = PS2_GET(), key.keycode != 0 )); TCP_SEND("%c", key.data")
dnl