Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 188 | noddan | 1 | /** |
| 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. |
||
| 4 | * |
||
| 5 | * @date 2006-11-21 |
||
| 6 | * @author Jimmy Myhrman |
||
| 7 | * |
||
| 8 | */ |
||
| 9 | |||
| 10 | /*----------------------------------------------------------------------------- |
||
| 11 | * Includes |
||
| 12 | *---------------------------------------------------------------------------*/ |
||
| 13 | /* system files */ |
||
| 14 | #include <avr/io.h> |
||
| 15 | #include <avr/interrupt.h> |
||
| 16 | #include <avr\pgmspace.h> //För pgm_Read_byte |
||
| 17 | #include <avr/wdt.h> |
||
| 18 | #include <stdio.h> |
||
| 19 | #include <font.h> |
||
| 20 | /* lib files */ |
||
| 21 | #include <can.h> |
||
| 22 | #include <timebase.h> |
||
| 23 | #include <ks0108.h> |
||
| 24 | |||
| 25 | |||
| 26 | //En variabel för att hålla tillståndet |
||
| 27 | |||
| 28 | //Interrupttest |
||
| 29 | |||
| 30 | |||
| 31 | uint8_t encoderPosition; //Bara för interrupttest; |
||
| 32 | |||
| 33 | SIGNAL (SIG_INTERRUPT1) |
||
| 34 | { |
||
| 35 | if ((PINB&(0b10000000))==0){ |
||
| 36 | encoderPosition = encoderPosition - 1; |
||
| 37 | } else { |
||
| 38 | encoderPosition = encoderPosition + 1; |
||
| 39 | } |
||
| 40 | |||
| 41 | |||
| 42 | if (encoderPosition > 250) encoderPosition = 0; |
||
| 43 | if (encoderPosition > 99) encoderPosition = 99; |
||
| 44 | } |
||
| 45 | |||
| 46 | // /Interrupttest |
||
| 47 | |||
| 48 | |||
| 49 | /*----------------------------------------------------------------------------- |
||
| 50 | * Main Program |
||
| 51 | *---------------------------------------------------------------------------*/ |
||
| 52 | int main(void) { |
||
| 53 | //INterrupttest |
||
| 54 | GICR|=0x80; |
||
| 55 | MCUCR=0b00001000; |
||
| 56 | GIFR=0x80; |
||
| 57 | |||
| 58 | |||
| 59 | // /Interrupttest |
||
| 60 | |||
| 61 | Timebase_Init(); |
||
| 62 | sei(); |
||
| 63 | |||
| 64 | uint32_t timeStamp = 0; |
||
| 65 | |||
| 66 | |||
| 67 | //Här leker vi med displayen woohoo |
||
| 68 | |||
| 69 | //Sätt rubbet till utgångar.. kanske inte snygg lösning, men det får bli så sålänge. |
||
| 70 | PORTC=0x00; |
||
| 71 | |||
| 72 | DDRC |= (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5); |
||
| 73 | |||
| 74 | PORTD=0x00; |
||
| 75 | DDRD |= (1<<0)|(1<<1)|(1<<2)|(1<<4)|(1<<5)|(1<<6)|(1<<7); |
||
| 76 | PORTB=0x00; |
||
| 77 | DDRB |= (1<<0)|(1<<1); |
||
| 78 | |||
| 79 | DDRD &= ~(1<<3); |
||
| 80 | DDRB &= ~(1<<7); |
||
| 81 | |||
| 82 | //Initiera tjohej |
||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | //Ny och snyggare kod :) |
||
| 89 | |||
| 90 | |||
| 91 | //Slå på |
||
| 92 | glcdPowerOn(); |
||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | //Test med lite CAN |
||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | Can_Message_t rxMsg; |
||
| 102 | char buffert[21]; |
||
| 103 | |||
| 104 | |||
| 105 | glcdSetXY(0,0); |
||
| 106 | glcdPutStr("CanInit..."); |
||
| 107 | if (Can_Init() != CAN_OK) { |
||
| 108 | glcdPutStr("FAILED!"); |
||
| 109 | } |
||
| 110 | else { |
||
| 111 | glcdPutStr("OK!"); |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | //Can-loopen |
||
| 116 | while (1) { |
||
| 117 | /* service the CAN routines */ |
||
| 118 | Can_Service(); |
||
| 119 | |||
| 120 | /* check if any messages have been received */ |
||
| 121 | while (Can_Receive(&rxMsg) == CAN_OK) { |
||
| 122 | glcdSetXY(0,1); |
||
| 123 | glcdPutStr("MSG Recieved!"); |
||
| 124 | 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)); |
||
| 126 | glcdPutStr(buffert); |
||
| 127 | |||
| 128 | glcdSetXY(0,3); |
||
| 129 | |||
| 130 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
||
| 131 | snprintf(buffert,21,"%x ", rxMsg.Data.bytes[i]); |
||
| 132 | glcdPutStr(buffert); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | /* Här kollar vi klickvriden */ |
||
| 137 | glcdSetXY(116,0); |
||
| 138 | snprintf(buffert,21,"%u ",encoderPosition); |
||
| 139 | glcdPutStr(buffert); |
||
| 140 | |||
| 141 | |||
| 142 | } |
||
| 143 | |||
| 144 | |||
| 145 | while (1) { |
||
| 146 | |||
| 147 | } |
||
| 148 | |||
| 149 | return 0; |
||
| 150 | } |