Rev 188 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 188 | Rev 189 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * CAN Test. This program sends a CAN message once every second. The ID of the |
2 | * CAN Test. This program sends a CAN message once every second. The ID of the |
| 3 | * message is increased each time for testing purposes. |
3 | * message is increased each time for testing purposes. |
| 4 | * |
4 | * |
| 5 | * @date 2006-11-21 |
5 | * @date 2006-11-21 |
| 6 | * @author Jimmy Myhrman |
6 | * @author Jimmy Myhrman |
| 7 | * |
7 | * |
| 8 | */ |
8 | */ |
| 9 | 9 | ||
| 10 | /*----------------------------------------------------------------------------- |
10 | /*----------------------------------------------------------------------------- |
| 11 | * Includes |
11 | * Includes |
| 12 | *---------------------------------------------------------------------------*/ |
12 | *---------------------------------------------------------------------------*/ |
| 13 | /* system files */ |
13 | /* system files */ |
| 14 | #include <avr/io.h> |
14 | #include <avr/io.h> |
| 15 | #include <avr/interrupt.h> |
15 | #include <avr/interrupt.h> |
| 16 | #include <avr\pgmspace.h> //För pgm_Read_byte |
16 | #include <avr\pgmspace.h> //För pgm_Read_byte |
| 17 | #include <avr/wdt.h> |
17 | #include <avr/wdt.h> |
| 18 | #include <stdio.h> |
18 | #include <stdio.h> |
| 19 | #include <font.h> |
19 | #include <font.h> |
| 20 | /* lib files */ |
20 | /* lib files */ |
| 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; |
| 37 | } else { |
32 | } else { |
| 38 | encoderPosition = encoderPosition + 1; |
33 | encoderPosition = encoderPosition + 1; |
| 39 | } |
34 | } |
| 40 | 35 | ||
| 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) { |
| 108 | glcdPutStr("FAILED!"); |
77 | glcdPutStr("FAILED!"); |
| 109 | } |
78 | } |
| 110 | else { |
79 | else { |
| 111 | glcdPutStr("OK!"); |
80 | glcdPutStr("OK!"); |
| 112 | } |
81 | } |
| 113 | 82 | ||
| 114 | 83 | ||
| 115 | //Can-loopen |
84 | //Can-loopen |
| 116 | while (1) { |
85 | while (1) { |
| 117 | /* service the CAN routines */ |
86 | /* service the CAN routines */ |
| 118 | Can_Service(); |
87 | Can_Service(); |
| 119 | 88 | ||
| 120 | /* check if any messages have been received */ |
89 | /* check if any messages have been received */ |
| 121 | while (Can_Receive(&rxMsg) == CAN_OK) { |
90 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 122 | glcdSetXY(0,1); |
91 | glcdSetXY(0,1); |
| 123 | glcdPutStr("MSG Recieved!"); |
92 | glcdPutStr("MSG Recieved!"); |
| 124 | glcdSetXY(0,2); |
93 | glcdSetXY(0,2); |
| 125 | snprintf(buffert,21,"ID=%lx L=%u E=%u RT=%u", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
94 | snprintf(buffert,21,"ID=%lx L=%u E=%u RT=%u", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 126 | glcdPutStr(buffert); |
95 | glcdPutStr(buffert); |
| 127 | 96 | ||
| 128 | glcdSetXY(0,3); |
97 | glcdSetXY(0,3); |
| 129 | 98 | ||
| 130 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
99 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
| 131 | snprintf(buffert,21,"%x ", rxMsg.Data.bytes[i]); |
100 | snprintf(buffert,21,"%x ", rxMsg.Data.bytes[i]); |
| 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 | } |
| 151 | 115 | ||