Subversion Repositories HomeAutomation

Rev

Rev 163 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 163 Rev 164
Line 19... Line 19...
19
/* lib files */
19
/* lib files */
20
#include <can.h>
20
#include <can.h>
21
#include <serial.h>
21
#include <serial.h>
22
#include <timebase.h>
22
#include <timebase.h>
23
#include <lcd_HD44780.h>
23
#include <lcd_HD44780.h>
-
 
24
 
-
 
25
#define BUFFER_SIZE 20
24
 
26
 
25
/*-----------------------------------------------------------------------------
27
/*-----------------------------------------------------------------------------
26
 * Main Program
28
 * Main Program
27
 *---------------------------------------------------------------------------*/
29
 *---------------------------------------------------------------------------*/
28
int main(void) {
30
int main(void) {
-
 
31
 
-
 
32
    char buffer[ BUFFER_SIZE ];
-
 
33
    int num=1234;
-
 
34
 
29
    Timebase_Init();
35
    Timebase_Init();
30
    Serial_Init();
36
    Serial_Init();
31
    sei();
37
    sei();
32
    lcd_init( LCD_DISP_ON );
38
    lcd_init( LCD_DISP_ON );
33
 
39
 
34
    printf("\n------------------------------------------------------------\n");
40
    printf("\n------------------------------------------------------------\n");
35
    printf(  "   CAN Test: Periodic Transmission\n");
41
    printf(  "   CAN Test: Periodic Transmission\n");
36
    printf(  "------------------------------------------------------------\n");
42
    printf(  "------------------------------------------------------------\n");
37
 
43
 
38
    lcd_clrscr();
44
    lcd_clrscr();
39
    lcd_puts("CAN LCD test\n");
45
    lcd_puts("CAN LCD test\n");
40
 
46
 
41
    printf("CanInit...");
47
    printf("CanInit...");
42
    lcd_puts("CanInit... ");
48
    lcd_puts("CanInit... ");
43
    if (Can_Init() != CAN_OK) {
49
    if (Can_Init() != CAN_OK) {
Line 46... Line 52...
46
    }
52
    }
47
    else {
53
    else {
48
        printf("OK!\n");
54
        printf("OK!\n");
49
        lcd_puts("OK!\n");
55
        lcd_puts("OK!\n");
50
    }
56
    }
-
 
57
   
-
 
58
//    snprintf(buffer, BUFFER_SIZE, "yo %d 98765432109\n", num);
-
 
59
//    lcd_puts(buffer);
-
 
60
//    lcd_puts("test\n");
-
 
61
//    lcd_puts(buffer);
51
   
62
 
52
    uint32_t timeStamp = 0;
63
    uint32_t timeStamp = 0;
53
   
64
   
54
    Can_Message_t txMsg;
65
    Can_Message_t txMsg;
55
    Can_Message_t rxMsg;
66
    Can_Message_t rxMsg;
56
    txMsg.Id = 0;
67
    txMsg.Id = 0;
57
    txMsg.RemoteFlag = 0;
68
    txMsg.RemoteFlag = 0;
58
    txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set.
69
    txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set.
59
   
70
   
60
    /* main loop */
71
    /* main loop */
61
    while (1) {
72
    while (1) {
62
        /* service the CAN routines */
73
        /* service the CAN routines */
63
        Can_Service();
74
        Can_Service();
64
       
75
       
Line 72... Line 83...
72
       
83
       
73
        /* check if any messages have been received */
84
        /* check if any messages have been received */
74
        while (Can_Receive(&rxMsg) == CAN_OK) {
85
        while (Can_Receive(&rxMsg) == CAN_OK) {
75
            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("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
76
            printf("data={ ");
87
            printf("data={ ");
-
 
88
 
77
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
89
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
78
                printf("%x ", rxMsg.Data.bytes[i]);
90
                printf("%x ", rxMsg.Data.bytes[i]);
79
            }
91
            }
80
            printf("}\n");
92
            printf("}\n");
-
 
93
 
-
 
94
            if( rxMsg.Id == 0x3 ){
-
 
95
//                lcd_gotoxy(0,1);
-
 
96
                lcd_clrscr();
-
 
97
 //               lcd_putc(0xdf);
-
 
98
                lcd_puts("Temperature data:\n");
-
 
99
 
-
 
100
                for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){
-
 
101
                        snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf );
-
 
102
                        lcd_gotoxy(0,1+i);
-
 
103
                        lcd_puts( buffer );
-
 
104
                }
-
 
105
            }
81
        }
106
        }
82
    }
107
    }
83
   
108
   
84
    return 0;
109
    return 0;
85
}
110
}