OpenCores
URL https://opencores.org/ocsvn/mips32r1/mips32r1/trunk

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Software/] [demos/] [XD4_UART/] [src/] [drivers/] [lcd.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ayersg
#include "lcd.h"
2
 
3
static uint8_t LCD_position = 0;
4
static uint8_t LCD_autoIncr = 1;
5
 
6
static void LCD_incrPos(uint32_t amount)
7
{
8
        if (LCD_autoIncr == 0) {
9
                return;
10
        }
11
        while (amount > 32) {
12
                amount -= 32;
13
        }
14
        LCD_position += (uint8_t)amount;
15
        if (LCD_position >= 32) {
16
                LCD_position -= 32;
17
        }
18
}
19
 
20
 
21
void LCD_clear(void)
22
{
23
        volatile uint32_t *LCD;
24
        int i;
25
 
26
        LCD = (volatile uint32_t *)LCD_ADDRESS;
27
 
28
        for (i=0; i<8; i++) {
29
                LCD[i] = 0x20202020;
30
        }
31
        LCD_position = 0;
32
}
33
 
34
void LCD_setPos(uint8_t position)
35
{
36
        LCD_position = position;
37
}
38
 
39
uint8_t LCD_getPos(void)
40
{
41
        return LCD_position;
42
}
43
 
44
void LCD_setAutoIncr(uint8_t incr)
45
{
46
        LCD_autoIncr = incr;
47
}
48
 
49
void LCD_printByte(uint8_t byte)
50
{
51
        volatile uint8_t *LCD;
52
 
53
        LCD = (volatile uint8_t *)(LCD_ADDRESS + LCD_position);
54
        *LCD = byte;
55
        LCD_incrPos(1);
56
}
57
 
58
void LCD_printByteHex(uint8_t byte)
59
{
60
        volatile uint8_t *LCD;
61
        uint8_t nibble_h, nibble_l;
62
 
63
        LCD = (volatile uint8_t *)(LCD_ADDRESS + LCD_position);
64
        nibble_h = byte >> 4;
65
        nibble_l = byte & 0x0f;
66
 
67
        if (nibble_h < 10) {
68
                nibble_h += 48;
69
        }
70
        else {
71
                nibble_h += 55;
72
        }
73
        if (nibble_l < 10) {
74
                nibble_l += 48;
75
        }
76
        else {
77
                nibble_h += 55;
78
        }
79
        *LCD = nibble_h;
80
        LCD++;
81
        *LCD = nibble_l;
82
        LCD_incrPos(2);
83
}
84
 
85
void LCD_printByteDec(uint8_t byte)
86
{
87
        volatile uint8_t *LCD;
88
        uint8_t hundreds, tens, ones;
89
        uint32_t n_printed = 1;
90
 
91
        LCD = (volatile uint8_t *)(LCD_ADDRESS + LCD_position);
92
        hundreds = tens = ones = 48;
93
 
94
        while (byte >= 100) {
95
                hundreds++;
96
                byte -= 100;
97
        }
98
        while (byte >= 10) {
99
                tens++;
100
                byte -= 10;
101
        }
102
        while (byte >= 1) {
103
                ones++;
104
                byte -= 1;
105
        }
106
        if (hundreds > 48) {
107
                *LCD = hundreds;
108
                LCD++;
109
                n_printed++;
110
        }
111
        if ((n_printed > 1) || (tens > 48)) {
112
                *LCD = tens;
113
                LCD++;
114
                n_printed++;
115
        }
116
        *LCD = ones;
117
        LCD_incrPos(n_printed);
118
}
119
 
120
void LCD_printWord(uint32_t word)
121
{
122
        volatile uint32_t *LCD;
123
 
124
        LCD = (volatile uint32_t *)(LCD_ADDRESS + LCD_position);
125
        *LCD = word;
126
        LCD_incrPos(4);
127
}
128
 
129
void LCD_printString(char *string)
130
{
131
        volatile char *LCD;
132
        int i = 0;
133
 
134
        LCD = (volatile char *)(LCD_ADDRESS + LCD_position);
135
 
136
        while (string[i] != '\0') {
137
                LCD[i] = string[i];
138
                i++;
139
        }
140
        LCD_incrPos(i);
141
}
142
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.