Reworking of the assembly
[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
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.
9  *
10  */
11
12 #include "vend.h"
13
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 */
18
19 /* private prototypes */
20 void display_send_byte(char c);
21 void display_reset();
22 void display_update();
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         scroll_point = 0;
34         display_update();
35 }
36
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;
40 }
41
42 void display_send_byte(char c) {
43         bset_misc_output(A3800_DISPLAY_WRITE);  /* enable the display clock */
44
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 */
48 }
49
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((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
54         delay(DISPLAY_DELAY);
55         bset((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
56
57         spi_enable();
58         delay(DISPLAY_DELAY);
59
60         display_send_byte(0xC0 | 10);    /* tell the controller there are 10 digits */
61         display_send_byte(0xE0);    /* set duty cycle to 100%                  */
62
63         spi_disable();
64 }
65
66 void display_update() {
67         int i;
68         display_reset();
69         
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
74                  * character set
75                  */
76                 display_send_byte(i[display_buffer]&0x7f);
77         }
78 }
79
80 void display_init() {
81         display_reset();
82 }
83

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