![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
app4
Dependencies: mbed-rtos mbed CRC16
Fork of S5info_APP2 by
Diff: main.cpp
- Revision:
- 23:9c4e4898b741
- Parent:
- 22:7244c3391bac
- Child:
- 24:2034362db66f
diff -r 7244c3391bac -r 9c4e4898b741 main.cpp --- a/main.cpp Tue Mar 07 05:45:26 2017 +0000 +++ b/main.cpp Tue Mar 07 06:09:06 2017 +0000 @@ -16,18 +16,19 @@ uint8_t byte_sent_pos, //position de l'octet dans le tableau d'envoi trame_length; //longueur de la trame complete -signed char bit_sent; //position du bit de l'octet en cours d'envoi (du MSB au LSB) 7..0 +signed char bit_sent; //position du bit de l'octet en cours d'envoi (du MSB au LSB) 7..0 +bool bTimer1 = false; void initTimers() { //Timer 1 (match) LPC_SC->PCLKSEL0 |= (1 << 4); // pclk = cclk timer1 LPC_SC->PCONP |= (1 << 2); // timer1 power on - LPC_TIM1->MR0 = 960000; // 10 ms + LPC_TIM1->MR0 = 960000 / 2; // 10/2 ms LPC_TIM1->MCR = 3; // interrupt and reset control LPC_TIM1->EMR = (3 << 4); // Interrupt & reset timer on match NVIC_EnableIRQ(TIMER1_IRQn); // enable timer interrupt - LPC_TIM1->TCR = 1; // enable Timer + LPC_TIM1->TCR = 0; // disable Timer //Timer 2 (cap) LPC_SC->PCLKSEL1 |= (1 << 12); // pclk = cclk timer2 @@ -43,7 +44,34 @@ LPC_TIM2->TCR = 1; // start Timer } -bool bTimer1 = false; +//encodage manchester +bool codeManchester(bool bit, bool clock) +{ + return (bit == clock); +} + +//Envoie de données bit par bit +void send_data() +{ + out = codeManchester(((trame_sent[byte_sent_pos] >> bit_sent) & 0x01), bTimer1); + if(bTimer1) + { + bit_sent--; + } + bTimer1 = !bTimer1; //varier entre la 1ere et 2eme partie de demi-periode + if (bit_sent < 0) //Si l'octet a ete envoye + { + bit_sent = 7; //remettre la position initiale pour le prochain octet + byte_sent_pos++; //incrementer l'octet + if (byte_sent_pos >= trame_length) //Si la trame a ete envoyee + { + byte_sent_pos = 0; + bTimer1 = false; + LPC_TIM1->TCR = 0; // disable Timer + } + } +} + extern "C" void TIMER1_IRQHandler() { if ((LPC_TIM1->IR & 0x01) == 0x01) @@ -87,29 +115,6 @@ LPC_TIM2->IR |= 0xFFFFFFFF; // clear } -bool codeManchester(bool bit, bool clock) -{ - return (bit == clock); -} - -void send_data() -{ - out = codeManchester(((trame_sent[byte_sent_pos] >> bit_sent) & 0x01), bTimer1); // Encodage Manchester - if(bTimer1) - { - bit_sent--; - } - bTimer1 = !bTimer1; //varier entre la 1ere et 2eme partie de demi-periode - if (bit_sent < 0) { //Si l'octet a ete envoye - bit_sent = 7; //remettre la position initiale pour le prochain octet - byte_sent_pos++; //incrementer l'octet - if (byte_sent_pos >= trame_length) { //Si la trame a ete envoyee - byte_sent_pos = 0; - bTimer1 = false; - } - } -} - //création de la trame void create_trame(char message[],unsigned char taille) { @@ -140,6 +145,7 @@ byte_sent_pos = 0; bit_sent = 7; bTimer1 = false; + LPC_TIM1->TCR = 3; // enable and reset Timer //TODO start interrupt timer 1 //LPC_RIT->MCR = 1; //Permettre les interruption du MAT //LPC_RIT->MR0 = LPC_RIT->TC + HALF_PERIOD; //Faire une interruption a la prochaine demi-periode