Demo 1 for Lab1

Dependencies:   mbed

Committer:
duncan_120
Date:
Mon Oct 25 09:38:37 2021 +0000
Revision:
1:f1966862d774
Parent:
0:7b72346ba27a
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
traintony 0:7b72346ba27a 1 #include "mbed.h"
traintony 0:7b72346ba27a 2 #define UART_BAUD_RATE 115200 //defalt:9600
traintony 0:7b72346ba27a 3 Serial uart(USBTX, USBRX);
traintony 0:7b72346ba27a 4
traintony 0:7b72346ba27a 5 //-----System variable-----
traintony 0:7b72346ba27a 6 int i;
traintony 0:7b72346ba27a 7 //-----function zone-----
traintony 0:7b72346ba27a 8 void InitializeUart();
traintony 0:7b72346ba27a 9 void UartReceiveInterrupt();
traintony 0:7b72346ba27a 10
traintony 0:7b72346ba27a 11 int main() {
traintony 0:7b72346ba27a 12 InitializeUart();
traintony 0:7b72346ba27a 13
traintony 0:7b72346ba27a 14 while(1){
traintony 0:7b72346ba27a 15 //please write your code here
traintony 0:7b72346ba27a 16 wait(1);
traintony 0:7b72346ba27a 17 i++;
traintony 0:7b72346ba27a 18 }
traintony 0:7b72346ba27a 19 }
traintony 0:7b72346ba27a 20
traintony 0:7b72346ba27a 21 void InitializeUart(){
traintony 0:7b72346ba27a 22 uart.baud(UART_BAUD_RATE);
traintony 0:7b72346ba27a 23 uart.attach(&UartReceiveInterrupt, Serial::RxIrq);
traintony 0:7b72346ba27a 24 uart.printf("UART OK\r\n");
traintony 0:7b72346ba27a 25 }
traintony 0:7b72346ba27a 26
traintony 0:7b72346ba27a 27 void UartReceiveInterrupt(){
traintony 0:7b72346ba27a 28 while(uart.readable()) {
traintony 0:7b72346ba27a 29 // please write your code here
traintony 0:7b72346ba27a 30 uart.getc();
traintony 0:7b72346ba27a 31 uart.printf("This program runs %d seconds.\r\n", i);
traintony 0:7b72346ba27a 32 }
duncan_120 1:f1966862d774 33 }
duncan_120 1:f1966862d774 34 //oooooooo