1 | #include <avr/io.h>
|
2 | #include <avr/eeprom.h>
|
3 | #include <avr/interrupt.h>
|
4 |
|
5 | #include "Kam54g10_menueOSD.h"
|
6 | #include "Kam54g10_usart.h"
|
7 | #include "Kam54g10_CRC.h"
|
8 |
|
9 | //Zoom routine--------------
|
10 | #define BYTES_IN_COMMAND 19
|
11 | #define NR_ZOOM_COMMAND 655
|
12 |
|
13 | static unsigned short crc_16;
|
14 | static unsigned int ADIteiler=0;
|
15 |
|
16 | // Timer IInterrupt Initialisation
|
17 | void initall()
|
18 | {
|
19 | //interrupt
|
20 | TCNT0 = 5; //Set Timer/counter
|
21 | TIMSK |= (1<<TOIE0); //Enable Timer/counter0 overflow interrupt
|
22 | TCCR0 |= (1<<CS01);
|
23 | TCCR0 |= (1<<CS00); //Select the clock source to be used by the timer/counter --> CPU Takt --> 4MHz/64
|
24 | TIFR |= (1<<TOV0); //interrupt starts with each overflow
|
25 | }//End initall()
|
26 |
|
27 | //Interrupt Service Routine für AD Wandlung
|
28 | ISR(TIMER0_OVF_vect)
|
29 | {
|
30 | ADIteiler++; //clocks interrupt counter value on each ms
|
31 | if(ADIteiler >= 60) //Counter cycle for all ms 60
|
32 | {
|
33 | ADIteiler=0; //counter 0 set
|
34 |
|
35 | static unsigned char k; //static ist nur in dieser Funktion sichtbar
|
36 | static unsigned char i;
|
37 | static unsigned char j;
|
38 | static unsigned char zommValue = 0;
|
39 | unsigned char Zoom[NR_ZOOM_COMMAND][BYTES_IN_COMMAND];
|
40 |
|
41 | crc_16 = 0;
|
42 |
|
43 | for(k = 0; k < NR_ZOOM_COMMAND; k++ )
|
44 | {
|
45 |
|
46 |
|
47 | Zoom[k][0] = 0x02;
|
48 | Zoom[k][1] = 0x21;
|
49 | Zoom[k][2] = 0x45;
|
50 | Zoom[k][3] = 0x00;
|
51 | Zoom[k][4] = (unsigned char)(zommValue >>8);
|
52 | Zoom[k][5] = (unsigned char)zommValue & 0xFF;
|
53 | Zoom[k][6] = 0x00;
|
54 | Zoom[k][7] = 0x00;
|
55 | Zoom[k][8] = 0x00;
|
56 | Zoom[k][9] = 0x00;
|
57 | Zoom[k][10] = 0x00;
|
58 | Zoom[k][11] = 0x00;
|
59 | Zoom[k][12] = 0x00;
|
60 | Zoom[k][13] = 0x00;
|
61 | Zoom[k][14] = 0x00;
|
62 | Zoom[k][15] = 0x00;
|
63 | Zoom[k][16] = 0x00;
|
64 | Zoom[k][17] = 0x00;
|
65 | Zoom[k][18] = 0x00;
|
66 |
|
67 | for (i = 1; i < 17; i++ )
|
68 | crc_16 = update_crc_16(crc_16, Zoom[k][i]); //calculate crc for the command
|
69 |
|
70 | Zoom[k][i] = (unsigned char)(crc_16 >> 8); // add crc value to [17] and [18] Buf position
|
71 | Zoom[k][i+1] = (unsigned char)crc_16 & 0xFF;
|
72 |
|
73 |
|
74 | for (j = 0; j < BYTES_IN_COMMAND; j++ )
|
75 | UART_Putc( Zoom[k][j] );
|
76 |
|
77 | zommValue=zommValue+100;
|
78 | }
|
79 |
|
80 | }
|
81 | }//End ISR(TIMER0_OVF_vect)
|
82 |
|
83 | void Send_ZoomCommand( void )
|
84 | {
|
85 | initall();
|
86 | cli();
|
87 | sei();
|
88 | }
|
89 |
|
90 | //Main---------
|
91 | #include <stdlib.h>
|
92 | #include <avr/io.h>
|
93 | #include <util/delay.h>
|
94 | #include <avr/interrupt.h>
|
95 |
|
96 | #include "Kam54g10_Zoom.h"
|
97 |
|
98 | #define BYTES_IN_COMMAND 19
|
99 |
|
100 | unsigned int iState;
|
101 |
|
102 |
|
103 |
|
104 | int main(void)
|
105 | {
|
106 |
|
107 | DDRC = 0x00; // PORTB auf Eingang
|
108 | PORTC = 0xFF; // pull ups for key inputs PortD2 and portD3
|
109 |
|
110 | DDRB = 0xFF; // outputs for LEDs
|
111 | PORTB = 0x00; // LEDs off
|
112 |
|
113 | UART_Init();
|
114 |
|
115 | sei();
|
116 |
|
117 |
|
118 | iState = 0;
|
119 | for(;;)
|
120 | {
|
121 | if (iState != PINC) // Key state changed ?
|
122 | {
|
123 | _delay_ms(50); // dirty "debounce"
|
124 |
|
125 | PINC = PINC & 0xFF;
|
126 | if ((PINC & 0x01) == 0x00) // one key
|
127 | {
|
128 | Send_MenueCommand(0);
|
129 | PORTB = 0xFE;
|
130 | }
|
131 |
|
132 | else if ((PINC & 0x02) == 0x00) // other key
|
133 | {
|
134 | PORTB = 0xF7;
|
135 | Send_ZoomCommand();
|
136 | }
|
137 |
|
138 | else // no key
|
139 | {
|
140 | PORTB = 0xff;
|
141 | }
|
142 | iState = PINC;
|
143 | }
|
144 | }
|
145 |
|
146 | }
|