2 * display.c - functions for controlling the display on the vending machine.
4 * Use set_msg(char*) to write a new message to the screen, replacing the previous
5 * one. The message can be at most 1023 characters long. Use set_wrap_mode with
6 * one of the WRAP_* options in vend.h to set the scrolling behaviour. If the
7 * message is less than 10 characters, it is not scrolled. Otherwise, the
14 char display_buffer[10]; /* what each byte on the display reads */
15 char current_message[1024]; /* message that is scrolled or switched between */
16 u8 wrap_mode; /* whether to scroll or alternate between msgs */
18 /* private prototypes */
19 void display_send_byte(char c);
21 void display_update();
24 void set_msg(char* newmsg) {
25 char* dest = current_message;
26 /* equivalent of a string copy */
27 /* while (dest++ = newmsg++); */
36 inline void set_wrap_mode(u8 new_wrap_mode) {
37 /* in theory it should be inlined anyway? */
38 wrap_mode = new_wrap_mode;
41 void display_send_byte(char c) {
42 *_misc_output |= A3800_DISPLAY_WRITE; /* enable the display clock */
44 _io_ports[M6811_SPDR] = c; /* load SPI with byte */
45 while(!(_io_ports[M6811_SPDR]&0x80)); /* wait for completion */
48 #define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */
49 void display_reset() {
50 /* lower the reset line for a while */
51 _io_ports[M6811_PORTA] &= ~PORTA_DISP_RESET;
53 _io_ports[M6811_PORTA] |= PORTA_DISP_RESET;
55 _io_ports[M6811_SPCR] |= M6811_SPE; /* enable the SPI */
58 display_send_byte(0xCA); /* tell the controller there are 10 digits */
59 display_send_byte(0xE0); /* set duty cycle to 100% */
61 _io_ports[M6811_SPCR] &= ~M6811_SPE; /* disable the SPI again */
64 void display_update() {
68 for (i=0; i < 10; i++) {
69 /* FIXME: we may need to fiddle with the character codes sent to the
70 * controller. It doesn't seem like we have to, but datasheets for
71 * the "pin-for-pin" compatible MSC1937 from OKI suggest a different
74 display_send_byte(i[display_buffer]&0x7f);