tq_sdt_led.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. #include "tq_sdt_led.h"
  2. #include "ALL_Includes.h"
  3. #include <stdbool.h>
  4. #include "stm32f0xx_exti.h"
  5. #include "stm32f0xx_syscfg.h"
  6. #include "tq.h"
  7. uint8_t data_[20];
  8. uint16_t data1_[20];
  9. uint8_t buf [40];
  10. uint8_t i,pos,posi,sendpos,temp,startTQ=0;
  11. uint16_t timer;
  12. extern uint8_t sendbuf[10];
  13. extern uint8_t MyType;
  14. extern void sendstr(void);
  15. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. void NVIC_init(uint8_t NVIC_IRQChannel,uint8_t Priority)
  17. {
  18. NVIC_InitTypeDef NVIC_InitStruct;
  19. NVIC_InitStruct.NVIC_IRQChannel = NVIC_IRQChannel;
  20. NVIC_InitStruct.NVIC_IRQChannelPriority = Priority;
  21. NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
  22. NVIC_Init(&NVIC_InitStruct);
  23. }
  24. void TQ_SDT_Init(void)
  25. {
  26. EXTI_InitTypeDef EXTI_InitStruct;
  27. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  28. config_io_PuPd_DOWN(GPIOA, GPIO_Pin_5);
  29. config_io_PuPd_DOWN(GPIOA, GPIO_Pin_7);
  30. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  31. NVIC_init(EXTI4_15_IRQn,0x02);
  32. SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource5);
  33. EXTI_ClearITPendingBit(EXTI_Line5);
  34. EXTI_InitStruct.EXTI_Line = EXTI_Line5;
  35. EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
  36. if (MyType == 6) EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
  37. else EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
  38. EXTI_InitStruct.EXTI_LineCmd = ENABLE;
  39. EXTI_Init(&EXTI_InitStruct);
  40. if (MyType==2 || MyType==5 || MyType==6|| MyType==7) //EZ4300 or 1040XL or 2500
  41. {
  42. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  43. config_io_PuPd_DOWN(GPIOB, GPIO_Pin_1);
  44. NVIC_init(EXTI0_1_IRQn,0x01);
  45. SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource1);
  46. EXTI_ClearITPendingBit(EXTI_Line1);
  47. EXTI_InitStruct.EXTI_Line = EXTI_Line1;
  48. EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
  49. if (MyType == 6 || MyType == 7) EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
  50. else EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
  51. EXTI_InitStruct.EXTI_LineCmd = ENABLE;
  52. EXTI_Init(&EXTI_InitStruct);
  53. }
  54. }
  55. void I2C_InitConfig(void)
  56. {
  57. GPIO_InitTypeDef GPIO_InitStructure;
  58. I2C_InitTypeDef I2C_InitStructure;
  59. NVIC_InitTypeDef NVIC_InitStruct;
  60. //GPIO配置,I2C1:PA9->SCL, PA10->SDA
  61. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  62. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
  63. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  64. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  65. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  66. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  67. GPIO_Init(GPIOA, &GPIO_InitStructure);
  68. GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_4);
  69. GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_4);
  70. //I2C初始化
  71. RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  72. RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); //I2C1时钟源设置为SYSCLK
  73. I2C_DeInit(I2C1);
  74. I2C_Cmd(I2C1, DISABLE);
  75. I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; //I2C模式
  76. I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;//7位地址模式
  77. I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable; //模拟滤波启用
  78. I2C_InitStructure.I2C_DigitalFilter = 0x00; //数字滤波禁用
  79. I2C_InitStructure.I2C_OwnAddress1 = 0x38<<1; //本机I2C地址
  80. I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; //ACK启用
  81. I2C_InitStructure.I2C_Timing = 0x20E30000;
  82. I2C_Init(I2C1, &I2C_InitStructure);
  83. I2C1->CR1|=0x7F<<1; //开启中断
  84. NVIC_init(I2C1_IRQn,0x01);
  85. NVIC_Init(&NVIC_InitStruct);
  86. I2C_Cmd(I2C1, ENABLE); //开启I2C
  87. }
  88. void printnum_1040(int iii)
  89. {
  90. switch (iii)
  91. {
  92. case 0x1100: sendbuf[sendpos] = 0x2D; break;
  93. case 0x00FC: sendbuf[sendpos] = 0x30; break;
  94. case 0x0018: sendbuf[sendpos] = 0x31; break;
  95. case 0x116C: sendbuf[sendpos] = 0x32; break;
  96. case 0x113C: sendbuf[sendpos] = 0x33; break;
  97. case 0x1198: sendbuf[sendpos] = 0x34; break;
  98. case 0x11B4: sendbuf[sendpos] = 0x35; break;
  99. case 0x11F4: sendbuf[sendpos] = 0x36; break;
  100. case 0x001C: sendbuf[sendpos] = 0x37; break;
  101. case 0x11FC: sendbuf[sendpos] = 0x38; break;
  102. case 0x119C: sendbuf[sendpos] = 0x39; break;
  103. case 0x02: sendbuf[sendpos] = 0x02; break;
  104. //case 0x20: sendbuf[sendpos] = 0x20; break;
  105. case 0x0D: sendbuf[sendpos] = 0x0D; break;
  106. case 0x00: sendbuf[sendpos] = 0x20; break;
  107. default: sendbuf[sendpos] = 0xFF; break;
  108. }
  109. sendpos++;
  110. }
  111. void printnum_2500(int iii)
  112. {
  113. switch (iii)
  114. {
  115. case 0x2529: sendbuf[sendpos] = 0x30; break;
  116. case 0x0500: sendbuf[sendpos] = 0x31; break;
  117. case 0x2325: sendbuf[sendpos] = 0x32; break;
  118. case 0x2724: sendbuf[sendpos] = 0x33; break;
  119. case 0x070C: sendbuf[sendpos] = 0x34; break;
  120. case 0x262C: sendbuf[sendpos] = 0x35; break;
  121. case 0x262D: sendbuf[sendpos] = 0x36; break;
  122. case 0x2625: sendbuf[sendpos] = 0x36; break;
  123. case 0x0520: sendbuf[sendpos] = 0x37; break;
  124. case 0x272D: sendbuf[sendpos] = 0x38; break;
  125. case 0x272C: sendbuf[sendpos] = 0x39; break;
  126. case 0x0204: sendbuf[sendpos] = 0x2D; break;
  127. case 0x02: sendbuf[sendpos] = 0x02; break;
  128. case 0x20: sendbuf[sendpos] = 0x20; break;
  129. case 0x0D: sendbuf[sendpos] = 0x0D; break;
  130. default: sendbuf[sendpos] = 0x20; break;
  131. }
  132. sendpos++;
  133. }
  134. void EXTI0_1_IRQHandler(void)
  135. {
  136. u8 i;
  137. if ( EXTI_GetITStatus(EXTI_Line1)!= RESET )
  138. {
  139. EXTI_ClearITPendingBit(EXTI_Line1);
  140. if (MyType==5 && pos>=113)
  141. {
  142. sendpos=0;
  143. for (i=0;i<6;i++) sendbuf[i]=0;
  144. printnum_1040(data1_[4]);
  145. printnum_1040(data1_[3]);
  146. printnum_1040(data1_[2]);
  147. printnum_1040(data1_[1]);
  148. printnum_1040(data1_[0]);
  149. printnum_1040(0x0D);
  150. for(i=0;i<20;i++) data1_[i]=0;
  151. sendstr();
  152. };
  153. pos=0;
  154. posi=0;
  155. startTQ=1;
  156. }
  157. }
  158. void printnum_sitrex(int iii)
  159. {
  160. switch (iii)
  161. {
  162. case 0x7E: sendbuf[sendpos] = 0x30; break;
  163. case 0x0C: sendbuf[sendpos] = 0x31; break;
  164. case 0xB6: sendbuf[sendpos] = 0x32; break;
  165. case 0x9E: sendbuf[sendpos] = 0x33; break;
  166. case 0xCC: sendbuf[sendpos] = 0x34; break;
  167. case 0xDA: sendbuf[sendpos] = 0x35; break;
  168. case 0xFA: sendbuf[sendpos] = 0x36; break;
  169. case 0x0E: sendbuf[sendpos] = 0x37; break;
  170. case 0xFE: sendbuf[sendpos] = 0x38; break;
  171. case 0xDE: sendbuf[sendpos] = 0x39; break;
  172. case 0x80: sendbuf[sendpos] = 0x2D; break;
  173. case 0x02: sendbuf[sendpos] = 0x02; break;
  174. case 0x20: sendbuf[sendpos] = 0x20; break;
  175. case 0x0D: sendbuf[sendpos] = 0x0D; break;
  176. default: sendbuf[sendpos] = 0x20; break;
  177. }
  178. sendpos++;
  179. }
  180. void EXTI4_15_IRQHandler(void)
  181. {
  182. u8 i;
  183. if ( EXTI_GetITStatus(EXTI_Line5)!= RESET )
  184. {
  185. EXTI_ClearITPendingBit(EXTI_Line5);
  186. temp = ((GPIOA->IDR&GPIO_Pin_7)>0)&1;
  187. if (MyType==1)
  188. {
  189. if (pos>0 && pos<9 ) data_[0]=(data_[0]<<1)|temp;
  190. else if (pos<17) data_[1]=(data_[1]<<1)|temp;
  191. else if (pos<25) data_[2]=(data_[2]<<1)|temp;
  192. else if (pos<33) data_[3]=(data_[3]<<1)|temp;
  193. else if (pos<=35) data_[4]=(data_[4]<<1)|temp;
  194. pos++;
  195. }
  196. else if (MyType==2)
  197. {
  198. if (startTQ)
  199. {
  200. posi=pos>>3;
  201. data_[posi]=(data_[posi]<<1)|temp;
  202. pos++;
  203. if (pos>=143)
  204. {
  205. EZ_TQ();//结束
  206. pos=0;
  207. startTQ=0;
  208. }
  209. }
  210. }
  211. else if (MyType==4)
  212. {
  213. posi=pos>>3;
  214. data_[posi]=(data_[posi]<<1)|temp;
  215. pos++;
  216. if (posi==12)
  217. {
  218. sendpos = 0;
  219. for (i=7;i<12;i++) printnum_sitrex(data_[i]);
  220. printnum_sitrex(0x0D);
  221. sendstr();
  222. }
  223. else if (pos%8==0)
  224. {
  225. if ((data_[posi] ==0x04) || (data_[posi] ==0x08))
  226. {
  227. pos = 8;
  228. data_[0] = data_[posi];
  229. // startTQ=1;
  230. }
  231. }
  232. }
  233. else if (MyType==5)
  234. {
  235. temp = ~temp;
  236. if (startTQ)
  237. {
  238. if (pos>96 && pos<113)
  239. {
  240. data1_[0]=data1_[0]<<1;
  241. data1_[0]=data1_[0]|(temp&0x01);
  242. }
  243. else if (pos>80)
  244. {
  245. data1_[1]=data1_[1]<<1;
  246. data1_[1]=data1_[1]|(temp&0x01);
  247. }
  248. else if (pos>64)
  249. {
  250. data1_[2]=data1_[2]<<1;
  251. data1_[2]=data1_[2]|(temp&0x01);
  252. }
  253. else if (pos>48)
  254. {
  255. data1_[3]=data1_[3]<<1;
  256. data1_[3]=data1_[3]|(temp&0x01);
  257. }
  258. else if (pos>32)
  259. {
  260. data1_[4]=data1_[4]<<1;
  261. data1_[4]=data1_[4]|(temp&0x01);
  262. }
  263. else if (pos>16)
  264. {
  265. data1_[5]=data1_[5]<<1;
  266. data1_[5]=data1_[5]|(temp&0x011);
  267. }
  268. pos++;
  269. }
  270. }
  271. else if (MyType == 6||MyType == 7)
  272. {
  273. if (startTQ)
  274. {
  275. posi=pos>>3;
  276. data_[posi]=(data_[posi]<<1)|temp;
  277. pos++;
  278. if (pos>=160)
  279. {
  280. EZ_2500();//结束
  281. for(i=0;i<20;i++) data_[i]=0;
  282. pos=0;
  283. startTQ=0;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. void printnum_(uint8_t iii)
  290. {
  291. iii = (iii&0xFE)>>1;
  292. switch (iii)
  293. {
  294. case 0x01: sendbuf[sendpos] = 0x2D; break;
  295. case 0x7E: sendbuf[sendpos] = 0x30; break;
  296. case 0x30: sendbuf[sendpos] = 0x31; break;
  297. case 0x6D: sendbuf[sendpos] = 0x32; break;
  298. case 0x79: sendbuf[sendpos] = 0x33; break; ///////////////////
  299. case 0x33: sendbuf[sendpos] = 0x34; break;
  300. case 0x5B: sendbuf[sendpos] = 0x35; break; ////////////
  301. case 0x5F: sendbuf[sendpos] = 0x36; break; //////////////
  302. case 0x70: sendbuf[sendpos] = 0x37; break;
  303. case 0x7F: sendbuf[sendpos] = 0x38; break; ////////////////////
  304. case 0x7B: sendbuf[sendpos] = 0x39; break;
  305. case 0x02: sendbuf[sendpos] = 0x02; break;
  306. case 0x20: sendbuf[sendpos] = 0x20; break;
  307. case 0x0D: sendbuf[sendpos] = 0x0D; break;
  308. case 0x00: sendbuf[sendpos] = 0x20; break;
  309. case 0x40: sendbuf[sendpos] = 0x20; break;
  310. default: sendbuf[sendpos] = 0xFF; break;
  311. }
  312. sendpos++;
  313. }
  314. void printnum_ez(int iii)
  315. {
  316. switch (iii)
  317. {
  318. case 0x2625: sendbuf[sendpos] = 0x30; break;
  319. case 0x2200: sendbuf[sendpos] = 0x31; break;
  320. case 0x07A4: sendbuf[sendpos] = 0x32; break;
  321. case 0x2784: sendbuf[sendpos] = 0x33; break;
  322. case 0x2381: sendbuf[sendpos] = 0x34; break;
  323. case 0x2585: sendbuf[sendpos] = 0x35; break;
  324. case 0x25A5: sendbuf[sendpos] = 0x36; break;
  325. case 0x2204: sendbuf[sendpos] = 0x37; break;
  326. case 0x27A5: sendbuf[sendpos] = 0x38; break;
  327. case 0x2785: sendbuf[sendpos] = 0x39; break;
  328. case 0x0300: sendbuf[sendpos] = 0x2D; break;
  329. case 0x02: sendbuf[sendpos] = 0x02; break;
  330. case 0x20: sendbuf[sendpos] = 0x20; break;
  331. case 0x0D: sendbuf[sendpos] = 0x0D; break;
  332. default: sendbuf[sendpos] = 0x20; break;
  333. }
  334. sendpos++;
  335. }
  336. void EZ_TQ(void)
  337. {
  338. int x,y,z, xx;
  339. x = data_[6] & 0x40;
  340. if (x==0x40)
  341. {
  342. sendpos = 0;
  343. printnum_ez(0x02);
  344. x = (data_[9] & 0x0F)<<10;
  345. y = (data_[13] & 0x1F)<<5;
  346. z = (data_[17] & 0x1F);
  347. xx = x|y|z;
  348. printnum_ez(xx);
  349. if ((data_[8] & 0x07)==0x02 && (data_[12] & 0x07)==0x04)
  350. printnum_ez(0x2200);
  351. else
  352. printnum_ez(0x20);
  353. x = (data_[8] & 0x78)<<7;
  354. y = (data_[12] & 0xF8)<<2;
  355. z = (data_[16] & 0xF8)>>3;
  356. xx = x|y|z;
  357. printnum_ez(xx);
  358. x = (data_[7] & 0x0F)<<10;
  359. y = (data_[11] & 0x1F)<<5;
  360. z = data_[15] & 0x1F;
  361. xx = x|y|z;
  362. printnum_ez(xx);
  363. x = (((data_[6] & 0x01)<<3)|((data_[7] & 0xE0)>>5))<<10;
  364. y = (((data_[10] & 0x03)<<3)|((data_[11] & 0xE0)>>5))<<5;
  365. z = (((data_[14] & 0x03)<<3)|((data_[15] & 0xE0)>>5));
  366. xx = x|y|z;
  367. printnum_ez(xx);
  368. x = (data_[6] & 0x3C)<<8;
  369. y = (data_[10] & 0x7C)<<3;
  370. z = (data_[14] & 0x7C)>>2;
  371. xx = x|y|z;
  372. printnum_ez(xx);
  373. printnum_ez(0x0D);
  374. sendstr();
  375. }
  376. }
  377. void EZ_2500(void)
  378. {
  379. u16 i;
  380. sendpos=0;
  381. for (i=0;i<6;i++) sendbuf[i]=0;
  382. i = data_[16]<< 8 | data_[17];
  383. if (i==0x0204){
  384. printnum_2500(i);
  385. }
  386. else{
  387. i = data_[14]<< 8 | data_[15];
  388. printnum_2500(i);
  389. }
  390. i = data_[12]<< 8 | data_[13];
  391. printnum_2500(i);
  392. i = data_[10]<< 8 | data_[11];
  393. printnum_2500(i);
  394. i = data_[8]<< 8 | data_[9];
  395. printnum_2500(i);
  396. i = data_[6]<< 8 | data_[7];
  397. printnum_2500(i);
  398. printnum_2500(0x0D);
  399. for(i=0;i<20;i++) data1_[i]=0;
  400. sendstr();
  401. }
  402. void SDT_TQ(void)
  403. {
  404. uint8_t i;
  405. if (timer>10)
  406. {
  407. if (pos>0x23)
  408. {
  409. sendpos=0;
  410. for (i=0;i<8;i++) sendbuf[i]=0;
  411. printnum_(0x0D<<1);
  412. printnum_(data_[0]);
  413. printnum_(data_[1]);
  414. printnum_(data_[2]);
  415. printnum_(data_[3]);
  416. if(data_[4]==0x01) printnum_(0x30<<1);
  417. else printnum_(0x20<<1);
  418. sendstr();
  419. pos=0;
  420. }
  421. else LED_Off();
  422. timer=0;
  423. }
  424. }
  425. u8 LED_Coding(u8 temp,u8 tempp)
  426. {
  427. u8 out;
  428. u8 in1,in2;
  429. in1 = temp;
  430. in2 = tempp;
  431. if((in1 == 0x00) && (in2 == 0x00)) out = 0x20;
  432. else if((in1 == 0xe0) && (in2 == 0x07)) out = 0x30;
  433. else if((in1 == 0x60) && (in2 == 0x00)) out = 0x31;
  434. else if((in1 == 0xc4) && (in2 == 0x23)) out = 0x32;
  435. else if((in1 == 0xe0) && (in2 == 0x21)) out = 0x33;
  436. else if((in1 == 0x64) && (in2 == 0x24)) out = 0x34;
  437. else if((in1 == 0xA4) && (in2 == 0x25)) out = 0x35;
  438. else if((in1 == 0xa4) && (in2 == 0x27)) out = 0x36;
  439. else if((in1 == 0xe0) && (in2 == 0x00)) out = 0x37;
  440. else if((in1 == 0xe4) && (in2 == 0x27)) out = 0x38;
  441. else if((in1 == 0xe4) && (in2 == 0x25)) out = 0x39;
  442. else if((in1 == 0x00) && (in2 == 0x20)) out = 0x2D;
  443. else if((in1 == 0xff) && (in2 == 0xff)) out = 0x0D;
  444. else out = 0xff;
  445. sendbuf[sendpos++] = out;
  446. return out;
  447. }
  448. u8 LED_Coding_640(u8 temp,u8 tempp)
  449. {
  450. u8 out;
  451. u8 in1,in2;
  452. in1 = temp;
  453. in2 = tempp;
  454. if((in1 == 0x00) && (in2 == 0x00)) out = 0x20;
  455. else if((in1 == 0x00) && (in2 == 0xFC)) out = 0x30;
  456. else if((in1 == 0x00) && (in2 == 0x18)) out = 0x31;
  457. else if((in1 == 0x11) && (in2 == 0x6C)) out = 0x32;
  458. else if((in1 == 0x11) && (in2 == 0x3C)) out = 0x33;
  459. else if((in1 == 0x11) && (in2 == 0x98)) out = 0x34;
  460. else if((in1 == 0x11) && (in2 == 0xB4)) out = 0x35;
  461. else if((in1 == 0x11) && (in2 == 0xF4)) out = 0x36;
  462. else if((in1 == 0x00) && (in2 == 0x1C)) out = 0x37;
  463. else if((in1 == 0x11) && (in2 == 0xFC)) out = 0x38;
  464. else if((in1 == 0x11) && (in2 == 0x9C)) out = 0x39;
  465. else if((in1 == 0x11) && (in2 == 0x00)) out = 0x2D;
  466. else if((in1 == 0xff) && (in2 == 0xff)) out = 0x0D;
  467. else out = 0xff;
  468. sendbuf[sendpos++] = out;
  469. return out;
  470. }
  471. u16 RecIndex=0; //接收索引,用于处理接收数据流程
  472. void I2C1_IRQHandler(void)
  473. {
  474. u8 i;
  475. __IO uint32_t I2CFlagStatus = 0x00000000;
  476. I2CFlagStatus = (uint32_t)(I2C1->ISR & (uint16_t)0x0000100FE);
  477. if ((I2CFlagStatus & I2C_ISR_ADDR) != 0)
  478. {
  479. if((I2C1->ISR&I2C_ISR_DIR)==0) //rx mode
  480. {
  481. RecIndex= 0;
  482. for(i=0;i<20;i++) data_[i]=0;
  483. I2C1->ICR |= I2C_ICR_ADDRCF;
  484. }
  485. }
  486. else if ((I2CFlagStatus & I2C_ISR_RXNE) != 0)
  487. {
  488. data_[RecIndex++] = I2C_ReceiveData(I2C1);
  489. if(RecIndex>=30) RecIndex=0;
  490. else if (data_[0]==0xCD && RecIndex==19)
  491. {
  492. RecIndex = 0;
  493. sendpos=0;
  494. for (i=0;i<8;i++) sendbuf[i]=0;
  495. LED_Coding_640(0xFF,0xFF);
  496. LED_Coding_640(data_[17],data_[18]);
  497. LED_Coding_640(data_[15],data_[16]);
  498. LED_Coding_640(data_[13],data_[14]);
  499. LED_Coding_640(data_[11],data_[12]);
  500. LED_Coding_640(data_[9],data_[10]);
  501. sendstr();
  502. }
  503. else if (data_[0]==0xE0 && RecIndex==12)
  504. {
  505. RecIndex = 0;
  506. sendpos=0;
  507. for (i=0;i<8;i++) sendbuf[i]=0;
  508. LED_Coding(0xFF,0xFF);
  509. LED_Coding(data_[2],data_[3]);
  510. LED_Coding(data_[4],data_[5]);
  511. LED_Coding(data_[6],data_[7]);
  512. LED_Coding(data_[8],data_[9]);
  513. LED_Coding(data_[10],data_[11]);
  514. sendstr();
  515. }
  516. }
  517. else if ((I2CFlagStatus & I2C_ISR_STOPF) != 0)
  518. {
  519. I2C1->ICR |= I2C_ICR_STOPCF;
  520. if (data_[0]==0xE0)
  521. {
  522. RecIndex = 0;
  523. sendpos=0;
  524. for (i=0;i<8;i++) sendbuf[i]=0;
  525. LED_Coding(0xFF,0xFF);
  526. LED_Coding(data_[2],data_[3]);
  527. LED_Coding(data_[4],data_[5]);
  528. LED_Coding(data_[6],data_[7]);
  529. LED_Coding(data_[8],data_[9]);
  530. LED_Coding(data_[10],data_[11]);
  531. sendstr();
  532. } else if (data_[0]==0xCD)
  533. {
  534. RecIndex = 0;
  535. sendpos=0;
  536. for (i=0;i<8;i++) sendbuf[i]=0;
  537. LED_Coding_640(0xFF,0xFF);
  538. LED_Coding_640(data_[17],data_[18]);
  539. LED_Coding_640(data_[15],data_[16]);
  540. LED_Coding_640(data_[13],data_[14]);
  541. LED_Coding_640(data_[11],data_[12]);
  542. LED_Coding_640(data_[9],data_[10]);
  543. sendstr();
  544. }
  545. }
  546. }
  547. ///////////////////////////////////////////////////////////////////////////////////////////////////////