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