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

Subversion Repositories mips32r1

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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