[jaluino] r440 committed - testing 595 demux

2 views
Skip to first unread message

jal...@googlecode.com

unread,
Sep 29, 2013, 4:54:50 AM9/29/13
to jal...@googlegroups.com
Revision: 440
Author: sebastienlelong
Date: Sun Sep 29 08:54:35 2013 UTC
Log: testing 595 demux
http://code.google.com/p/jaluino/source/detail?r=440

Added:
/trunk/projects/jaluino_bee_cpc6128.jal

=======================================
--- /dev/null
+++ /trunk/projects/jaluino_bee_cpc6128.jal Sun Sep 29 08:54:35 2013 UTC
@@ -0,0 +1,160 @@
+-- Title: CPC 6128 keyboard USB interface
+-- Author: Sebastien Lelong, Copyright (c) 2008..2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4j
+-- Revision: $Revision: 373 $
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: USB keyboard interface for Amswtrad CPC 6128 keyboard
+-- This is basically a nice way to use demux and mux to read a keyboard
+-- matrix.
+--
+-- Sources:
+-- * https://sites.google.com/site/raspberrycpc6128/keyboard
+-- *
http://wiki.t-o-f.info/Arduino/ExempleMutliplexeurDentr%C3%A9esNum%C3%A9riques74HC165
+-- *
http://wiki.t-o-f.info/Arduino/ExempleD%C3%A9multiplexeurNum%C3%A9rique74HC595
+--
+-- Notes:
+-- PIC <=> 74HC595 demux:
+-- * RA0 <-> (11) SRCLK / CLOCK
+-- * RA1 <-> (12) RCLK / LATCH
+-- * RA2 <-> (14) SER / DATA
+--
+-- 74HC165 mux:
+-- * RB7 <-> (1) SH / LATCH
+-- * RB6 <-> (2) CLK / CLOCK
+-- * RB3 <-> (9) QH / DATA
+--
+
+include jaluino_bee
+include delay
+include print
+
+onboard_led_direction = output
+
+onboard_led = high
+delay_1s(1)
+onboard_led = low
+
+-- ok, now setup serial
+const serial_hw_baudrate = 9_600
+
+include serial_hardware
+serial_hw_init()
+
+
+;include usb_keyboard
+
+-- set all inputs to digital
+enable_digital_io()
+
+-- pin mapping
+-- for 74HC595 demux
+-- * RA0 <-> (11) SRCLK / CLOCK
+-- * RA1 <-> (12) RCLK / LATCH
+-- * RA2 <-> (14) SER / DATA
+alias demux595_clock is pin_a0
+alias demux595_data is pin_a2
+alias demux595_latch is pin_a1
+alias demux595_clock_direction is pin_a0_direction
+alias demux595_latch_direction is pin_a1_direction
+alias demux595_data_direction is pin_a2_direction
+-- for 74HC165 mux
+alias mux165_latch is pin_b7
+alias mux165_clock is pin_b6
+alias mux165_data is pin_b3
+alias mux165_latch_direction is pin_b7_direction
+alias mux165_clock_direction is pin_b6_direction
+alias mux165_data_direction is pin_b3_direction
+-- extra pins for 9th and 10th bits
+alias mux165_data_9 is pin_b5
+alias mux165_data_10 is pin_b6
+alias mux165_data_9_direction is pin_b5_direction
+alias mux165_data_10_direction is pin_b6_direction
+
+
+procedure cpc6128() is
+ -- demux
+ demux595_data_direction = output
+ demux595_latch_direction = output
+ demux595_clock_direction = output
+ -- mux
+ mux165_latch_direction = output
+ mux165_clock_direction = output
+ mux165_data_direction = input
+ -- extra inputs to read mux 9th and 10th bits
+ mux165_data_9_direction = input
+ mux165_data_10_direction = input
+end procedure
+
+cpc6128()
+
+procedure shift_out(byte in data) is
+ var byte i = 0
+ for 8 using i loop
+ var byte val = (data & (1 << (7 - i)))
+ print_byte_dec(serial_hw_data,i)
+ serial_hw_data = ":"
+ print_byte_bin(serial_hw_data,!!val)
+ print_crlf(serial_hw_data)
+ demux595_data = !!val
+ ;digitalWrite(dataPin, !!(val & (1 << (7 - i))));
+ demux595_clock = high
+ demux595_clock = low
+ end loop
+end procedure
+
+
+var byte data = 0
+
+forever loop
+ print_byte_bin(serial_hw_data,data)
+ print_crlf(serial_hw_data)
+ -- 595 demux, output bits
+ -- take the latchPin low
+ demux595_latch = low
+ -- shift out the bits for the SECOND 74HC595:
+ shift_out(data)
+ -- take the latch pin high so the LEDs update:
+ demux595_latch = high
+ -- pause before next value:
+ delay_1s(5)
+
+ data = data + 1
+ onboard_led = ! onboard_led
+end loop
+
+
+;var byte key_value = USB_KEYBOARD_KEY_A
+
+
+
+;-- intialize the library
+;usb_keyboard_init()
+;
+;-- main loop
+;forever loop
+; -- poll the usb flush function on a regular base, in order to
+; -- serve the USB requests
+; usb_keyboard_flush()
+;
+; -- check if USB device has been configured by the HOST
+; if usb_is_configured() then
+;
+; if serial_hw_data_available then
+; key_value = ascii_to_keyscan[serial_hw_data]
+; ;if key_value == 10 then
+; ; ush_keyboard_send_key( 0x00, 0x28)
+; ;elsif key_value == 32 then
+; ; ush_keyboard_send_key( 0x00, USB_KEYBOARD_KEY_SPACE)
+; ;else
+; ; ush_keyboard_send_key( 0x00, key_value - 93)
+; ;end if
+; ush_keyboard_send_key( 0x00, key_value)
+; ush_keyboard_send_key( 0x00, 0x00)
+; end if
+; end if
+;end loop
+
Reply all
Reply to author
Forward
0 new messages