1 |
//Program pro vyzkouseni funkcnosti modulu s LCD a mikropocitacem ATmega8 |
1 |
//Program pro vyzkouseni funkcnosti modulu s LCD a mikropocitacem ATmega8 |
2 |
//MLAB 21.11.2011 (JACHO) |
2 |
//MLAB 21.11.2011 (JACHO) |
3 |
|
3 |
|
4 |
//vytvoreno v programu AVR studio 4 |
4 |
//vytvoreno v programu AVR studio 4 |
5 |
|
5 |
|
6 |
//Propojení pinù modulu s LCD a ATmega8 (jejich nastavení se provádí v lcd.h) |
6 |
//Propojení pinù modulu s LCD a ATmega8 (jejich nastavení se provádí v lcd.h) |
7 |
//PIN_D0 PC3 |
7 |
//PIN_D0 PC3 |
8 |
//PIN_D1 PB4 |
8 |
//PIN_D1 PB4 |
9 |
//PIN_D2 PB5 |
9 |
//PIN_D2 PB5 |
10 |
//PIN_D3 PB3 |
10 |
//PIN_D3 PB3 |
11 |
//PIN_E PB1 |
11 |
//PIN_E PB1 |
12 |
//PIN_RS PB2 |
12 |
//PIN_RS PB2 |
13 |
|
13 |
|
- |
|
14 |
|
- |
|
15 |
//pri spravne funkci se na LCD zobrazi na prvem a druhem radku LCD je OK |
- |
|
16 |
//je dulezite spravne propojit modulu, napajet je a mit spravne nastaveny konstrast (pro zacatek potenciometr do prostred drahy) |
- |
|
17 |
|
14 |
#include <avr/io.h> |
18 |
#include <avr/io.h> |
15 |
#include <stdio.h> |
19 |
#include <stdio.h> |
16 |
#include <avr/iom8.h> |
20 |
#include <avr/iom8.h> |
17 |
#include "lcd.h" |
21 |
#include "lcd.h" |
18 |
#include "lcd.c" |
22 |
#include "lcd.c" |
19 |
#include <util/delay.h> |
23 |
#include <util/delay.h> |
20 |
|
24 |
|
21 |
|
25 |
|
22 |
#define MAXDISPLBUFFER 20 //buffer pro lcd display |
26 |
#define MAXDISPLBUFFER 20 //buffer pro lcd display |
23 |
|
27 |
|
24 |
|
28 |
|
25 |
//----------------------------------------------------------------------------- |
29 |
//----------------------------------------------------------------------------- |
26 |
|
30 |
|
27 |
int main(void) |
31 |
int main(void) |
28 |
{ |
32 |
{ |
29 |
|
33 |
|
30 |
LCD_init(); //Inicializace LCD |
34 |
LCD_init(); //Inicializace LCD |
31 |
|
35 |
|
32 |
char zasobnik[19]; |
36 |
char zasobnik[19]; |
33 |
|
37 |
|
34 |
sprintf(zasobnik,"LCD je OK"); //vlozi text do zasobnik |
38 |
sprintf(zasobnik,"LCD je OK"); //vlozi text do zasobnik |
35 |
LCD_gotoxy(0,0); //definuje kam se zacne zapisovat na LCD |
39 |
LCD_gotoxy(0,0); //definuje kam se zacne zapisovat na LCD |
36 |
ProcesDispl(zasobnik); |
40 |
ProcesDispl(zasobnik); |
37 |
LCD_gotoxy(0,2); |
41 |
LCD_gotoxy(0,2); |
38 |
ProcesDispl(zasobnik); |
42 |
ProcesDispl(zasobnik); |
39 |
_delay_ms(1); |
43 |
_delay_ms(1); |
40 |
|
44 |
|
41 |
|
45 |
|
42 |
return 0; |
46 |
return 0; |
43 |
|
47 |
|
44 |
|
48 |
|
45 |
|
49 |
|
46 |
} |
50 |
} |
47 |
|
51 |
|
48 |
void ProcesDispl(char *data) //zajiuje tisk øetìzce na lcd |
52 |
void ProcesDispl(char *data) //zajiuje tisk øetìzce na lcd |
49 |
{ |
53 |
{ |
50 |
uint8_t a,b; |
54 |
uint8_t a,b; |
51 |
|
55 |
|
52 |
for (a=0;a<MAXDISPLBUFFER;a++) |
56 |
for (a=0;a<MAXDISPLBUFFER;a++) |
53 |
{ |
57 |
{ |
54 |
switch (*(data+a)) |
58 |
switch (*(data+a)) |
55 |
{ |
59 |
{ |
56 |
case 0: *data = 0;return; |
60 |
case 0: *data = 0;return; |
57 |
case '\n': LCD_gotoxy(1,2);break; //posun na druhej øádek |
61 |
case '\n': LCD_gotoxy(1,2);break; //posun na druhej øádek |
58 |
case '\r': LCD_gotoxy(1,1);break; |
62 |
case '\r': LCD_gotoxy(1,1);break; |
59 |
case '\a': LCD_gotoxy(6,2);break; //posun na 2.øádek 6.políèko |
63 |
case '\a': LCD_gotoxy(6,2);break; //posun na 2.øádek 6.políèko |
60 |
case '\f': LCD_gotoxy(1,1); |
64 |
case '\f': LCD_gotoxy(1,1); |
61 |
for (b=0;b<8;b++) LCD_putc(0x20); |
65 |
for (b=0;b<8;b++) LCD_putc(0x20); |
62 |
LCD_gotoxy(1,2); |
66 |
LCD_gotoxy(1,2); |
63 |
for (b=0;b<8;b++) LCD_putc(0x20); |
67 |
for (b=0;b<8;b++) LCD_putc(0x20); |
64 |
LCD_gotoxy(1,1); |
68 |
LCD_gotoxy(1,1); |
65 |
break; |
69 |
break; |
66 |
default : LCD_putc(*(data+a)); |
70 |
default : LCD_putc(*(data+a)); |
67 |
} |
71 |
} |
68 |
} |
72 |
} |
69 |
*data = 0; |
73 |
*data = 0; |
70 |
} |
74 |
} |