Fix bug in ROM vis display of periods on the display
[uccvend-snackrom.git] / ROM2 / display_basic.c
1 /*
2  * display_basic.c - simple functions for writing to the screen of the vendie.
3  *
4  * Use set_msg(char[10]) to write a new message to the screen, replacing the
5  * previous one.
6  *
7  */
8
9 #include "display_basic.h"
10 #include "vend.h"
11
12 /* private prototypes */
13 void display_send_byte(char c);
14 void display_reset();
15
16 void set_msg(char newmsg[11]) {
17         int i;
18         int prevchar = 0;
19
20         //display_reset();
21         spi_enable();
22         for (i=0; i < 10; i++) {
23                 if (newmsg[i] == 0) break;
24         }
25         display_send_byte(0xaf); // reset ptr to start
26         for (i--; i >= 0; i--) {
27                 if (prevchar && newmsg[i] == 0x2E) {
28                         display_send_byte(newmsg[i]&0x7f);
29                         continue;
30                 }
31
32                 // check if next character is a period
33                 if (newmsg[i] == 0x2E) {
34                         prevchar = newmsg[i];
35                         continue;
36                 }
37
38                 if (prevchar) {
39                         display_send_byte(newmsg[i]&0x7f);
40                         display_send_byte(prevchar&0x7f);
41                         prevchar = 0;
42                         continue;
43                 }
44
45                 if (newmsg[i] == 0) break;
46                 
47                 display_send_byte(newmsg[i]&0x7f);
48         }
49         
50         if (prevchar) {
51                 display_send_byte(prevchar&0x7f);
52         }
53         spi_disable();
54 }
55
56 void display_send_byte(char c) {
57         bset_misc_output(A3800_DISPLAY_WRITE);  /* enable the display clock */
58
59         _io_ports[M6811_SPDR] = c;                  /* load SPI with byte */
60         while(!(_io_ports[M6811_SPSR]&M6811_SPIF)); /* wait for completion */
61         _io_ports[M6811_SPDR];                      /* SPDR read to clear SPIF flag */
62
63         bclr_misc_output(A3800_DISPLAY_WRITE);  /* disable the display clock */
64 }
65
66 #define DISPLAY_DELAY  20 /* ms to delay between ops - could be tweaked */
67 void display_reset() {
68         /* lower the reset line for a while */
69         bclr((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
70         delay(DISPLAY_DELAY);
71         bset((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
72         delay(DISPLAY_DELAY);
73
74         spi_enable();
75
76         display_send_byte(0xC0 | 10);    /* tell the controller there are 10 digits */
77         //display_send_byte(0xE0);    /* set duty cycle to 0%                  */
78         display_send_byte(0xFF);    /* set duty cycle to 100%                */
79
80         spi_disable();
81 }
82
83 void display_init() {
84         display_reset();
85 }
86

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