han back
/
CLEO_UART_PIR
SMART CLEO Uart PIR
main.cpp@1:611e7e2a13df, 2017-12-06 (annotated)
- Committer:
- SMART_CLEO
- Date:
- Wed Dec 06 08:42:05 2017 +0000
- Revision:
- 1:611e7e2a13df
- Parent:
- 0:49114a9f05a6
SMART_CLEO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SMART_CLEO | 0:49114a9f05a6 | 1 | #include "mbed.h" |
SMART_CLEO | 0:49114a9f05a6 | 2 | |
SMART_CLEO | 1:611e7e2a13df | 3 | PinName pin_PIR = PB_2; |
SMART_CLEO | 0:49114a9f05a6 | 4 | |
SMART_CLEO | 1:611e7e2a13df | 5 | InterruptIn Pir(pin_PIR); |
SMART_CLEO | 0:49114a9f05a6 | 6 | |
SMART_CLEO | 0:49114a9f05a6 | 7 | Serial SerialUART(PA_2, PA_3); |
SMART_CLEO | 0:49114a9f05a6 | 8 | |
SMART_CLEO | 0:49114a9f05a6 | 9 | uint8_t Buffer[37]; |
SMART_CLEO | 0:49114a9f05a6 | 10 | |
SMART_CLEO | 1:611e7e2a13df | 11 | int pir_flag = 0; |
SMART_CLEO | 0:49114a9f05a6 | 12 | |
SMART_CLEO | 1:611e7e2a13df | 13 | void PIR_ISR(void); |
SMART_CLEO | 0:49114a9f05a6 | 14 | void Sensor_Read_Data(uint8_t data); |
SMART_CLEO | 0:49114a9f05a6 | 15 | |
SMART_CLEO | 0:49114a9f05a6 | 16 | int main() { |
SMART_CLEO | 0:49114a9f05a6 | 17 | |
SMART_CLEO | 1:611e7e2a13df | 18 | uint8_t PIR_check = 0; |
SMART_CLEO | 0:49114a9f05a6 | 19 | |
SMART_CLEO | 0:49114a9f05a6 | 20 | SerialUART.baud(115200); |
SMART_CLEO | 0:49114a9f05a6 | 21 | |
SMART_CLEO | 1:611e7e2a13df | 22 | Pir.rise(&PIR_ISR); |
SMART_CLEO | 0:49114a9f05a6 | 23 | |
SMART_CLEO | 0:49114a9f05a6 | 24 | while(1) |
SMART_CLEO | 0:49114a9f05a6 | 25 | { |
SMART_CLEO | 1:611e7e2a13df | 26 | if(pir_flag) |
SMART_CLEO | 1:611e7e2a13df | 27 | { |
SMART_CLEO | 1:611e7e2a13df | 28 | pir_flag = 0; |
SMART_CLEO | 1:611e7e2a13df | 29 | if(PIR_check == 0) |
SMART_CLEO | 1:611e7e2a13df | 30 | { |
SMART_CLEO | 1:611e7e2a13df | 31 | Sensor_Read_Data(1); |
SMART_CLEO | 1:611e7e2a13df | 32 | PIR_check = 1; |
SMART_CLEO | 1:611e7e2a13df | 33 | } |
SMART_CLEO | 1:611e7e2a13df | 34 | wait(1); |
SMART_CLEO | 1:611e7e2a13df | 35 | } |
SMART_CLEO | 1:611e7e2a13df | 36 | else if(PIR_check) |
SMART_CLEO | 0:49114a9f05a6 | 37 | { |
SMART_CLEO | 0:49114a9f05a6 | 38 | Sensor_Read_Data(0); |
SMART_CLEO | 1:611e7e2a13df | 39 | PIR_check = 0; |
SMART_CLEO | 0:49114a9f05a6 | 40 | wait(1); |
SMART_CLEO | 0:49114a9f05a6 | 41 | } |
SMART_CLEO | 0:49114a9f05a6 | 42 | } |
SMART_CLEO | 0:49114a9f05a6 | 43 | } |
SMART_CLEO | 0:49114a9f05a6 | 44 | |
SMART_CLEO | 1:611e7e2a13df | 45 | void PIR_ISR(void) |
SMART_CLEO | 0:49114a9f05a6 | 46 | { |
SMART_CLEO | 1:611e7e2a13df | 47 | pir_flag = 1; |
SMART_CLEO | 1:611e7e2a13df | 48 | } |
SMART_CLEO | 0:49114a9f05a6 | 49 | |
SMART_CLEO | 0:49114a9f05a6 | 50 | void Sensor_Read_Data(uint8_t data) |
SMART_CLEO | 0:49114a9f05a6 | 51 | { |
SMART_CLEO | 0:49114a9f05a6 | 52 | Buffer[0] = 0x76; |
SMART_CLEO | 0:49114a9f05a6 | 53 | Buffer[1] = 0x01; |
SMART_CLEO | 1:611e7e2a13df | 54 | Buffer[2] = 0x10; |
SMART_CLEO | 0:49114a9f05a6 | 55 | Buffer[3] = 0x01; |
SMART_CLEO | 0:49114a9f05a6 | 56 | Buffer[4] = data; |
SMART_CLEO | 0:49114a9f05a6 | 57 | Buffer[5] = 0x3E; |
SMART_CLEO | 0:49114a9f05a6 | 58 | for(int i=0; i<6; i++) |
SMART_CLEO | 0:49114a9f05a6 | 59 | SerialUART.putc(Buffer[i]); |
SMART_CLEO | 1:611e7e2a13df | 60 | } |