SHOW:
|
|
- or go back to the newest paste.
1 | /**************************************/ | |
2 | /* ARE 2008 */ | |
3 | /* e-mail: biuro@are.net.pl */ | |
4 | /* www : are.net.pl */ | |
5 | /**************************************/ | |
6 | ||
7 | #define F_CPU 8000000UL // 1 MHz | |
8 | //#define F_CPU 14.7456E6 | |
9 | #include <avr/io.h> | |
10 | #include <stdio.h> | |
11 | #include <util/delay.h> | |
12 | #include <string.h> | |
13 | ||
14 | void delay_ms(int ms) | |
15 | { | |
16 | volatile long unsigned int i; | |
17 | for(i=0;i<ms;i++) | |
18 | _delay_ms(1); | |
19 | } | |
20 | ||
21 | void delay_us(int us) | |
22 | { | |
23 | volatile long unsigned int i; | |
24 | for(i=0;i<us;i++) | |
25 | _delay_us(1); | |
26 | } | |
27 | ||
28 | //RS PA0 | |
29 | //RW PA1 | |
30 | //E PA2 | |
31 | //DATA PD | |
32 | ||
33 | #define RS 0 | |
34 | #define RW 1 | |
35 | #define E 2 | |
36 | ||
37 | void LCD2x16_init(void) | |
38 | { | |
39 | PORTC &= ~(1<<RS); | |
40 | PORTC &= ~(1<<RW); | |
41 | ||
42 | PORTC |= (1<<E); | |
43 | PORTD = 0x38; // dwie linie, 5x7 punktow | |
44 | PORTC &=~(1<<E); | |
45 | _delay_us(120); | |
46 | ||
47 | PORTC |= (1<<E); | |
48 | PORTD = 0x0e; // wlacz wyswietlacz, kursor, miganie | |
49 | PORTC &=~(1<<E); | |
50 | _delay_us(120); | |
51 | ||
52 | PORTC |= (1<<E); | |
53 | PORTD = 0x06; | |
54 | PORTC &=~(1<<E); | |
55 | _delay_us(120); | |
56 | } | |
57 | ||
58 | void LCD2x16_clear(void){ | |
59 | PORTC &= ~(1<<RS); | |
60 | PORTC &= ~(1<<RW); | |
61 | ||
62 | PORTC |= (1<<E); | |
63 | PORTD = 0x01; | |
64 | PORTC &=~(1<<E); | |
65 | delay_ms(120); | |
66 | } | |
67 | ||
68 | void LCD2x16_putchar(int data) | |
69 | { | |
70 | PORTC |= (1<<RS); | |
71 | PORTC &= ~(1<<RW); | |
72 | ||
73 | PORTC |= (1<<E); | |
74 | PORTD = data; | |
75 | PORTC &=~(1<<E); | |
76 | _delay_us(120); | |
77 | } | |
78 | ||
79 | void LCD2x16_pos(int wiersz, int kolumna) | |
80 | { | |
81 | PORTC &= ~(1<<RS); | |
82 | PORTC &= ~(1<<RW); | |
83 | ||
84 | PORTC |= (1<<E); | |
85 | delay_ms(1); | |
86 | PORTD = 0x80+(wiersz-1)*0x40+(kolumna-1); | |
87 | delay_ms(1); | |
88 | PORTC &=~(1<<E); | |
89 | _delay_us(120); | |
90 | } | |
91 | ||
92 | ||
93 | ||
94 | int main(void){ | |
95 | char www[16] = "www-> are.net.pl"; | |
96 | char email[16] = "biuro@are.net.pl"; | |
97 | char tmp[17]; | |
98 | char tmp1[17]; | |
99 | int sp=60; | |
100 | int h= 8; | |
101 | int pv=51; | |
102 | int e=0; | |
103 | ||
104 | ||
105 | ||
106 | ||
107 | int i; | |
108 | int j=4; | |
109 | ||
110 | DDRD = 0xff; | |
111 | PORTD = 0x00; | |
112 | DDRC = 0xff; | |
113 | PORTC = 0x00; | |
114 | DDRB = 0xff; | |
115 | PORTB = 0xff; | |
116 | ||
117 | ADMUX=0x40; | |
118 | ||
119 | ||
120 | _delay_ms(200); | |
121 | ||
122 | ||
123 | LCD2x16_init(); | |
124 | LCD2x16_clear(); | |
125 | ||
126 | delay_ms(20); | |
127 | ||
128 | ||
129 | ||
130 | ||
131 | /* for(i=0;i < 16;i++) | |
132 | LCD2x16_putchar(www[i]); | |
133 | LCD2x16_pos(2,1); | |
134 | for(i=0;i < 16;i++) | |
135 | LCD2x16_putchar(email[i]); | |
136 | ||
137 | delay_ms(3000); | |
138 | LCD2x16_clear(); | |
139 | for(i=0;i < 16;i++) | |
140 | LCD2x16_putchar(www[i]);*/ | |
141 | ||
142 | while(1) | |
143 | { | |
144 | ||
145 | if(~PINB & 0x01) | |
146 | sp=50; | |
147 | if(~PINB & 0x02) | |
148 | sp=40; | |
149 | if(~PINB & 0x04) | |
150 | h=4; | |
151 | if(~PINB & 0x08) | |
152 | h=10; | |
153 | //LCD2x16_clear(); | |
154 | ||
155 | e=sp-pv; | |
156 | sprintf(tmp1,"SP=%2dp PV=%2dC", sp, pv); | |
157 | LCD2x16_pos(2,1); | |
158 | sprintf(tmp,"H=%2dp E=%3dC",h, e); | |
159 | for(i=0;i < 16;i++) | |
160 | LCD2x16_putchar(tmp[i]); | |
161 | LCD2x16_pos(1,1); | |
162 | for(i=0;i < 16;i++) | |
163 | LCD2x16_putchar(tmp1[i]); | |
164 | delay_ms(100); | |
165 | } | |
166 | ||
167 | return 0; | |
168 | } |