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

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [Clib/] [dvc_lib.c] - Blame information for rev 60

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
 
15 10 mcupro
#include "dvc_lib.h"
16
void __inline dis_byte(unsigned char data)
17
{
18
    SEG7LED=data ;
19
}
20
 
21
void dly_us(unsigned int us)
22
{
23
    int i ;
24
    while(us--)
25
    {
26
        i=FRQ/1000000/3-2 ;
27
        while(i--);
28
        //delay 1us
29
    }
30
}
31
 
32 15 mcupro
void dly_ms(unsigned int ms)
33
{
34
    int i ,us=1000*ms;
35
    while(us--)
36
    {
37
        i=12;
38
        while(i--);
39
    }
40
}
41
 
42 10 mcupro
void uart0_putc(unsigned char data)
43
{
44
    while((STATUS&(1<<2))!=0);
45
    UART0_DATA=data ;
46
}
47
unsigned char uart0_getc(void)
48
{
49
    unsigned char ret=0 ;
50
    while((STATUS&(1<<3))==0);
51
    ret=UART0_DATA ;
52
    set_bit(CMD,1);
53
    set_bit(CMD,1);
54
    clr_bit(CMD,1);
55
    return ret ;
56
}
57
unsigned char enqire_rxd(void)
58
{
59
    return(STATUS&(1<<3))?1:0 ;
60
}
61
 
62
void uart0_putstr(char*str)
63
{
64 35 mcupro
    while(1){
65
    if(*str=='\0')return ;
66
    else if(*str=='\n')
67
        {
68
                uart0_putc('\r');
69
                uart0_putc(*str++);
70
        }
71
        else
72
                uart0_putc(*str++);
73
                }
74 10 mcupro
}
75
 
76
void __inline led1_on(void)
77
{
78
    CMD=CMD&(~(1<<5));
79
}
80
void __inline led1_off(void)
81
{
82
    CMD=CMD|(1<<5);
83
}
84
void __inline led2_on(void)
85
{
86
    CMD=CMD&(~(1<<6));
87
}
88
void __inline led2_off(void)
89
{
90
    CMD=CMD|(1<<6);
91
}
92
 
93
//lcd part
94
 
95
void LCD_init(void)
96
{
97
    char i=3 ;
98
    CLEARSCREEN ;
99
    //clear screen
100
    while(i--)
101
    {
102
        LCD_en_command(DATA_MODE);
103
        //set 8 bit data transmission mode
104
        dly_us(LCD_INIT_US);
105
    }
106
    LCD_en_command(OPEN_SCREEN);
107
    //open display (enable lcd display)
108
    dly_us(LCD_DLY_US);
109
    LCD_en_command(DISPLAY_ADDRESS);
110
    //set lcd first display address
111
    dly_us(LCD_DLY_US);
112
    CLEARSCREEN ;
113
    //clear screen
114
    dly_us(LCD_DLY_US);
115
}
116
 
117
void LCD_en_command(unsigned char command)
118
{
119
    LCDDATA=command ;
120
    clr_bit(CMD,2);
121
    // LCD1602_RS=LOW;
122
    clr_bit(CMD,3);
123
    //LCD1602_RW=LOW;
124
    clr_bit(CMD,4);
125
    //LCD1602_EN=LOW;
126
    dly_us(LCD_DLY_US);
127
    set_bit(CMD,4);
128
    //LCD1602_EN=HIGH;
129
}
130
 
131
void LCD_en_dat(unsigned char dat)
132
{
133
    LCDDATA=dat ;
134
    set_bit(CMD,2);
135
    //LCD1602_RS=HIGH;
136
    clr_bit(CMD,3);
137
    //LCD1602_RW=LOW;
138
    clr_bit(CMD,4);
139
    //LCD1602_EN=LOW;
140
    dly_us(LCD_DLY_US);
141
    set_bit(CMD,4);
142
    //LCD1602_EN=HIGH;
143
}
144
 
145
void LCD_set_xy(unsigned char x,unsigned char y)
146
{
147
    unsigned char address ;
148
    if(y==LINE1)
149
    address=LINE1_HEAD+x ;
150
    else
151
    address=LINE2_HEAD+x ;
152
    LCD_en_command(address);
153
}
154
 
155
void LCD_write_char(unsigned x,unsigned char y,unsigned char dat)
156
{
157
    LCD_set_xy(x,y);
158
    LCD_en_dat(dat);
159
}
160
 
161
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char*s)
162
{
163
    LCD_set_xy(X,Y);
164
    while(*s)
165
    {
166
        LCD_en_dat(*s++);
167
    }
168
}
169
 
170
void download()
171
{
172
    unsigned char*addr=(void*)0 ;
173 15 mcupro
    uart0_putstr((char*)"This is MIPS789 BOOTLOADER\n");
174 10 mcupro
    dis_byte(0xcc);
175
    //attenions please'!'
176 35 mcupro
    while(uart0_getc()!='!');
177
    uart0_putc((unsigned char)('O'));
178 10 mcupro
    //'O'k .i am ready
179
    while(1)
180
    {
181
        *addr=(unsigned char)uart0_getc();
182
        dis_byte((unsigned char)(*addr++));
183
    }
184
}
185
 
186
void tmr_en(unsigned int cntr)
187
{
188
    set_bit(CMD,8);
189
    TMR_DATA=cntr ;
190
    tmr_clr();
191
}
192
 
193
void tmr_disen(void)
194
{
195
    clr_bit(CMD,8);
196
    clr_bit(CMD,7);
197
}
198
 
199
void tmr_clr(void)
200
{
201
    set_bit(CMD,7);
202
    set_bit(CMD,7);
203
    clr_bit(CMD,7);
204
    clr_bit(CMD,7);
205
}
206
 
207
unsigned int  read_tmr()
208
{
209
    return TMR_DATA ;
210
}
211
 
212
 
213
unsigned char get_key1()
214
{
215 15 mcupro
    return(STATUS&1)?0:1 ;
216 10 mcupro
}
217
 
218
unsigned char get_key2()
219
{
220 15 mcupro
    return(STATUS&(1<<1))?0:1 ;
221 10 mcupro
}

powered by: WebSVN 2.1.0

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