Rev 167 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 167 | Rev 178 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| - | 2 | * CAN LCD. |
|
| 2 | * |
3 | * For HD44780- and KS0073-based LCD displays |
| 3 | * |
4 | * This is the early version that only prints temperature sensor data. |
| 4 | * Added LCD output |
- | |
| 5 | * |
5 | * |
| 6 | * @date |
6 | * @date 2006-12-11 |
| 7 | * @author |
7 | * @author Erik Larsson |
| - | 8 | * |
|
| - | 9 | * TODO Fix more types of output: relay status, mail recieved etc. |
|
| - | 10 | * Make it configurable to use UART, because it's not necessary on the final PCB |
|
| 8 | * |
11 | * |
| 9 | */ |
12 | */ |
| - | 13 | ||
| - | 14 | /* For eq's testing purpose */ |
|
| - | 15 | #define EQLAZER 0 |
|
| 10 | 16 | ||
| 11 | /*----------------------------------------------------------------------------- |
17 | /*----------------------------------------------------------------------------- |
| 12 | * Includes |
18 | * Includes |
| 13 | *---------------------------------------------------------------------------*/ |
19 | *---------------------------------------------------------------------------*/ |
| 14 | /* system files */ |
20 | /* system files */ |
| Line 20... | Line 26... | ||
| 20 | #include <can.h> |
26 | #include <can.h> |
| 21 | #include <serial.h> |
27 | #include <serial.h> |
| 22 | #include <timebase.h> |
28 | #include <timebase.h> |
| 23 | #include <lcd_HD44780.h> |
29 | #include <lcd_HD44780.h> |
| 24 | 30 | ||
| - | 31 | /* defines */ |
|
| - | 32 | //#include <global_funcdefs> // TODO in future version use this (first fix the defs) |
|
| - | 33 | ||
| - | 34 | #ifdef EQLAZER |
|
| 25 | #include <eqlazer_funcdefs.h> |
35 | #include <eqlazer_funcdefs.h> // for eq's personal defs |
| - | 36 | #endif |
|
| 26 | 37 | ||
| 27 | #define BUFFER_SIZE 20 |
38 | #define BUFFER_SIZE 20 |
| 28 | 39 | ||
| 29 | /*----------------------------------------------------------------------------- |
40 | /*----------------------------------------------------------------------------- |
| 30 | * Main Program |
41 | * Main Program |
| Line 38... | Line 49... | ||
| 38 | Serial_Init(); |
49 | Serial_Init(); |
| 39 | sei(); |
50 | sei(); |
| 40 | lcd_init( LCD_DISP_ON ); |
51 | lcd_init( LCD_DISP_ON ); |
| 41 | 52 | ||
| 42 | printf("\n------------------------------------------------------------\n"); |
53 | printf("\n------------------------------------------------------------\n"); |
| 43 | printf( " CAN |
54 | printf( " CAN LCD\n"); |
| 44 | printf( "------------------------------------------------------------\n"); |
55 | printf( "------------------------------------------------------------\n"); |
| 45 | 56 | ||
| 46 | lcd_clrscr(); |
57 | lcd_clrscr(); |
| 47 | lcd_puts("CAN LCD test\n"); |
58 | lcd_puts("CAN LCD test\n"); |
| 48 | 59 | ||
| Line 61... | Line 72... | ||
| 61 | 72 | ||
| 62 | Can_Message_t txMsg; |
73 | Can_Message_t txMsg; |
| 63 | Can_Message_t rxMsg; |
74 | Can_Message_t rxMsg; |
| 64 | txMsg.Id = 0; |
75 | txMsg.Id = 0; |
| 65 | txMsg.RemoteFlag = 0; |
76 | txMsg.RemoteFlag = 0; |
| 66 | txMsg.ExtendedFlag = 1; |
77 | txMsg.ExtendedFlag = 1; |
| 67 | 78 | ||
| 68 | lcd_clrscr(); |
79 | lcd_clrscr(); |
| 69 | 80 | ||
| 70 | /* main loop */ |
81 | /* main loop */ |
| 71 | while (1) { |
82 | while (1) { |
| 72 | /* service the CAN routines */ |
83 | /* service the CAN routines */ |
| 73 | Can_Service(); |
84 | Can_Service(); |
| 74 | 85 | ||
| 75 | /* send CAN message and check for CAN errors once every second */ |
- | |
| 76 | // if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { |
- | |
| 77 | // timeStamp = Timebase_CurrentTime(); |
- | |
| 78 | /* send txMsg */ |
- | |
| 79 | // txMsg.Id++; |
- | |
| 80 | // Can_Send(&txMsg); |
- | |
| 81 | // } |
- | |
| 82 | - | ||
| 83 | /* check if any messages have been received */ |
86 | /* check if any messages have been received and print to uart */ |
| 84 | while (Can_Receive(&rxMsg) == CAN_OK) { |
87 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 85 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
88 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 86 | printf("data={ "); |
89 | printf("data={ "); |
| 87 | 90 | ||
| 88 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
91 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
| 89 | printf("%x ", rxMsg.Data.bytes[i]); |
92 | printf("%x ", rxMsg.Data.bytes[i]); |
| 90 | } |
93 | } |
| 91 | printf("}\n"); |
94 | printf("}\n"); |
| 92 | 95 | ||
| - | 96 | #ifdef EQLAZER /* More personalized code */ |
|
| - | 97 | if( (rxMsg.Id & 0x1E000000)>>25 == FUNCT_SENSORS){ |
|
| 93 | 98 | ||
| 94 |
|
99 | // TODO fixa rätt umatning av sensordata: negativa tal och decimaldelen. |
| - | 100 | // Skriva om hela skiten |
|
| 95 | 101 | // |
|
| 96 | /* which temperature sensor? */ |
102 | /* which temperature sensor? */ |
| 97 | if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_INSIDE ){ |
103 | if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_INSIDE ){ |
| 98 | /* Below 0 degrees celsius? */ |
104 | /* Below 0 degrees celsius? */ |
| 99 | if(rxMsg.Data.bytes[0]&0x80){ |
105 | if(rxMsg.Data.bytes[0]&0x80){ |
| 100 | rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0]; |
106 | rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0]; |
| Line 133... | Line 139... | ||
| 133 | lcd_puts( buffer ); |
139 | lcd_puts( buffer ); |
| 134 | }else{ |
140 | }else{ |
| 135 | lcd_clrscr(); |
141 | lcd_clrscr(); |
| 136 | lcd_puts("Sensors: No config."); |
142 | lcd_puts("Sensors: No config."); |
| 137 | } |
143 | } |
| - | 144 | } |
|
| - | 145 | #else /* Generally code */ |
|
| - | 146 | ||
| - | 147 | /* If temperature sensor data received print to LCD */ |
|
| - | 148 | if( rxMsg.Id == 0x300 ){ |
|
| 138 | /* |
149 | |
| 139 | for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){ |
150 | for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){ |
| 140 |
|
151 | snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf ); // TODO fixa korrekt utmatning av negativa tal och decimaldel |
| 141 | lcd_gotoxy(0,1+i); |
152 | lcd_gotoxy(0,1+i); |
| 142 | lcd_puts( buffer ); |
153 | lcd_puts( buffer ); |
| 143 | }*/ |
- | |
| 144 | } |
154 | } |
| - | 155 | } |
|
| - | 156 | #endif |
|
| 145 | } |
157 | } |
| 146 | } |
158 | } |
| 147 | 159 | ||
| 148 | return 0; |
160 | return 0; |
| 149 | } |
161 | } |