Rev 188 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 188 | Rev 189 | ||
|---|---|---|---|
| Line 21... | Line 21... | ||
| 21 | #include <can.h> |
21 | #include <can.h> |
| 22 | #include <timebase.h> |
22 | #include <timebase.h> |
| 23 | #include <ks0108.h> |
23 | #include <ks0108.h> |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | //En variabel för att hålla tillståndet |
- | |
| 27 | - | ||
| 28 | //Interrupttest |
- | |
| 29 | - | ||
| 30 | - | ||
| 31 | uint8_t encoderPosition; //Bara för interrupttest; |
26 | uint8_t encoderPosition; //Bara för interrupttest. +/-1 beroende på riktning.; |
| 32 | 27 | ||
| 33 | SIGNAL (SIG_INTERRUPT1) |
28 | SIGNAL (SIG_INTERRUPT1) |
| 34 | { |
29 | { |
| 35 | if ((PINB&(0b10000000))==0){ |
30 | if ((PINB&(0b10000000))==0){ |
| 36 | encoderPosition = encoderPosition - 1; |
31 | encoderPosition = encoderPosition - 1; |
| Line 41... | Line 36... | ||
| 41 | 36 | ||
| 42 | if (encoderPosition > 250) encoderPosition = 0; |
37 | if (encoderPosition > 250) encoderPosition = 0; |
| 43 | if (encoderPosition > 99) encoderPosition = 99; |
38 | if (encoderPosition > 99) encoderPosition = 99; |
| 44 | } |
39 | } |
| 45 | 40 | ||
| 46 | // /Interrupttest |
- | |
| 47 | 41 | ||
| 48 | 42 | ||
| 49 | /*----------------------------------------------------------------------------- |
43 | /*----------------------------------------------------------------------------- |
| 50 | * Main Program |
44 | * Main Program |
| 51 | *---------------------------------------------------------------------------*/ |
45 | *---------------------------------------------------------------------------*/ |
| 52 | int main(void) { |
46 | int main(void) { |
| 53 | //INterrupttest |
- | |
| 54 | GICR|=0x80; |
47 | GICR|=0x80; //Interrupt på |
| 55 | MCUCR=0b00001000; |
48 | MCUCR=0b00001000; //Rising Edge |
| 56 | GIFR=0x80; |
49 | GIFR=0x80; //Något interruptigt :) |
| 57 | 50 | ||
| 58 | - | ||
| 59 | // /Interrupttest |
- | |
| 60 | 51 | ||
| 61 | Timebase_Init(); |
52 | Timebase_Init(); |
| 62 | sei(); |
53 | sei(); |
| 63 | - | ||
| 64 | uint32_t timeStamp = 0; |
54 | uint32_t timeStamp = 0; |
| 65 | - | ||
| 66 | 55 | ||
| 67 | //Här leker vi med displayen woohoo |
- | |
| 68 | 56 | ||
| 69 | / |
57 | //Sätt en massa ut/ingångar.. kanske inte snygg lösning, men det får bli så sålänge. |
| 70 | PORTC=0x00; |
58 | PORTC=0x00; |
| 71 | - | ||
| 72 | DDRC |= (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5); |
59 | DDRC |= (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5); |
| 73 | - | ||
| 74 | PORTD=0x00; |
60 | PORTD=0x00; |
| 75 | DDRD |= (1<<0)|(1<<1)|(1<<2)|(1<<4)|(1<<5)|(1<<6)|(1<<7); |
61 | DDRD |= (1<<0)|(1<<1)|(1<<2)|(1<<4)|(1<<5)|(1<<6)|(1<<7); |
| 76 | PORTB=0x00; |
62 | PORTB=0x00; |
| 77 | DDRB |= (1<<0)|(1<<1); |
63 | DDRB |= (1<<0)|(1<<1); |
| 78 | - | ||
| 79 | DDRD &= ~(1<<3); |
64 | DDRD &= ~(1<<3); |
| 80 | DDRB &= ~(1<<7); |
65 | DDRB &= ~(1<<7); |
| 81 | 66 | ||
| 82 | //Initiera tjohej |
- | |
| 83 | - | ||
| 84 | - | ||
| 85 | - | ||
| 86 | 67 | ||
| 87 | - | ||
| 88 | //Ny och snyggare kod :) |
- | |
| 89 | - | ||
| 90 | - | ||
| 91 | //Slå på |
- | |
| 92 | glcdPowerOn(); |
68 | glcdPowerOn(); |
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | //Test med lite CAN |
- | |
| 98 | - | ||
| 99 | - | ||
| 100 | 69 | ||
| 101 | Can_Message_t rxMsg; |
70 | Can_Message_t rxMsg; |
| 102 | char buffert[21]; |
71 | char buffert[21]; //Buffert för snprintf |
| 103 | 72 | ||
| 104 | 73 | ||
| 105 | glcdSetXY(0,0); |
74 | glcdSetXY(0,0); |
| 106 | glcdPutStr("CanInit..."); |
75 | glcdPutStr("CanInit..."); |
| 107 | if (Can_Init() != CAN_OK) { |
76 | if (Can_Init() != CAN_OK) { |
| Line 132... | Line 101... | ||
| 132 | glcdPutStr(buffert); |
101 | glcdPutStr(buffert); |
| 133 | } |
102 | } |
| 134 | } |
103 | } |
| 135 | 104 | ||
| 136 | /* Här kollar vi klickvriden */ |
105 | /* Här kollar vi klickvriden */ |
| 137 | glcdSetXY( |
106 | glcdSetXY(115,0); |
| 138 | snprintf(buffert,21,"%u ",encoderPosition); |
107 | snprintf(buffert,21,"%u ",encoderPosition); |
| 139 | glcdPutStr(buffert); |
108 | glcdPutStr(buffert); |
| 140 | 109 | ||
| 141 | - | ||
| 142 | } |
- | |
| 143 | - | ||
| 144 | - | ||
| 145 | while (1) { |
- | |
| 146 | 110 | ||
| 147 | } |
111 | } |
| 148 | 112 | ||
| 149 | return 0; |
113 | return 0; |
| 150 | } |
114 | } |