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
5 * previous one. The message can be at most 255 characters long. Use
6 * set_wrap_mode with one of the WRAP_* options in vend.h to set the scrolling
7 * behaviour. If the message is less than 10 characters, it is not scrolled.
8 * Otherwise, the message will scroll.
14 char display_buffer[10]; /* what each byte on the display reads */
15 char current_message[256]; /* message that is scrolled or switched between */
16 u8 wrap_mode; /* whether to scroll or alternate between msgs */
17 u8 scroll_point; /* how far through the message we have scrolled */
19 /* private prototypes */
20 void display_send_byte(char c);
22 void display_update();
24 void set_msg(char* newmsg) {
25 char* dest = current_message;
26 /* equivalent of a string copy */
27 /* while (dest++ = newmsg++); */
37 extern inline void set_wrap_mode(u8 new_wrap_mode) {
38 /* in theory it should be inlined anyway? */
39 wrap_mode = new_wrap_mode;
42 void display_send_byte(char c) {
43 bset_misc_output(A3800_DISPLAY_WRITE); /* enable the display clock */
45 _io_ports[M6811_SPDR] = c; /* load SPI with byte */
46 while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
47 _io_ports[M6811_SPDR]; /* SPDR read to clear SPIE flag */
50 #define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */
51 void display_reset() {
52 /* lower the reset line for a while */
53 bclr(&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
55 bset(&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
60 display_send_byte(0xC0 | 10); /* tell the controller there are 10 digits */
61 display_send_byte(0xE0); /* set duty cycle to 100% */
66 void display_update() {
70 for (i=0; i < 10; i++) {
71 /* FIXME: we may need to fiddle with the character codes sent to the
72 * controller. It doesn't seem like we have to, but datasheets for
73 * the "pin-for-pin" compatible MSC1937 from OKI suggest a different
76 display_send_byte(i[display_buffer]&0x7f);