item_cost = cost;
while(coin_value); /* wait until coin mech cleared */
}
+
+void coinmech_init() {
+ _io_ports[M6811_SCCR1] = 0x10;
+ _io_ports[M6811_SCCR2] = 0x2e;
+ _io_ports[M6811_BAUD] = 0x03;
+ send_byte(0xff);
+}
void coin_eat();
void coin_cost(u16 cost); /* specify the cost of an item. */
+void coinmech_init();
#endif /* _COINMECH_H_ */
* KX - keypad press where X is (ascii 0..9 or R)
* CXXXXX - coin balance, XXXXX is number of cents.
* MXYY - dispense ack/nack. X is what happened (0..MOTOR_*_FAIL), YY is the motor
+ * DX - door open/close event where X is 1 for open, 0 for closed.
*
* Messages Received:
* VXX - vend a slot XX
_io_ports[M6811_SPDR] = c; /* load SPI with byte */
while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
_io_ports[M6811_SPDR]; /* SPDR read to clear SPIE flag */
+
+ bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */
}
#define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */
coin_cost(cost);
send_ack();
-}
-
+}
void send_keypress(u8 key) {
/* send a packet of the form KX with X being the key, or R for reset */
wait_for_tx_free();
send_packet();
}
+void send_door_msg(bool open) {
+ wait_for_tx_free();
+ tx_buffer[0] = 'D';
+ tx_buffer[1] = open?'1':'0';
+ tx_buffer[2] = '\n';
+ tx_buffer[3] = 0;
+ send_packet();
+}
+
void do_chime() {
chime_start();
send_ack();
}
int main() {
- u16 last_coin_value = coin_value;
+ u16 last_coin_value;
+ bool last_door_open;
+
+ chime_start();
+
+ misc_output = 0;
+ changer_output = 0x7f;
+ _io_ports[M6811_PORTA] = 0xc8;
+ _io_ports[M6811_DDRD] = 0x3e;
+ _io_ports[M6811_SPCR] = 0x12;
- /* init coin mech */
- comm_init();
display_init();
+ comm_init();
+ coinmech_init();
+
+ last_coin_value = 0;
+ last_door_open = 0;
while(1) {
+ if (door_open() != last_door_open) {
+ last_door_open = door_open();
+ send_door_msg(last_door_open);
+ }
+
if (rx_queue_state) {
switch (msg_buf[0]) {
case 'V':
break;
default:
/* shrug */
+ send_nack();
break;
}
msg_clr();
-/* memory.x -- Memory definition for a 68HC11 program in EEPROM (512 bytes)
- Copyright 2001 Free Software Foundation, Inc.
-
-The file was adapted from GTAM. You can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2, or (at your option) any later version.
-
-*/
-
MEMORY
{
/* we squeeze both page0 and data into the internal 256 bytes of RAM */
.globl _start
_start:
-;; enable the RTI
+ ;; enable the RTI
ldaa #0x40
staa 0x1024
-;; enable the ADC, and configure IRQ' for edge-sensitive operation
+
+ ;; enable the ADC, and configure IRQ' for edge-sensitive operation
ldaa #0xa0
staa 0x1039
-;; set the stack pointer
+
+ ;; set RTI intervals, and PA3/7 DDRs
+ ldaa #0x81
+ staa 0x1026
+
+ ;; clear ADC register
+ clra
+ staa 0x1030
+
+ ;; set the stack pointer
lds _stack
-;; initialize initialised variables
+ ;; blank initialised variables - should match memory.x's page0
ldx #0x0000
-loop:
+loop1:
cpx #0x0080
- bcc out
+ bcc out1
clr 00,x
inx
- bra loop
-out:
+ bra loop1
+out1:
jsr main
#define PORTE_MOTOR_OVERCURRENT 0x01
#define PORTE_MOTOR_OVERVOLTAGE 0x02
-/* Address 3000 bits */
-#define A3000_MOTOR_ROW_DISABLE 0x80
-
/* Address 1800 bits */
#define A1800_DOOR_OPEN 0x20
+/* Address 3000 bits */
+#define A3000_MOTOR_ROW_DISABLE 0x80
+
/* Address 3800 bits */
#define A3800_DISPLAY_WRITE 0x04
#define A3800_MOTOR_DATA 0x10