1 | /*****************************************************
|
2 | Chip type : ATmega8515
|
3 | Program type : Application
|
4 | Clock frequency : 3,579000 MHz
|
5 | Memory model : Small
|
6 | External SRAM size : 0
|
7 | Data Stack size : 128
|
8 | *****************************************************/
|
9 |
|
10 | #include <mega8515.h>
|
11 | #include <delay.h>
|
12 |
|
13 | // Alphanumeric LCD Module functions
|
14 | #asm
|
15 | .equ __lcd_port=0x1B ;PORTA
|
16 | #endasm
|
17 | #include <lcd.h>
|
18 |
|
19 | // External Interrupt 0 service routine
|
20 | interrupt [EXT_INT0] void ext_int0_isr(void)
|
21 | {
|
22 | // Place your code here
|
23 |
|
24 | }
|
25 |
|
26 | // Declare your global variables here
|
27 | unsigned char i;
|
28 | reset();
|
29 | void main(void)
|
30 | {
|
31 | // Declare your local variables here
|
32 |
|
33 | // Input/Output Ports initialization
|
34 | // Port A initialization
|
35 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
|
36 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
|
37 | PORTA=0x00;
|
38 | DDRA=0x00;
|
39 |
|
40 | // Port B initialization
|
41 | // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
|
42 | // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
|
43 | PORTB=0x00;
|
44 | DDRB=0xFF;
|
45 |
|
46 | // Port C initialization
|
47 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
|
48 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
|
49 | PORTC=0x00;
|
50 | DDRC=0x00;
|
51 |
|
52 | // Port D initialization
|
53 | // Func7=In Func6=Out Func5=Out Func4=Out Func3=Out Func2=In Func1=Out Func0=Out
|
54 | // State7=P State6=0 State5=0 State4=0 State3=0 State2=P State1=0 State0=0
|
55 | PORTD=0x84;
|
56 | DDRD=0x7B;
|
57 |
|
58 | // Port E initialization
|
59 | // Func2=Out Func1=Out Func0=Out
|
60 | // State2=0 State1=0 State0=0
|
61 | PORTE=0x00;
|
62 | DDRE=0x07;
|
63 |
|
64 | // Timer/Counter 0 initialization
|
65 | // Clock source: System Clock
|
66 | // Clock value: Timer 0 Stopped
|
67 | // Mode: Normal top=FFh
|
68 | // OC0 output: Disconnected
|
69 | TCCR0=0x00;
|
70 | TCNT0=0x00;
|
71 | OCR0=0x00;
|
72 |
|
73 | // Timer/Counter 1 initialization
|
74 | // Clock source: System Clock
|
75 | // Clock value: Timer 1 Stopped
|
76 | // Mode: Normal top=FFFFh
|
77 | // OC1A output: Discon.
|
78 | // OC1B output: Discon.
|
79 | // Noise Canceler: Off
|
80 | // Input Capture on Falling Edge
|
81 | // Timer 1 Overflow Interrupt: Off
|
82 | // Input Capture Interrupt: Off
|
83 | // Compare A Match Interrupt: Off
|
84 | // Compare B Match Interrupt: Off
|
85 | TCCR1A=0x00;
|
86 | TCCR1B=0x00;
|
87 | TCNT1H=0x00;
|
88 | TCNT1L=0x00;
|
89 | ICR1H=0x00;
|
90 | ICR1L=0x00;
|
91 | OCR1AH=0x00;
|
92 | OCR1AL=0x00;
|
93 | OCR1BH=0x00;
|
94 | OCR1BL=0x00;
|
95 |
|
96 | // External Interrupt(s) initialization
|
97 | // INT0: On
|
98 | // INT0 Mode: Low level
|
99 | // INT1: Off
|
100 | // INT2: Off
|
101 | GICR|=0x00; //40
|
102 | MCUCR=0x00;
|
103 | EMCUCR=0x00;
|
104 | GIFR=0x00; //40
|
105 |
|
106 | // Timer(s)/Counter(s) Interrupt(s) initialization
|
107 | TIMSK=0x00;
|
108 |
|
109 | // Analog Comparator initialization
|
110 | // Analog Comparator: Off
|
111 | // Analog Comparator Input Capture by Timer/Counter 1: Off
|
112 | ACSR=0x80;
|
113 | delay_ms(100);
|
114 | PORTB.1=0; //RS0
|
115 | PORTB.0=1; //RD
|
116 | PORTB.3=1; //WR
|
117 | PORTB.2=1; //CS
|
118 |
|
119 | // LCD module initialization
|
120 | lcd_init(16);
|
121 | lcd_clear();lcd_gotoxy(3,0);lcd_putsf("Systemstart");
|
122 | PORTE.0=1;delay_ms(3000);
|
123 | lcd_clear();
|
124 | // Global enable interrupts
|
125 | #asm("sei")
|
126 | PORTE.0=0;
|
127 | i=0;
|
128 | //PORTD.4=1; //relais K3 an
|
129 | PORTB.1=0;//RS0
|
130 | PORTB.0=1;//RD
|
131 | PORTB.3=1;//WR
|
132 | PORTB.2=1;//CS
|
133 | while (1)
|
134 | {
|
135 |
|
136 | if(PIND.7==0)//taster
|
137 | {
|
138 | PORTC = 0b00001011;
|
139 | PORTB.1=1; //RS0
|
140 | PORTB.2=0; //CS
|
141 | PORTB.3=0; //WR
|
142 | #asm
|
143 | nop
|
144 | nop
|
145 | nop
|
146 | #endasm
|
147 | PORTB.3=1; //WR
|
148 | PORTB.2=1; //CS
|
149 | delay_ms(2);
|
150 | PORTC = 0b00001000;
|
151 | PORTB.2=0; //CS
|
152 | PORTB.3=0; //WR
|
153 | #asm
|
154 | nop
|
155 | nop
|
156 | nop
|
157 | #endasm
|
158 | PORTB.3=1; //WR
|
159 | PORTB.2=1; //CS
|
160 | PORTB.1=0; //RS0
|
161 | delay_ms(100);
|
162 |
|
163 | }
|
164 |
|
165 |
|
166 | //PORTE.0=1; //gelb
|
167 | //PORTE.1=1; //grün
|
168 | //PORTE.2=1; //blau
|
169 |
|
170 | };
|
171 | }
|
172 | //--------------------------------unterprogramme-------------------------------------------------------------------------------------
|
173 | reset()
|
174 | {
|
175 | PORTE.2=1; //blau an test !!!
|
176 | PORTC=0x00;DDRC=0xFF;//portc ausgang
|
177 |
|
178 | PORTC=0b00001011;
|
179 | PORTB.1=1;//rs0
|
180 | PORTB.2=0;//cs
|
181 | PORTB.3=0;//WR
|
182 | delay_ms(2);
|
183 | PORTB.3=1;//WR
|
184 | PORTB.2=1;//cs
|
185 | PORTB.1=0;//rs0
|
186 | PORTE.2=0; //blau aus test !!!!
|
187 | }
|