Line No. | Rev | Author | Line |
---|---|---|---|
1 | 3 | kaklik | //////////////////////////////////////////////////////////////// |
2 | // Program pro otestovani funkci knihovny KBD.C |
||
3 | // Jde o pouziti funkci pod prerusovacimi rutinami |
||
4 | //////////////////////////////////////////////////////////////// |
||
5 | // |
||
6 | // (c) PEFI 2003 |
||
7 | // Verze 0.00 - uvodni verze |
||
8 | // |
||
9 | //////////////////////////////////////////////////////////////// |
||
10 | |||
11 | |||
12 | #include <16F876.h> |
||
13 | #use delay(clock=4000000) |
||
14 | #fuses XT,NOBROWNOUT,NOPROTECT,NOLVP,NOWDT |
||
15 | |||
16 | // prepinace programu |
||
17 | #define FCE_GETC |
||
18 | //#define FCE_WAITC // pouzijeme funkci, ktera ceka na klavesu a spi |
||
19 | //#define FCE_TIMEOUTC // pouzije funkci, ktera ceka na klavesu jen po urcitou dobu |
||
20 | |||
21 | // LCD Display |
||
22 | #define LCD_RS PIN_B2 // rizeni registru LCD displeje |
||
23 | #define LCD_E PIN_B3 // enable LCD displeje |
||
24 | #define LCD_DATA_LSB PIN_A0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
||
25 | #include <lcd.c> |
||
26 | |||
27 | |||
28 | // klavesnice |
||
29 | #include <kbd.c> |
||
30 | |||
31 | |||
32 | |||
33 | |||
34 | // prerusovaci rutina od zmeny na klavesnici |
||
35 | // |
||
36 | #int_RB |
||
37 | void RB_handler() |
||
38 | { |
||
39 | kbd_pullkbd(); |
||
40 | } |
||
41 | |||
42 | |||
43 | |||
44 | // perusovaci rutina pro odmerovani doby zakmitu a timeoutu |
||
45 | #int_timer1 |
||
46 | void timer0_handler() |
||
47 | { |
||
48 | kbd_ticktimer(); |
||
49 | set_timer1(-600l); // nastaven tik po 10ms |
||
50 | } |
||
51 | |||
52 | |||
53 | /****************************************/ |
||
54 | /********* HLAVNI SMYCKA ****************/ |
||
55 | /****************************************/ |
||
56 | |||
57 | void main() { |
||
58 | |||
59 | int c; |
||
60 | |||
61 | setup_timer_1(T1_EXTERNAL | T1_CLK_OUT ); // povol oscilator na timeru1, slouzi k mereni casu i behem spanku |
||
62 | enable_interrupts(INT_TIMER1); |
||
63 | enable_interrupts(INT_RB); |
||
64 | |||
65 | lcd_init(); |
||
66 | kbd_init(); |
||
67 | enable_interrupts(GLOBAL); |
||
68 | |||
69 | #ifdef FCE_GETC |
||
70 | printf(lcd_putc,"Int: kbd_getc "); |
||
71 | #endif |
||
72 | #ifdef FCE_WAITC |
||
73 | printf(lcd_putc,"Int: kbd_waitc "); |
||
74 | #endif |
||
75 | #ifdef FCE_TIMEOUTC |
||
76 | printf(lcd_putc,"Int:kbd_timeoutc"); |
||
77 | #endif |
||
78 | |||
79 | while(1) |
||
80 | { |
||
81 | #ifdef FCE_GETC |
||
82 | c=kbd_getc(); |
||
83 | #endif |
||
84 | |||
85 | #ifdef FCE_WAITC |
||
86 | c=kbd_waitc(); |
||
87 | #endif |
||
88 | |||
89 | #ifdef FCE_TIMEOUTC |
||
90 | delay_ms(1000); |
||
91 | lcd_gotoxy(1,2); |
||
92 | printf(lcd_putc,"Ceka na stisk "); |
||
93 | c=kbd_timeoutc(1000); // timeout nastaven na cca 10s |
||
94 | #endif |
||
95 | |||
96 | if (c!=0) |
||
97 | { |
||
98 | lcd_gotoxy(1,2); |
||
99 | printf(lcd_putc,"Stisknuto %2X ",c); // vypise kod klavesy |
||
100 | } |
||
101 | #ifdef FCE_TIMEOUTC |
||
102 | else { |
||
103 | lcd_gotoxy(1,2); |
||
104 | printf(lcd_putc,"timeout vyprsel "); // vypie kod klavesy |
||
105 | } |
||
106 | #endif |
||
107 | } |
||
108 | } |
||
109 | |||
110 | // End of File |
Powered by WebSVN v2.8.3