bosko lekovic
/
IO_board_K22
K22 processor
main.cpp@2:b188a511819f, 2020-08-15 (annotated)
- Committer:
- bosko001
- Date:
- Sat Aug 15 19:55:02 2020 +0000
- Revision:
- 2:b188a511819f
- Parent:
- 1:1052d6227111
- Child:
- 3:71278c5b7c67
simulira konfliktnu spi telegramom
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 ledB(LED3,1); |
bosko001 | 0:c06c791ca345 | 34 | |
bosko001 | 0:c06c791ca345 | 35 | int b = b2; |
bosko001 | 0:c06c791ca345 | 36 | |
bosko001 | 0:c06c791ca345 | 37 | |
bosko001 | 0:c06c791ca345 | 38 | while (true) |
bosko001 | 0:c06c791ca345 | 39 | { |
bosko001 | 0:c06c791ca345 | 40 | |
bosko001 | 0:c06c791ca345 | 41 | { |
bosko001 | 0:c06c791ca345 | 42 | |
bosko001 | 0:c06c791ca345 | 43 | if( b!= b2) |
bosko001 | 0:c06c791ca345 | 44 | { |
bosko001 | 0:c06c791ca345 | 45 | b = b2; |
bosko001 | 1:1052d6227111 | 46 | if( b ) { ledB = 1;} |
bosko001 | 2:b188a511819f | 47 | else { ledB = 0; static char c = 0; /*writeIOspiData( 0xa0, c++ );*/ transIOspiData( 1, 0xa, c++ ); } |
bosko001 | 0:c06c791ca345 | 48 | } |
bosko001 | 0:c06c791ca345 | 49 | |
bosko001 | 0:c06c791ca345 | 50 | } |
bosko001 | 0:c06c791ca345 | 51 | |
bosko001 | 0:c06c791ca345 | 52 | |
bosko001 | 0:c06c791ca345 | 53 | |
bosko001 | 0:c06c791ca345 | 54 | thread_sleep_for(BLINKING_RATE_MS); |
bosko001 | 0:c06c791ca345 | 55 | } |
bosko001 | 0:c06c791ca345 | 56 | } |
bosko001 | 0:c06c791ca345 | 57 | |
bosko001 | 0:c06c791ca345 | 58 | |
bosko001 | 0:c06c791ca345 | 59 | |
bosko001 | 0:c06c791ca345 | 60 | |
bosko001 | 0:c06c791ca345 | 61 | void consolafun( void ) |
bosko001 | 0:c06c791ca345 | 62 | { |
bosko001 | 0:c06c791ca345 | 63 | while( true ) |
bosko001 | 0:c06c791ca345 | 64 | { |
bosko001 | 0:c06c791ca345 | 65 | |
bosko001 | 0:c06c791ca345 | 66 | char uc = getchar( ); |
bosko001 | 0:c06c791ca345 | 67 | switch( (unsigned char) uc ) |
bosko001 | 0:c06c791ca345 | 68 | { |
bosko001 | 0:c06c791ca345 | 69 | case 'r': case 'R': |
bosko001 | 0:c06c791ca345 | 70 | |
bosko001 | 0:c06c791ca345 | 71 | printf("\n\rcitanje registra, unesi broj:\n\r"); |
bosko001 | 0:c06c791ca345 | 72 | int r; |
bosko001 | 0:c06c791ca345 | 73 | scanf("%x", &r); |
bosko001 | 1:1052d6227111 | 74 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 75 | |
bosko001 | 0:c06c791ca345 | 76 | break; |
bosko001 | 0:c06c791ca345 | 77 | case 'w': case 'W': |
bosko001 | 0:c06c791ca345 | 78 | { |
bosko001 | 0:c06c791ca345 | 79 | printf("\n\rupis registra, unesi broj registra:"); |
bosko001 | 0:c06c791ca345 | 80 | int r; |
bosko001 | 0:c06c791ca345 | 81 | scanf("%x", &r); |
bosko001 | 0:c06c791ca345 | 82 | printf( " %x", r ); |
bosko001 | 0:c06c791ca345 | 83 | printf("\n\runesi vrednost registra:"); |
bosko001 | 0:c06c791ca345 | 84 | int v; |
bosko001 | 0:c06c791ca345 | 85 | scanf("%x", &v); |
bosko001 | 0:c06c791ca345 | 86 | printf( " %x", v ); |
bosko001 | 1:1052d6227111 | 87 | // printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r)); |
bosko001 | 0:c06c791ca345 | 88 | } |
bosko001 | 0:c06c791ca345 | 89 | break; |
bosko001 | 0:c06c791ca345 | 90 | } |
bosko001 | 0:c06c791ca345 | 91 | |
bosko001 | 0:c06c791ca345 | 92 | } |
bosko001 | 0:c06c791ca345 | 93 | } |