bruno LARNAUDIE
/
Can
main.cpp@0:85bca9d6be51, 2011-08-28 (annotated)
- Committer:
- slowness
- Date:
- Sun Aug 28 16:17:08 2011 +0000
- Revision:
- 0:85bca9d6be51
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slowness | 0:85bca9d6be51 | 1 | #include "mbed.h" |
slowness | 0:85bca9d6be51 | 2 | |
slowness | 0:85bca9d6be51 | 3 | /*Configuration des LED en sortie num�rique*/ |
slowness | 0:85bca9d6be51 | 4 | |
slowness | 0:85bca9d6be51 | 5 | DigitalOut led_write(LED1); |
slowness | 0:85bca9d6be51 | 6 | DigitalOut led_read(LED4); |
slowness | 0:85bca9d6be51 | 7 | DigitalOut led_can(LED3); |
slowness | 0:85bca9d6be51 | 8 | |
slowness | 0:85bca9d6be51 | 9 | Serial pc(p9, p10); |
slowness | 0:85bca9d6be51 | 10 | CAN can(p30, p29); /*Configuration des ports du CAN : rd p30 td p29*/ |
slowness | 0:85bca9d6be51 | 11 | Ticker ticker; /*Fonction timer*/ |
slowness | 0:85bca9d6be51 | 12 | Ticker ticker1; /*Fonction timer*/ |
slowness | 0:85bca9d6be51 | 13 | |
slowness | 0:85bca9d6be51 | 14 | /*Fonction de configuration du message d'envoi*/ |
slowness | 0:85bca9d6be51 | 15 | char compteur=0; |
slowness | 0:85bca9d6be51 | 16 | void send(){ |
slowness | 0:85bca9d6be51 | 17 | |
slowness | 0:85bca9d6be51 | 18 | /*Initialisation des variables*/ |
slowness | 0:85bca9d6be51 | 19 | |
slowness | 0:85bca9d6be51 | 20 | char message[8]={compteur,0x10,0x11,0x10,0x11,0x10,0x11,0x00}; /*Initialisation du tableau de donn�e du message � envoyer*/ |
slowness | 0:85bca9d6be51 | 21 | CANMessage canmsg = CANMessage(); /*Variable de type CANMessage*/ |
slowness | 0:85bca9d6be51 | 22 | char i; /*Variable compteur i*/ |
slowness | 0:85bca9d6be51 | 23 | |
slowness | 0:85bca9d6be51 | 24 | /*Caract�ristique du message � envoyer sur le CAN*/ |
slowness | 0:85bca9d6be51 | 25 | |
slowness | 0:85bca9d6be51 | 26 | canmsg.id=0x001; /*L'identification du message*/ |
slowness | 0:85bca9d6be51 | 27 | canmsg.len=8; /*Longeur de la trame en octet*/ |
slowness | 0:85bca9d6be51 | 28 | canmsg.format=CANStandard; /*Format de la trame CANStandart 11 octet*/ |
slowness | 0:85bca9d6be51 | 29 | canmsg.type=CANData; /*Type de la trame CANData*/ |
slowness | 0:85bca9d6be51 | 30 | |
slowness | 0:85bca9d6be51 | 31 | for(i=0;i<8;i++){ /*Copie du tableau de donn�e dans le tableau du messge*/ |
slowness | 0:85bca9d6be51 | 32 | canmsg.data[i]=message[i]; |
slowness | 0:85bca9d6be51 | 33 | } |
slowness | 0:85bca9d6be51 | 34 | led_write=can.write(canmsg); /*Si la transmission se fait sans error, allume une led*/ |
slowness | 0:85bca9d6be51 | 35 | |
slowness | 0:85bca9d6be51 | 36 | compteur++; |
slowness | 0:85bca9d6be51 | 37 | }/*Fin Fontion*/ |
slowness | 0:85bca9d6be51 | 38 | |
slowness | 0:85bca9d6be51 | 39 | void send1(){ |
slowness | 0:85bca9d6be51 | 40 | |
slowness | 0:85bca9d6be51 | 41 | /*Initialisation des variables*/ |
slowness | 0:85bca9d6be51 | 42 | |
slowness | 0:85bca9d6be51 | 43 | char message[8]={compteur,0x20,0x22,0x20,0x22,0x20,0x22,0x20}; /*Initialisation du tableau de donn�e du message � envoyer*/ |
slowness | 0:85bca9d6be51 | 44 | CANMessage canmsg = CANMessage(); /*Variable de type CANMessage*/ |
slowness | 0:85bca9d6be51 | 45 | char i; /*Variable compteur i*/ |
slowness | 0:85bca9d6be51 | 46 | |
slowness | 0:85bca9d6be51 | 47 | /*Caract�ristique du message � envoyer sur le CAN*/ |
slowness | 0:85bca9d6be51 | 48 | |
slowness | 0:85bca9d6be51 | 49 | canmsg.id=0x010; /*L'identification du message*/ |
slowness | 0:85bca9d6be51 | 50 | canmsg.len=8; /*Longeur de la trame en octet*/ |
slowness | 0:85bca9d6be51 | 51 | canmsg.format=CANStandard; /*Format de la trame CANStandart 11 octet*/ |
slowness | 0:85bca9d6be51 | 52 | canmsg.type=CANData; /*Type de la trame CANData*/ |
slowness | 0:85bca9d6be51 | 53 | |
slowness | 0:85bca9d6be51 | 54 | for(i=0;i<8;i++){ /*Copie du tableau de donn�e dans le tableau du messge*/ |
slowness | 0:85bca9d6be51 | 55 | canmsg.data[i]=message[i]; |
slowness | 0:85bca9d6be51 | 56 | } |
slowness | 0:85bca9d6be51 | 57 | led_write=can.write(canmsg); /*Si la transmission se fait sans error, allume une led*/ |
slowness | 0:85bca9d6be51 | 58 | |
slowness | 0:85bca9d6be51 | 59 | compteur++; |
slowness | 0:85bca9d6be51 | 60 | }/*Fin Fontion*/ |
slowness | 0:85bca9d6be51 | 61 | |
slowness | 0:85bca9d6be51 | 62 | /*DEBUT PROGRAMME*/ |
slowness | 0:85bca9d6be51 | 63 | |
slowness | 0:85bca9d6be51 | 64 | int main() { |
slowness | 0:85bca9d6be51 | 65 | |
slowness | 0:85bca9d6be51 | 66 | char message[8]={0x00,0x10,0x11,0x10,0x11,0x10,0x11,0x00}; /*Initialisation du tableau de donn�e du message � envoyer*/ |
slowness | 0:85bca9d6be51 | 67 | CANMessage canmsg = CANMessage(); /*Variable de type CANMessage*/ |
slowness | 0:85bca9d6be51 | 68 | char i; |
slowness | 0:85bca9d6be51 | 69 | can.frequency(1000000); /*Baud rate : kbits/s */ |
slowness | 0:85bca9d6be51 | 70 | pc.baud(9600); |
slowness | 0:85bca9d6be51 | 71 | canmsg.id=0x001; /*L'identification du message*/ |
slowness | 0:85bca9d6be51 | 72 | canmsg.len=8; /*Longeur de la trame en octet*/ |
slowness | 0:85bca9d6be51 | 73 | canmsg.format=CANStandard; /*Format de la trame CANStandart 11 octet*/ |
slowness | 0:85bca9d6be51 | 74 | canmsg.type=CANData; |
slowness | 0:85bca9d6be51 | 75 | for(i=0;i<8;i++){ |
slowness | 0:85bca9d6be51 | 76 | canmsg.data[i]=message[i]; |
slowness | 0:85bca9d6be51 | 77 | } |
slowness | 0:85bca9d6be51 | 78 | while(1){ /*Variable compteur i*/ |
slowness | 0:85bca9d6be51 | 79 | |
slowness | 0:85bca9d6be51 | 80 | /*Type de la trame CANData*/ |
slowness | 0:85bca9d6be51 | 81 | led_write=can.write(canmsg); |
slowness | 0:85bca9d6be51 | 82 | wait(0.1); |
slowness | 0:85bca9d6be51 | 83 | |
slowness | 0:85bca9d6be51 | 84 | }/*Fin while*/ |
slowness | 0:85bca9d6be51 | 85 | |
slowness | 0:85bca9d6be51 | 86 | } |
slowness | 0:85bca9d6be51 | 87 | /*FIN PROGRAMME*/ |