reworkings
[uccvend-snackrom.git] / ROM2 / display.c
1 /*
2  * display.c - functions for controlling the display on the vending machine.
3  *
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
8  * message will scroll.
9  *
10  */
11
12 #include "vend.h"
13
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  */
17
18 /* private prototypes */
19 void display_send_byte(char c);
20 void display_reset();
21 void display_update();
22
23
24 void set_msg(char* newmsg) {
25         char* dest = current_message;
26         /* equivalent of a string copy */
27         /* while (dest++ = newmsg++); */
28         while (newmsg) {
29                 dest = newmsg;
30                 dest++;
31                 newmsg++;
32         }
33         display_update();
34 }
35
36 inline void set_wrap_mode(u8 new_wrap_mode) {
37         /* in theory it should be inlined anyway? */
38         wrap_mode = new_wrap_mode;
39 }
40
41 void display_send_byte(char c) {
42         *_misc_output |= A3800_DISPLAY_WRITE;  /* enable the display clock */
43
44         _io_ports[M6811_SPDR] = c;            /* load SPI with byte */
45         while(!(_io_ports[M6811_SPDR]&0x80)); /* wait for completion */
46 }
47
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;
52         delay(DISPLAY_DELAY);
53         _io_ports[M6811_PORTA] |= PORTA_DISP_RESET;
54
55         _io_ports[M6811_SPCR] |= M6811_SPE;       /* enable the SPI */
56         delay(DISPLAY_DELAY);
57
58         display_send_byte(0xCA);    /* tell the controller there are 10 digits */
59         display_send_byte(0xE0);    /* set duty cycle to 100%                  */
60
61         _io_ports[M6811_SPCR] &= ~M6811_SPE;       /* disable the SPI again */
62 }
63
64 void display_update() {
65         int i;
66         display_reset();
67         
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
72                  * character set
73                  */
74                 display_send_byte(i[display_buffer]&0x7f);
75         }
76 }
77
78 void display_init() {
79         display_reset();
80 }
81

UCC git Repository :: git.ucc.asn.au