From: Bernard Blackham Date: Fri, 15 Aug 2003 10:00:27 +0000 (+0000) Subject: More bugfixes & initing X-Git-Tag: ROMW~64 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=41ad37ba6d86ccc4f8f720cb09f7891ae166cb38;p=uccvend-snackrom.git More bugfixes & initing --- diff --git a/ROM2/coinmech.c b/ROM2/coinmech.c index e24fe62..c52e146 100644 --- a/ROM2/coinmech.c +++ b/ROM2/coinmech.c @@ -130,3 +130,10 @@ void coin_cost(u16 cost) { 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); +} diff --git a/ROM2/coinmech.h b/ROM2/coinmech.h index 41f18ab..615caf6 100644 --- a/ROM2/coinmech.h +++ b/ROM2/coinmech.h @@ -7,5 +7,6 @@ extern volatile u16 coin_value; void coin_eat(); void coin_cost(u16 cost); /* specify the cost of an item. */ +void coinmech_init(); #endif /* _COINMECH_H_ */ diff --git a/ROM2/comm.h b/ROM2/comm.h index 9bff8bd..65a3446 100644 --- a/ROM2/comm.h +++ b/ROM2/comm.h @@ -12,6 +12,7 @@ * 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 diff --git a/ROM2/display_basic.c b/ROM2/display_basic.c index 0526d2f..72d8ac0 100644 --- a/ROM2/display_basic.c +++ b/ROM2/display_basic.c @@ -27,6 +27,8 @@ void display_send_byte(char c) { _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 */ diff --git a/ROM2/main_basic.c b/ROM2/main_basic.c index e459471..8a48086 100644 --- a/ROM2/main_basic.c +++ b/ROM2/main_basic.c @@ -89,8 +89,7 @@ void give_change() { 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(); @@ -104,18 +103,44 @@ void send_keypress(u8 key) { 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': @@ -135,6 +160,7 @@ int main() { break; default: /* shrug */ + send_nack(); break; } msg_clr(); diff --git a/ROM2/memory.x b/ROM2/memory.x index 843cbbf..f33b3a8 100644 --- a/ROM2/memory.x +++ b/ROM2/memory.x @@ -1,14 +1,3 @@ -/* memory.x -- Memory definition for a 68HC11 program in EEPROM (512 bytes) - Copyright 2001 Free Software Foundation, Inc. - Written by Stephane Carrez (stcarrez@worldnet.fr) - Adapted for openvend by Bernard Blackham (dagobah@ucc.asn.au) - -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 */ diff --git a/ROM2/start.s b/ROM2/start.s index 1520835..c370263 100644 --- a/ROM2/start.s +++ b/ROM2/start.s @@ -2,24 +2,34 @@ .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 diff --git a/ROM2/vend.h b/ROM2/vend.h index ea079b4..9922719 100644 --- a/ROM2/vend.h +++ b/ROM2/vend.h @@ -45,12 +45,12 @@ void my_memcpy(char* dst, char* src, u8 size); #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