bosko lekovic
/
IO_board
IO plocana FRDM K64
main.cpp@1:1052d6227111, 2020-08-13 (annotated)
- Committer:
- bosko001
- Date:
- Thu Aug 13 17:30:08 2020 +0000
- Revision:
- 1:1052d6227111
- Parent:
- 0:c06c791ca345
- Child:
- 2:b188a511819f
IO test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 0:c06c791ca345 | 1 | /* mbed Microcontroller Library |
bosko001 | 0:c06c791ca345 | 2 | * Copyright (c) 2019 ARM Limited |
bosko001 | 0:c06c791ca345 | 3 | * SPDX-License-Identifier: Apache-2.0 |
bosko001 | 0:c06c791ca345 | 4 | */ |
bosko001 | 0:c06c791ca345 | 5 | |
bosko001 | 0:c06c791ca345 | 6 | #include "mbed.h" |
bosko001 | 0:c06c791ca345 | 7 | #include "platform/mbed_thread.h" |
bosko001 | 0:c06c791ca345 | 8 | |
bosko001 | 1:1052d6227111 | 9 | #include "IOspi.h" |
bosko001 | 0:c06c791ca345 | 10 | |
bosko001 | 0:c06c791ca345 | 11 | // Blinking rate in milliseconds |
bosko001 | 0:c06c791ca345 | 12 | #define BLINKING_RATE_MS 200 |
bosko001 | 0:c06c791ca345 | 13 | |
bosko001 | 0:c06c791ca345 | 14 | |
bosko001 | 0:c06c791ca345 | 15 | |
bosko001 | 0:c06c791ca345 | 16 | |
bosko001 | 0:c06c791ca345 | 17 | DigitalIn b2(SW2); |
bosko001 | 0:c06c791ca345 | 18 | |
bosko001 | 0:c06c791ca345 | 19 | |
bosko001 | 0:c06c791ca345 | 20 | |
bosko001 | 0:c06c791ca345 | 21 | char tx_niz[] = { 7,0,1,2,3, 4, 5 , 6, 7, 8}; |
bosko001 | 0:c06c791ca345 | 22 | |
bosko001 | 0:c06c791ca345 | 23 | void consolafun( void ); |
bosko001 | 0:c06c791ca345 | 24 | Thread th_consola( consolafun ); |
bosko001 | 0:c06c791ca345 | 25 | |
bosko001 | 0:c06c791ca345 | 26 | int main() |
bosko001 | 0:c06c791ca345 | 27 | { |
bosko001 | 0:c06c791ca345 | 28 | // Initialise the digital pin LED1 as an output |
bosko001 | 1:1052d6227111 | 29 | printf("\n\n\r ____________ POCETAK IOspi_______________\n\r"); |
bosko001 | 0:c06c791ca345 | 30 | |
bosko001 | 1:1052d6227111 | 31 | inic_IOspi( ); |
bosko001 | 0:c06c791ca345 | 32 | |
bosko001 | 0:c06c791ca345 | 33 | DigitalOut led(LED1,1); |
bosko001 | 0:c06c791ca345 | 34 | DigitalOut ledB(LED3,1); |
bosko001 | 0:c06c791ca345 | 35 | |
bosko001 | 0:c06c791ca345 | 36 | int b = b2; |
bosko001 | 0:c06c791ca345 | 37 | |
bosko001 | 0:c06c791ca345 | 38 | |
bosko001 | 0:c06c791ca345 | 39 | while (true) |
bosko001 | 0:c06c791ca345 | 40 | { |
bosko001 | 0:c06c791ca345 | 41 | |
bosko001 | 0:c06c791ca345 | 42 | { |
bosko001 | 0:c06c791ca345 | 43 | |
bosko001 | 0:c06c791ca345 | 44 | if( b!= b2) |
bosko001 | 0:c06c791ca345 | 45 | { |
bosko001 | 0:c06c791ca345 | 46 | b = b2; |
bosko001 | 1:1052d6227111 | 47 | if( b ) { ledB = 1;} |
bosko001 | 1:1052d6227111 | 48 | else { ledB = 0; static char c = 0; /*writeIOspiData( 0xa0, c++ );*/ char *rx = transIOspiData( 1, 0xa, c++ ); for(int i= 0; i<8; i++) printf(" %x", rx[i]);printf(" \n\r"); } |
bosko001 | 0:c06c791ca345 | 49 | } |
bosko001 | 0:c06c791ca345 | 50 | |
bosko001 | 0:c06c791ca345 | 51 | } |
bosko001 | 0:c06c791ca345 | 52 | |
bosko001 | 0:c06c791ca345 | 53 | |
bosko001 | 0:c06c791ca345 | 54 | |
bosko001 | 0:c06c791ca345 | 55 | thread_sleep_for(BLINKING_RATE_MS); |
bosko001 | 0:c06c791ca345 | 56 | } |
bosko001 | 0:c06c791ca345 | 57 | } |
bosko001 | 0:c06c791ca345 | 58 | |
bosko001 | 0:c06c791ca345 | 59 | |
bosko001 | 0:c06c791ca345 | 60 | |
bosko001 | 0:c06c791ca345 | 61 | |
bosko001 | 0:c06c791ca345 | 62 | void consolafun( void ) |
bosko001 | 0:c06c791ca345 | 63 | { |
bosko001 | 0:c06c791ca345 | 64 | while( true ) |
bosko001 | 0:c06c791ca345 | 65 | { |
bosko001 | 0:c06c791ca345 | 66 | |
bosko001 | 0:c06c791ca345 | 67 | char uc = getchar( ); |
bosko001 | 0:c06c791ca345 | 68 | switch( (unsigned char) uc ) |
bosko001 | 0:c06c791ca345 | 69 | { |
bosko001 | 0:c06c791ca345 | 70 | case 'r': case 'R': |
bosko001 | 0:c06c791ca345 | 71 | |
bosko001 | 0:c06c791ca345 | 72 | printf("\n\rcitanje registra, unesi broj:\n\r"); |
bosko001 | 0:c06c791ca345 | 73 | int r; |
bosko001 | 0:c06c791ca345 | 74 | scanf("%x", &r); |
bosko001 | 1:1052d6227111 | 75 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 76 | |
bosko001 | 0:c06c791ca345 | 77 | break; |
bosko001 | 0:c06c791ca345 | 78 | case 'w': case 'W': |
bosko001 | 0:c06c791ca345 | 79 | { |
bosko001 | 0:c06c791ca345 | 80 | printf("\n\rupis registra, unesi broj registra:"); |
bosko001 | 0:c06c791ca345 | 81 | int r; |
bosko001 | 0:c06c791ca345 | 82 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 83 | printf( " %x", r ); |
bosko001 | 0:c06c791ca345 | 84 | printf("\n\runesi vrednost registra:"); |
bosko001 | 0:c06c791ca345 | 85 | int v; |
bosko001 | 0:c06c791ca345 | 86 | scanf("%x", &v); |
bosko001 | 0:c06c791ca345 | 87 | printf( " %x", v ); |
bosko001 | 1:1052d6227111 | 88 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 89 | } |
bosko001 | 0:c06c791ca345 | 90 | break; |
bosko001 | 0:c06c791ca345 | 91 | } |
bosko001 | 0:c06c791ca345 | 92 | |
bosko001 | 0:c06c791ca345 | 93 | } |
bosko001 | 0:c06c791ca345 | 94 | } |