Statistics
| Revision:

root / trunk / tp_info6 / bsp / lcd.c @ 2

History | View | Annotate | Download (1.61 KB)

1
#ifdef M32C87
2
        #include "sfr32c87.h"
3
        #define LCD_RS p3_0
4
        #define LCD_RW p3_1
5
        #define LCD_E  p3_2
6

    
7
        #define LCD_DATA(x) p3= (x & 0xF0) | (p3 & 0x0F);
8
        #define dLCD_DATA pd3=0xF0 | pd3;
9

    
10
        #define dLCD_RS        pd3_0
11
        #define dLCD_RW        pd3_1
12
        #define dLCD_E        pd3_2        
13
#endif
14

    
15
#ifdef M32C83
16
        #include "sfr32c83.h"
17
        #define LCD_RS p3_0
18
        #define LCD_RW p3_1
19
        #define LCD_E  p3_2
20

    
21
        #define LCD_DATA(x) p3= x;
22
        #define dLCD_DATA pd3=0xFF;
23

    
24
        #define dLCD_RS        pd3_0
25
        #define dLCD_RW        pd3_1
26
        #define dLCD_E        pd3_2                
27
#endif
28

    
29
#include "lcd.h"
30

    
31

    
32
#ifdef M32C87
33
void lcd_car(char c)
34
{
35
        LCD_DATA (c);
36
    LCD_E=1;
37
    delay(10);
38
           LCD_E=0;
39
           delay(10);
40

    
41
           LCD_DATA(c<<4);
42
    LCD_E=1;
43
           delay(10);
44
    LCD_E=0;
45
           delay(10);
46
}
47
#endif
48

    
49

    
50
#ifdef M32C83
51
void lcd_car(char c)
52
{
53
        LCD_DATA (c);
54
    LCD_E=1;
55
    delay(10);
56
           LCD_E=0;
57
           delay(10);
58
}
59
#endif
60

    
61

    
62

    
63
void lcd_com(char c)
64
{
65
   LCD_RS=0;
66
   lcd_car(c);
67
}
68

    
69

    
70
void lcd_putc(char c)
71
{
72
   LCD_RS=1;
73
   lcd_car(c);
74
}
75

    
76
void lcd_str(char far *p)
77
{
78
char c;
79
        while (c=*p++)
80
                lcd_putc(c);        
81
}
82

    
83
void lcd_cls(void)
84
{
85
        lcd_com(0x01);
86
        delay(100);
87
}
88

    
89

    
90
void lcd_init()
91
{
92

    
93
        dLCD_E=1;
94
        dLCD_RS=1;
95
        dLCD_RW=1;
96
        dLCD_DATA;
97

    
98
        LCD_RW=0;
99
        LCD_RS=0;
100
        LCD_E=0;
101

    
102
   lcd_com(0x33); //init 4 bit
103
   delay(5000);
104
   lcd_com(0x32); // reset 4 bits
105
   delay(100);
106
   lcd_com(0x28);
107
   delay(100);   
108
   lcd_com(0x28);
109
   delay(100);   
110
   lcd_com(0x06);
111
   delay(100);   
112
   lcd_com(0x0E);
113
   lcd_com(0x01);
114
   delay(100);   
115
   lcd_com(0x80);
116
   delay(100);   
117
}
118

    
119
void delay (int n)
120
{
121
int i;
122

    
123
        for  (i=0;i<n*60;i++);
124
}