From 6e1b8105f5da1411470dbaac3f18bf2d244106c6 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 12 Sep 2018 02:07:41 +0200 Subject: cleanup wiring --- doc/pinout.txt | 31 ++++++++++++++++++++++ elegoo/config.h | 10 +++---- forth/flash-led.fs | 10 +++++++ forth/main.fs | 31 ++++++++++++++++++++++ forth/see.fs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 doc/pinout.txt create mode 100644 forth/main.fs create mode 100644 forth/see.fs diff --git a/doc/pinout.txt b/doc/pinout.txt new file mode 100644 index 0000000..f3f9d12 --- /dev/null +++ b/doc/pinout.txt @@ -0,0 +1,31 @@ +pin atmega328p arduino elegoo + +1 PC6 (PCINT14/RESET) reset - +2 PD0 (PCINT16/RXD) digital pin 0 (RX) - +3 PD1 (PCINT17/TXD) digital pin 1 (TX) - +4 PD2 (PCINT18/INT0) digital pin 2 ground sensor right +5 PD3 (PCINT19/OC2B/INT1) digital pin 3 (PWM) ground sensor center +6 PD4 (PCINT20/XCK/T0) digital pin 4 ground sensor left +7 VCC VCC - +8 GND GND - +9 PB6 (PCINT6/XTAL1/TOSC1) crystal - +10 PB7 (PCINT7/XTAL2/TOSC2) crystal - +11 PD5 (PCINT21/OC0B/T1) digital pin 5 (PWM) motor analog enable right +12 PD6 (PCINT22/OC0A/AIN0) digital pin 6 (PWM) motor analog enable left +13 PD7 (PCINT23/AIN1) digital pin 7 direction backward right +14 PB0 (PCINT0/CLKO/ICP1) digital pin 8 direction forward right + +15 PB1 (OC1A/PCINT1) digital pin 9 (PWM) direction backward left +16 PB2 (SS/OC1B/PCINT2) digital pin 10 (PWM) direction forward left +17 PB3 (MOSI/OC2A/PCINT3) digital pin 11 (PWM) ultrasonic servo pwm +18 PB4 (MISO/PCINT4) digital pin 12 infrared receiver +19 PB5 (SCK/PCINT5) digital pin 13 (LED) - +20 AVCC VCC +21 AREF analog reference +22 GND GND +23 PC0 (ADC0/PCINT8) analog input 0 ultrasonic trigger output +24 PC1 (ADC1/PCINT9) analog input 1 ultrasonic echo input +25 PC2 (ADC2/PCINT10) analog input 2 free +26 PC3 (ADC3/PCINT11) analog input 3 free +27 PC4 (ADC4/SDA/PCINT12) analog input 4 free +28 PC5 (ADC5/SCL/PCINT13) analog input 5 free diff --git a/elegoo/config.h b/elegoo/config.h index 6753bd0..31aa155 100644 --- a/elegoo/config.h +++ b/elegoo/config.h @@ -8,8 +8,8 @@ #define velo 130 // Pinout motor -#define ENA 5 // 10 pwm enable right PD5 Out PWM -#define ENB 6 // 5 pwm enable left PD6 Out PWM +#define ENA 5 // 10 pwm enable right PD5 Out PWM OC0B +#define ENB 6 // 5 pwm enable left PD6 Out PWM OC0A #define IN1 7 // 9 direction backward right PD7 Out #define IN2 8 // 8 direction forward right PB0 Out @@ -18,11 +18,11 @@ // Pinout sensors #define SR 2 // right PD2 In -#define SC 4 // center PD4 In -#define SL 11 // left PB3 In +#define SC 3 // center PD3 In +#define SL 4 // left PD4 In // Servo -#define SRV 3 // PD3 Out PWM +#define SRV 11 // PB3 Out PWM OC2A // Pinout IR #define IR 12 // PB4 In diff --git a/forth/flash-led.fs b/forth/flash-led.fs index e9b8657..08fc643 100644 --- a/forth/flash-led.fs +++ b/forth/flash-led.fs @@ -2,8 +2,18 @@ marker -flash-led-avr \ PB5 is Arduino digital pin 13. +$0023 constant pinb $0024 constant ddrb $0025 constant portb + +$0026 constant pinc +$0027 constant ddrc +$0028 constant portc + +$0029 constant pind +$002a constant ddrd +$002b constant portd + 1 #5 lshift constant bit5 : init bit5 ddrb mset ; \ set pin as output diff --git a/forth/main.fs b/forth/main.fs new file mode 100644 index 0000000..7551f7c --- /dev/null +++ b/forth/main.fs @@ -0,0 +1,31 @@ +-io +marker -io \ define ports + +$23 constant pinb +$24 constant ddrb +$25 constant portb + +$26 constant pinc +$27 constant ddrc +$28 constant portc + +$29 constant pind +$2a constant ddrd +$2b constant portd + +: bv ( bit -- mask ) 1 swap lshift ; + +#5 bv portb 2constant led +#5 bv ddrb mset + +#2 bv pind 2constant sr +#2 bv ddrd mclr + +#4 bv pind 2constant sc +#4 bv ddrd mclr + +#3 bv pind 2constant sl +#3 bv ddrd mclr + +: read ( mask port -- flag ) + c@ invert 0= swap drop ; diff --git a/forth/see.fs b/forth/see.fs new file mode 100644 index 0000000..a1c2deb --- /dev/null +++ b/forth/see.fs @@ -0,0 +1,77 @@ +\ ********************************************************************* +\ Filename: see.txt * +\ Date: 20.03.2017 * +\ FF Version: 5.0 * +\ MCU: Atmega * +\ Copyright: Mikael Nordman * +\ Author: Mikael Nordman * +\ ********************************************************************* +\ FlashForth is licensed acording to the GNU General Public License* +\ ********************************************************************* +-see +marker -see +hex ram +: *@ dup @ ; +: u.4 4 u.r ; +: *@+ dup cell+ @ u.4 ; +: 5sp 5 spaces ; +: @braddr ( addr -- addr xt-addr ) + *@ fff and dup 800 and + if f800 or then 2* over + cell+ ; +: @xtaddr ( addr -- addr xt-addr ) + dup cell+ @ xa> ; +: .rjmp ( addr -- addr+2 ) @braddr u.4 cell+ ; +: .br ( addr -- addr+2 ) + *@ 3 rshift 7f and dup 40 and + if ff80 or then 2* over + cell+ u.4 cell+ ; +: .reg ( addr -- addr ) + dup @ 4 rshift 1f and ." r" decimal 2 u.r hex cell+ ; +: .ldi ( addr -- addr ) + *@ dup 4 rshift dup 000f and 0010 + + ." r" decimal 2 u.r hex + 00f0 and swap 000f and + 2 u.r cell+ ; +: ?call ( addr -- addr f ) *@ fe0e and 940e - ; +: ?ret ( addr -- addr f ) *@ 9508 - ; +: ?rcall ( addr -- addr f ) *@ f000 and d000 - ; +: ?jmp ( addr -- addr f ) *@ fe0e and 940c - ; +: ?rjmp ( addr -- addr f ) *@ f000 and c000 - ; +: ?breq ( addr -- addr f ) *@ fc07 and f001 - ; +: ?brne ( addr -- addr f ) *@ fc07 and f401 - ; +: ?brcc ( addr -- addr f ) *@ fc07 and f400 - ; +: ?pop ( addr -- addr f ) *@ fe0f and 900f - ; +: ?push ( addr -- addr f ) *@ fe0f and 920f - ; +: ?st-y ( addr -- addr f ) *@ fe0f and 920a - ; +: ?ldy+ ( addr -- addr f ) *@ fe0f and 9009 - ; +: ?ijmp ( addr -- addr f ) *@ 9409 - ; +: ?ldi ( addr -- addr f ) *@ f000 and e000 - ; +: (see) ( addr -- addr' | false ) + dup u.4 + *@ u.4 + ?call 0= if *@+ ." call " @xtaddr c>n .id cell+ cell+ else + ?rcall 0= if 5sp ." rcall " @braddr c>n .id cell+ else + ?breq 0= if 5sp ." breq " .br else + ?brne 0= if 5sp ." brne " .br else + ?brcc 0= if 5sp ." brcc " .br else + ?rjmp 0= if 5sp ." rjmp " .rjmp else + ?ijmp 0= if 5sp ." ijmp" drop false else + ?ret 0= if 5sp ." ret" drop false else + ?jmp 0= if *@+ ." jmp " @xtaddr c>n .id drop false else + ?pop 0= if 5sp ." pop " .reg else + ?push 0= if 5sp ." push " .reg else + ?ldy+ 0= if 5sp ." ld " .reg ." y+" else + ?st-y 0= if 5sp ." st -y " .reg else + ?ldi 0= if 5sp ." ldi " .ldi else + cell+ + then then then then then + then then then then then + then then then then + cr ; + +: dis ( addr -- ) + hex cr + begin (see) dup 0= + until drop ; + +: see ( "word" -- ) ' dis ; +hex ram + -- cgit v1.2.3