robocon_2016
/
2016_slave_cylinder
CY1_9/30
main.cpp@0:347fe1fcc3d3, 2016-09-30 (annotated)
- Committer:
- sgrsn
- Date:
- Fri Sep 30 12:29:55 2016 +0000
- Revision:
- 0:347fe1fcc3d3
CE1_9/30
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:347fe1fcc3d3 | 1 | #include "mbed.h" |
sgrsn | 0:347fe1fcc3d3 | 2 | #include "i2cslave.h" |
sgrsn | 0:347fe1fcc3d3 | 3 | #include "define.h" |
sgrsn | 0:347fe1fcc3d3 | 4 | |
sgrsn | 0:347fe1fcc3d3 | 5 | char Registar[128]= {}; |
sgrsn | 0:347fe1fcc3d3 | 6 | void check(); |
sgrsn | 0:347fe1fcc3d3 | 7 | BusOut cylinders(dp2, dp6, dp10, dp14, dp17, dp18, dp25, dp28); |
sgrsn | 0:347fe1fcc3d3 | 8 | |
sgrsn | 0:347fe1fcc3d3 | 9 | int main() |
sgrsn | 0:347fe1fcc3d3 | 10 | { |
sgrsn | 0:347fe1fcc3d3 | 11 | NVIC_SetPriority(TIMER_16_0_IRQn, 20); |
sgrsn | 0:347fe1fcc3d3 | 12 | NVIC_SetPriority(TIMER_16_1_IRQn, 20); |
sgrsn | 0:347fe1fcc3d3 | 13 | NVIC_SetPriority(TIMER_32_0_IRQn, 20); |
sgrsn | 0:347fe1fcc3d3 | 14 | NVIC_SetPriority(TIMER_32_1_IRQn, 20); |
sgrsn | 0:347fe1fcc3d3 | 15 | NVIC_SetPriority(I2C_IRQn, 10); |
sgrsn | 0:347fe1fcc3d3 | 16 | i2cslave i2c(dp5, dp27, Registar); |
sgrsn | 0:347fe1fcc3d3 | 17 | i2c.address(CY1_addr); |
sgrsn | 0:347fe1fcc3d3 | 18 | i2c.frequency(1000000); |
sgrsn | 0:347fe1fcc3d3 | 19 | Ticker tic; |
sgrsn | 0:347fe1fcc3d3 | 20 | tic.attach(check, 0.1); |
sgrsn | 0:347fe1fcc3d3 | 21 | while(1) |
sgrsn | 0:347fe1fcc3d3 | 22 | { |
sgrsn | 0:347fe1fcc3d3 | 23 | cylinders = Registar[motor1_state]; |
sgrsn | 0:347fe1fcc3d3 | 24 | } |
sgrsn | 0:347fe1fcc3d3 | 25 | } |
sgrsn | 0:347fe1fcc3d3 | 26 | |
sgrsn | 0:347fe1fcc3d3 | 27 | void check() |
sgrsn | 0:347fe1fcc3d3 | 28 | { |
sgrsn | 0:347fe1fcc3d3 | 29 | Registar[check_reg]++; |
sgrsn | 0:347fe1fcc3d3 | 30 | if(Registar[check_reg] > 2) |
sgrsn | 0:347fe1fcc3d3 | 31 | { |
sgrsn | 0:347fe1fcc3d3 | 32 | NVIC_SystemReset(); |
sgrsn | 0:347fe1fcc3d3 | 33 | } |
sgrsn | 0:347fe1fcc3d3 | 34 | } |