20190816

Dependencies:   mbed

Committer:
VASKO
Date:
Sat Aug 03 13:17:12 2019 +0000
Revision:
5:ad4e5a078834
Parent:
4:d461cadeb702
Child:
6:1364a236ee22
Working with ArrTx by pointer instead of index.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
VASKO 0:5152e3f9df72 1 #include "mbed.h"
VASKO 0:5152e3f9df72 2
VASKO 0:5152e3f9df72 3 #define ArrTxSize 16
VASKO 0:5152e3f9df72 4 #define ArrRxSize 16
VASKO 0:5152e3f9df72 5
VASKO 2:56a194afd255 6 Serial pc(USBTX,USBRX);
VASKO 0:5152e3f9df72 7
VASKO 0:5152e3f9df72 8 DigitalOut myled(LED1);
VASKO 0:5152e3f9df72 9
VASKO 2:56a194afd255 10 uint8_t ArrTx[ArrTxSize] = {0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4b,0x4c,0x4d,0x4e,0x4f};
VASKO 2:56a194afd255 11 uint8_t ArrRx[ArrRxSize] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
VASKO 5:ad4e5a078834 12
VASKO 5:ad4e5a078834 13 uint8_t *pArrTx = &ArrTx[0];
VASKO 5:ad4e5a078834 14
VASKO 0:5152e3f9df72 15 void IntrTx() {
VASKO 5:ad4e5a078834 16 if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ){
VASKO 5:ad4e5a078834 17 pc.putc(*pArrTx);
VASKO 0:5152e3f9df72 18 }
VASKO 0:5152e3f9df72 19 else{
VASKO 2:56a194afd255 20 pc.attach(NULL, Serial::TxIrq);
VASKO 2:56a194afd255 21 myled=0;
VASKO 0:5152e3f9df72 22 }
VASKO 0:5152e3f9df72 23 }
VASKO 0:5152e3f9df72 24
VASKO 4:d461cadeb702 25 void CopyMemUint8(uint8_t *src = &ArrRx[0], uint8_t *dst = &ArrTx[0], int qty = ArrTxSize){
VASKO 3:7cdb20aac969 26 for ( ; qty > 0; src++,dst++,qty-- ) *dst = *src;
VASKO 3:7cdb20aac969 27 }
VASKO 4:d461cadeb702 28
VASKO 4:d461cadeb702 29 uint8_t *pArrRx = &ArrRx[0];
VASKO 3:7cdb20aac969 30
VASKO 2:56a194afd255 31 void IntrRx() {
VASKO 4:d461cadeb702 32 *pArrRx = pc.getc();
VASKO 5:ad4e5a078834 33 if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) {
VASKO 4:d461cadeb702 34 pArrRx = &ArrRx[0];
VASKO 4:d461cadeb702 35 CopyMemUint8();
VASKO 5:ad4e5a078834 36 pArrTx = &ArrTx[0];
VASKO 5:ad4e5a078834 37 pc.putc(*pArrTx);
VASKO 2:56a194afd255 38 pc.attach(&IntrTx, Serial::TxIrq);
VASKO 2:56a194afd255 39 myled=1;
VASKO 2:56a194afd255 40 }
VASKO 0:5152e3f9df72 41 }
VASKO 0:5152e3f9df72 42
VASKO 0:5152e3f9df72 43 int main() {
VASKO 0:5152e3f9df72 44 pc.attach(&IntrRx, Serial::RxIrq);
VASKO 0:5152e3f9df72 45 pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил
VASKO 0:5152e3f9df72 46
VASKO 2:56a194afd255 47 //Exige Monumentum
VASKO 2:56a194afd255 48 //Я дебил,потому что хотел выполнить действия,которые
VASKO 2:56a194afd255 49 //требуются постоянно,один раз и именно здесь.
VASKO 0:5152e3f9df72 50
VASKO 0:5152e3f9df72 51 while(1) {
VASKO 0:5152e3f9df72 52 }
VASKO 0:5152e3f9df72 53 }