main.c
1 | #include <asf.h>
| 2 | #include <avr/io.h>
| 3 | #include <stdlib.h>
| 4 | #include "lcd.h"
| 5 | #define F_CPU 16000000
| 6 | #include <util/delay.h>
| 7 | #include <avr/interrupt.h>
| 8 | #include <avr/eeprom.h>
| 9 | #include <stdint.h>
| 10 | #include <stdio.h>
| 11 | #include <inttypes.h>
| 12 | #include <string.h>
| 13 |
| 14 | char masch1 [12];
| 15 | int z1=-1;
| 16 | int z2=-1;
| 17 | int z3=-1;
| 18 | int z4=-1;
| 19 | int z5=-1;
| 20 | int z6=-1;
| 21 | int z7=-1;
| 22 | int z8=-1;
| 23 | int z9=-1;
| 24 | int z10=-1;
| 25 | char z11=-1;
| 26 | char zr='/r';
| 27 | char z=0;
| 28 | unsigned char nummernPos=20;
| 29 | int menueUeb =0;
| 30 |
| 31 |
| 32 | static int lcd_putchar (char c, FILE *stream){
| 33 | lcd_data(c);
| 34 | return 0;
| 35 | }
| 36 |
| 37 | static FILE mystdout = FDEV_SETUP_STREAM(lcd_putchar, NULL,_FDEV_SETUP_WRITE);
| 38 |
| 39 | void zahl1 (){
| 40 | if(z1<9){
| 41 | z1++;}
| 42 | else
| 43 | z1=0;
| 44 | lcd_clear();
| 45 | //lcd_setcursor(0,1);
| 46 | printf("%i",z1);
| 47 | }
| 48 |
| 49 | void zahl2 (){
| 50 | if(z2<9){
| 51 | z2++;}
| 52 | else
| 53 | z2=0;
| 54 |
| 55 | //lcd_setcursor(1,1);
| 56 | printf("%i%i",z1,z2);
| 57 | }
| 58 |
| 59 | void zahl3 (){
| 60 | if(z3<9){
| 61 | z3++;}
| 62 | else
| 63 | z3=0;
| 64 |
| 65 | //lcd_setcursor(2,1);
| 66 | printf("%i%i",z1,z2,z3);
| 67 | }
| 68 |
| 69 | void zahl4 (){
| 70 | if(z4<9){
| 71 | z4++;}
| 72 | else
| 73 | z4=0;
| 74 | lcd_setcursor(3,1);
| 75 | printf("%i",z4);
| 76 | }
| 77 |
| 78 | void zahl5 (){
| 79 | if(z5<9){
| 80 | z5++;}
| 81 | else
| 82 | z5=0;
| 83 | lcd_setcursor(4,1);
| 84 | printf("%i",z5);
| 85 | }
| 86 |
| 87 | void zahl6 (){
| 88 | if(z6<9){
| 89 | z6++;}
| 90 | else
| 91 | z6=0;
| 92 | lcd_setcursor(5,1);
| 93 | printf("%i",z6);
| 94 | }
| 95 |
| 96 | void zahl7 (){
| 97 | if(z7<9){
| 98 | z7++;}
| 99 | else
| 100 | z7=0;
| 101 | lcd_setcursor(6,1);
| 102 | printf("%i",z7);
| 103 | }
| 104 |
| 105 | void zahl8 (){
| 106 | if(z8<9){
| 107 | z8++;}
| 108 | else
| 109 | z8=0;
| 110 | lcd_setcursor(7,1);
| 111 | printf("%i",z8);
| 112 | }
| 113 |
| 114 | void zahl9 (){
| 115 | if(z9<9){
| 116 | z9++;}
| 117 | else
| 118 | z9=0;
| 119 | lcd_setcursor(8,1);
| 120 | printf("%i",z9);
| 121 | }
| 122 |
| 123 | void zahl10 (){
| 124 | if(z10<9){
| 125 | z10++;}
| 126 | else
| 127 | z10=0;
| 128 | lcd_setcursor(9,1);
| 129 | printf("%i",z10);
| 130 | }
| 131 | void zahl11 (){
| 132 | if(z11<9){
| 133 | z11++;}
| 134 | else
| 135 | z11=0;
| 136 | lcd_setcursor(10,1);
| 137 | printf("%i",z11);
| 138 | }
| 139 | void zahlr (){
| 140 | zr='/r';
| 141 | lcd_setcursor(11,1);
| 142 | printf("%s",zr);
| 143 | }
| 144 |
| 145 |
| 146 | ISR(PCINT2_vect){ // ISR AUF und AB Taster
| 147 |
| 148 | if(!(PIND&(1<<PIND6))){ //Taster AB
| 149 | PCMSK2&=~(1<<PCINT22);
| 150 | _delay_ms(150);
| 151 | PCMSK2|=1<<PCINT22;
| 152 | switch (nummernPos){
| 153 |
| 154 | case 20:
| 155 | zahl1();
| 156 | nummernPos=20;
| 157 | menueUeb=20;
| 158 | break;
| 159 |
| 160 | case 21:
| 161 | zahl2();
| 162 | nummernPos=21;
| 163 | menueUeb=21;
| 164 | break;
| 165 |
| 166 | case 22:
| 167 | zahl3();
| 168 | nummernPos=22;
| 169 | menueUeb=22;
| 170 | break;
| 171 |
| 172 |
| 173 |
| 174 | }
| 175 | }
| 176 |
| 177 | /*if(!(PIND&(1<<PIND5))){ // Taster AUF
| 178 | PCMSK2&=~(1<<PCINT21);
| 179 | _delay_ms(100);
| 180 | PCMSK2|=1<<PCINT21;
| 181 |
| 182 |
| 183 | }*/
| 184 | }
| 185 |
| 186 | ISR(INT1_vect){ //Taster ENTER
| 187 |
| 188 | EIMSK&=~(1<<INT1);
| 189 | _delay_ms(150);
| 190 | EIMSK|=1<<INT1;
| 191 |
| 192 |
| 193 |
| 194 | if(menueUeb==20){
| 195 | lcd_setcursor(1,1);
| 196 | nummernPos++;
| 197 | }
| 198 |
| 199 | if(menueUeb==21){
| 200 | lcd_setcursor(2,1);
| 201 | nummernPos++;
| 202 | }
| 203 |
| 204 | if(menueUeb==22){
| 205 | lcd_setcursor(3,1);
| 206 | nummernPos++;
| 207 | }
| 208 |
| 209 |
| 210 |
| 211 |
| 212 | }
| 213 |
| 214 |
| 215 |
| 216 |
| 217 | int main(void) {
| 218 | stdout = &mystdout;
| 219 | lcd_init(); //LC Display initialisieren
| 220 |
| 221 |
| 222 |
| 223 | DDRB=0b00111111; //PORTB Eingänge (0) und Ausgänge (1) festlegen
| 224 | DDRC=0b00001111; //PORTC Eingänge (0) und Ausgänge (1) festlegen
| 225 | DDRD=0b10000010; //PORTD Eingänge (0) und Ausgänge (1) festlegen
| 226 | PCICR|=1<<PCIE2; //Pin change Interrupts initalisieren
| 227 | PCMSK2|=1<<PCINT22|1<<PCINT21; // Pins für Pin change definieren (PD5 und PD6)
| 228 | EICRA|=1<<ISC11; //INT1 auf fallende Flanke auslösen
| 229 | EIMSK|=1<<INT1;
| 230 |
| 231 | sei();
| 232 |
| 233 |
| 234 | while (1){
| 235 |
| 236 | }
| 237 | }
|
|