From: Bernard Blackham Date: Wed, 6 Aug 2003 03:53:52 +0000 (+0000) Subject: display & keypad work X-Git-Tag: ROMW~106 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=caf0c7e19f65db08f81413320f11a8d5a8bea5d2;p=uccvend-snackrom.git display & keypad work --- diff --git a/ROM2/display.c b/ROM2/display.c index 3ab045b..25edee8 100644 --- a/ROM2/display.c +++ b/ROM2/display.c @@ -1,26 +1,26 @@ /* * display.c - functions for controlling the display on the vending machine. * - * Use set_msg(char*) to write a new message to the screen, replacing the previous - * one. The message can be at most 1023 characters long. Use set_wrap_mode with - * one of the WRAP_* options in vend.h to set the scrolling behaviour. If the - * message is less than 10 characters, it is not scrolled. Otherwise, the - * message will scroll. + * Use set_msg(char*) to write a new message to the screen, replacing the + * previous one. The message can be at most 255 characters long. Use + * set_wrap_mode with one of the WRAP_* options in vend.h to set the scrolling + * behaviour. If the message is less than 10 characters, it is not scrolled. + * Otherwise, the message will scroll. * */ #include "vend.h" char display_buffer[10]; /* what each byte on the display reads */ -char current_message[1024]; /* message that is scrolled or switched between */ +char current_message[256]; /* message that is scrolled or switched between */ u8 wrap_mode; /* whether to scroll or alternate between msgs */ +u8 scroll_point; /* how far through the message we have scrolled */ /* private prototypes */ void display_send_byte(char c); void display_reset(); void display_update(); - void set_msg(char* newmsg) { char* dest = current_message; /* equivalent of a string copy */ @@ -30,6 +30,7 @@ void set_msg(char* newmsg) { dest++; newmsg++; } + scroll_point = 0; display_update(); } @@ -39,10 +40,11 @@ inline void set_wrap_mode(u8 new_wrap_mode) { } void display_send_byte(char c) { - *_misc_output |= A3800_DISPLAY_WRITE; /* enable the display clock */ + bset_misc_output(A3800_DISPLAY_WRITE); /* enable the display clock */ - _io_ports[M6811_SPDR] = c; /* load SPI with byte */ - while(!(_io_ports[M6811_SPDR]&0x80)); /* wait for completion */ + _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 */ } #define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */ @@ -52,13 +54,13 @@ void display_reset() { delay(DISPLAY_DELAY); _io_ports[M6811_PORTA] |= PORTA_DISP_RESET; - _io_ports[M6811_SPCR] |= M6811_SPE; /* enable the SPI */ + spi_enable(); delay(DISPLAY_DELAY); - display_send_byte(0xCA); /* tell the controller there are 10 digits */ + display_send_byte(0xC0 | 10); /* tell the controller there are 10 digits */ display_send_byte(0xE0); /* set duty cycle to 100% */ - _io_ports[M6811_SPCR] &= ~M6811_SPE; /* disable the SPI again */ + spi_disable(); } void display_update() { diff --git a/ROM2/helpers.c b/ROM2/helpers.c index 71c1007..68adb3f 100644 --- a/ROM2/helpers.c +++ b/ROM2/helpers.c @@ -16,3 +16,11 @@ buffered_addr(home_sensors) buffered_addr(changer_output) buffered_addr(misc_output) + +inline void spi_enable() { + _io_ports[M6811_SPCR] |= M6811_SPE; +} + +inline void spi_disable() { + _io_ports[M6811_SPCR] &= ~M6811_SPE; +} diff --git a/ROM2/keypad.c b/ROM2/keypad.c index 80a11a7..5ab9b45 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -1,2 +1,19 @@ #include "vend.h" +int keypad_read_row() { + bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */ + + _io_ports[M6811_SPDR] = 0; + while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */ + + return _io_ports[M6811_SPDR]; +} + +/* row is 0 or 1 */ +void keypad_select_row(int row) { + if (row) + _io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW; + else + _io_ports[M6811_PORTD] &= ~PORTD_KEYPAD_ROW; +} + diff --git a/ROM2/vend.h b/ROM2/vend.h index 7094266..aa6409d 100644 --- a/ROM2/vend.h +++ b/ROM2/vend.h @@ -11,11 +11,17 @@ typedef signed short s16; typedef unsigned long u32; typedef signed long s32; typedef u8 bool; -typedef u16 addr_t; +typedef u16 addr_t; /* addresses of these set at link time */ +/* to add more addresses, define them here with buffered_addr_h, in helpers.c + * with buffered_addr, and also in LDFLAGS in the Makefile + */ #define buffered_addr_h(a) \ - extern volatile u8* _##a + extern volatile u8* _##a; \ + extern inline void set_##a(u8 b); \ + extern inline void bset_##a(u8 m); \ + extern inline void bclr_##a(u8 m); \ buffered_addr_h(switch_input); buffered_addr_h(misc_input); @@ -23,14 +29,17 @@ buffered_addr_h(home_sensors); buffered_addr_h(changer_output); buffered_addr_h(misc_output); +void spi_enable(); +void spi_disable(); + /******* from display.c *******/ /* scrolling modes */ #define WRAP_SCROLL_L 1 /* scroll to the left */ -#define WRAP_SCROLL_R 1 /* scroll to the right */ -#define WRAP_ALTERNATE 2 /* alternate between text */ +#define WRAP_SCROLL_R 2 /* scroll to the right */ +#define WRAP_ALTERNATE 3 /* alternate between text */ -extern char current_message[1024]; +extern char current_message[256]; void display_init(); void set_msg(char* newmsg); @@ -41,8 +50,12 @@ void delay(u16 ms); /******** Some meaningful bits ******/ #define PORTA_DISP_RESET 0x80 /* active low */ +#define PORTD_KEYPAD_ROW 0x20 /* clear for row 0, set for row 1 */ /* Address 3800 bits */ #define A3800_DISPLAY_WRITE 0x04 +/******* from main.c *******/ +int __attribute__((noreturn)) main (void); + #endif /* _VEND_H_ */