0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看威廉希尔官方网站 视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

【南京中科微CSM32RV20开发板试用体验】+2-oled rtc的使用

开发板试用精选 来源:开发板试用 作者:电子发烧友论坛 2022-11-30 10:47 次阅读
本文来源电子发烧友社区,作者:卢松涛, 帖子地址:https://bbs.elecfans.com/jishu_2249213_1_1.html

在"【南京中科微CSM32RV20开发板试用体验】+1-GPIO口串口的使用"基础上增加
oled rtc

硬件IIC非中断的使用:
///---- Chapter 12 I2C Test Init -------------------------------------------------------------------------------------
uint8_t i2c_data;
I2C_Init_case1();//非中断模式
rtc的使用:
///---- Chapter 7 RTC Test Init --------------------------------------------------------------------------------------
//RTC_Init_case1();
RTC_Init_case2();

Interrupt_Level(MtiMER_int_ID, INT_LEVEL2 );//CLIC设置中断抢占级别
Interrupt_Enable(MTIMER_int_ID);//CLIC使能中断
SYS_Interrupt_Enable();//CLIC开总中断


  1. #include "headfile.h"
  2. #ifndef __OLEDFONT_H
  3. #define __OLEDFONT_H
  4. //常用ASCII表
  5. //偏移量32
  6. //ASCII字符集
  7. //偏移量32
  8. //大小:12*6
  9. /************************************6*8的点阵************************************/
  10. const unsigned char F6x8[][6] =
  11. {
  12. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
  13. 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
  14. 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
  15. 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
  16. 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
  17. 0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
  18. 0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
  19. 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
  20. 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
  21. 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
  22. 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
  23. 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
  24. 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
  25. 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
  26. 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
  27. 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
  28. 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
  29. 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
  30. 0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
  31. 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
  32. 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
  33. 0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
  34. 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
  35. 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
  36. 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
  37. 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
  38. 0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
  39. 0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
  40. 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
  41. 0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
  42. 0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
  43. 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
  44. 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
  45. 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
  46. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
  47. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
  48. 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
  49. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
  50. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
  51. 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
  52. 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
  53. 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
  54. 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
  55. 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
  56. 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
  57. 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
  58. 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
  59. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
  60. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
  61. 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
  62. 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
  63. 0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
  64. 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
  65. 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
  66. 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
  67. 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
  68. 0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
  69. 0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
  70. 0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
  71. 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
  72. 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
  73. 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
  74. 0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
  75. 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
  76. 0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
  77. 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
  78. 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
  79. 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
  80. 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
  81. 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
  82. 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
  83. 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
  84. 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
  85. 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
  86. 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
  87. 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
  88. 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
  89. 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
  90. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
  91. 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
  92. 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
  93. 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
  94. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
  95. 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
  96. 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
  97. 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
  98. 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
  99. 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
  100. 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
  101. 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
  102. 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
  103. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
  104. };
  105. /****************************************8*16的点阵************************************/
  106. const unsigned char F8X16[]=
  107. {
  108. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//0
  109. 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  110. 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  111. 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  112. 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  113. 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  114. 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  115. 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  116. 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  117. 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  118. 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  119. 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  120. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  121. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  122. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  123. 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  124. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  125. 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  126. 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  127. 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  128. 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  129. 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  130. 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  131. 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  132. 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  133. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  134. 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  135. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  136. 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  137. 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  138. 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  139. 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  140. 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  141. 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  142. 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  143. 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  144. 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  145. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  146. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  147. 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  148. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  149. 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  150. 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  151. 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  152. 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  153. 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  154. 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  155. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  156. 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  157. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  158. 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  159. 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  160. 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  161. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  162. 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  163. 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  164. 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  165. 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  166. 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  167. 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  168. 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// 60
  169. 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  170. 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  171. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  172. 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  173. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  174. 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  175. 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  176. 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  177. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  178. 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  179. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  180. 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  181. 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  182. 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  183. 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  184. 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  185. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  186. 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  187. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  188. 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  189. 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  190. 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  191. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  192. 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  193. 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  194. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  195. 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  196. 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  197. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  198. 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  199. 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  200. 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  201. 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  202. 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
  203. };
  204. /***********************************************
  205. PCtoLCD2002设置
  206. 阴码,逆向,C51格式,十六进制数据,列行式,输出三个全选中
  207. 每行显示点阵9999,索引9999
  208. 格式: 段前缀 【无】;
  209. 段后缀 【无】;
  210. 注释前缀(右边空格去掉) 【/ *"】;
  211. 注释后缀 【",】;
  212. 数据后缀 【,】;
  213. 行前缀 【{】;
  214. 行后缀 【},】
  215. **********************************************/
  216. /***********************************
  217. 16x16汉字
  218. 取字软件:PCtoLCD2002
  219. 使用方法见文档
  220. ***********************************/
  221. const unsigned char Chinese_Word_16[][32]= {
  222. {0x84,0x84,0xFC,0x84,0x84,0x40,0x64,0x54,0x4C,0x47,0x4C,0x54,0xE4,0x44,0x40,0x00,0x10,0x30,0x1F,0x08,0x08,0x00,0x1F,0x11,0x11,0x1F,0x40,0x80,0x7F,0x00,0x00,0x00},/*"琦",0*/
  223. {0x00,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x02,0x7E,0x02,0x02,0x00,0x00,0x01,0x01,0x01,0x3D,0x25,0x25,0x25,0x25,0x3D,0x41,0x81,0x7F,0x01,0x01,0x01,0x00},/*"哥",1*/
  224. {0x00,0x40,0x20,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00},/*"牛",2*/
  225. {0x40,0x40,0x42,0xCC,0x00,0x82,0xBA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBA,0x82,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x5F,0x4A,0x4A,0x4A,0x4F,0x4A,0x4A,0x4A,0x5F,0x40,0x00},/*"逼",3*/
  226. };
  227. #endif
  228. void mp_receive_data(uint8_t *buf, uint16_t *len)
  229. {
  230. uint8_t rxlen = UART1_RX_CNT;
  231. uint16_t i = 0;
  232. *len = 0; //默认为0
  233. Delay32M_ms(10); //等待40ms,连续超过10ms没有接收到一个数据,则认为接收结束
  234. if (rxlen == UART1_RX_CNT && rxlen) //接收到了数据,且接收完成了
  235. {
  236. for (i = 0; i < rxlen; i++)
  237. {
  238. buf[i] = uart_dev.rxbuf[i];
  239. }
  240. *len = UART1_RX_CNT; //记录本次数据长度
  241. UART1_RX_CNT = 0; //清零
  242. uart_dev.frameok=1; //标记完成一帧数据接收
  243. // getData=0;//数据接收完成,标志位清零
  244. }
  245. }
  246. #define Max_Column 128
  247. void OLED_Write_IIC_Command(uint8_t IIC_Command)
  248. {
  249. I2C_Write(0x00,IIC_Command);
  250. }
  251. void OLED_Write_IIC_Data(uint8_t IIC_Data)
  252. {
  253. I2C_Write(0x40,IIC_Data);
  254. }
  255. /**
  256. * @brief :OLED_Clear
  257. * [url=home.php?mod=space&uid=1902110]@NOTE[/url] : --清屏函数
  258. --清完屏,整个屏幕是黑色的!和没点亮一样
  259. * @param : >>
  260. >>
  261. * @return :void
  262. *
  263. * @date :2021/01/29
  264. * [url=home.php?mod=space&uid=44345]@design[/url] :
  265. **/
  266. void OLED_Clear(void)
  267. {
  268. uint8_t i,n;
  269. for(i=0; i<8; i++)
  270. {
  271. OLED_Write_IIC_Command (0xb0+i); //设置页地址(0~7)
  272. OLED_Write_IIC_Command (0x00); //设置显示位置—列低地址
  273. OLED_Write_IIC_Command (0x10); //设置显示位置—列高地址
  274. for(n=0; n<128; n++)
  275. {
  276. OLED_Write_IIC_Data(0x00);
  277. }
  278. }
  279. //更新显示
  280. }
  281. /**
  282. * @brief :OLED_Set_Pos
  283. * @note : --坐标设置
  284. * @param : >>
  285. >>
  286. * @return :void
  287. *
  288. * @date :2021/01/29
  289. * @design :
  290. **/
  291. void OLED_Set_Pos(uint8_t x, uint8_t y)
  292. { OLED_Write_IIC_Command(0xb0+y);
  293. OLED_Write_IIC_Command(((x&0xf0)>>4)|0x10);
  294. OLED_Write_IIC_Command((x&0x0f));
  295. }
  296. /**
  297. * @brief :OLED_ShowChar
  298. * @note : --在指定位置显示一个字符,包括部分字符
  299. --例如:OLED_ShowChar(20,6,'A',16);
  300. * @param : >>
  301. >>x:0~127
  302. >>y:0~6
  303. >>mode:0,反白显示;1,正常显示
  304. >>size:选择字体 8/16
  305. * @return :void
  306. *
  307. * @date :2021/01/29
  308. * @design :
  309. **/
  310. void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size)
  311. {
  312. uint8_t c=0,i=0;
  313. c=chr-' ';//得到偏移后的值
  314. if(x>Max_Column-1) {
  315. x=0;
  316. y=y+2;
  317. }
  318. if(Char_Size ==16)
  319. {
  320. OLED_Set_Pos(x,y);
  321. for(i=0; i<8; i++)
  322. OLED_Write_IIC_Data(F8X16[c*16+i]);
  323. OLED_Set_Pos(x,y+1);
  324. for(i=0; i<8; i++)
  325. OLED_Write_IIC_Data(F8X16[c*16+i+8]);
  326. }
  327. else
  328. {
  329. OLED_Set_Pos(x,y);
  330. for(i=0; i<6; i++)
  331. OLED_Write_IIC_Data(F6x8[c][i]);
  332. }
  333. }
  334. /**
  335. * @brief :OLED_ShowString
  336. * @note : --显示一个字符号串
  337. --例如:
  338. u8 SET[2][3] = {{"ON "},{"OFF"}};
  339. OLED_ShowString(0,0,SET[0],8);
  340. * @param : >>
  341. >>size:选择字体 8/16
  342. * @return :void
  343. *
  344. * @date :2021/01/29
  345. * @design :
  346. **/
  347. void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
  348. {
  349. while (*chr!='')
  350. { OLED_ShowChar(x,y,*chr,Char_Size);
  351. x+=8;
  352. if(x>120) {
  353. x=0;
  354. y+=2;
  355. }
  356. chr++;
  357. }
  358. }
  359. /**********************************************
  360. //m^n函数
  361. **********************************************/
  362. uint32_t oled_pow(uint8_t m,uint8_t n)
  363. {
  364. uint32_t result=1;
  365. while(n--)result*=m;
  366. return result;
  367. }
  368. /**
  369. * @brief :OLED_ShowNumber
  370. * @note : --显示数字
  371. --例如:OLED_ShowNumber(0,0,45125215,10);
  372. * @param : >>x,y :起点坐标
  373. >>len :数字的位数
  374. >>size:字体大小默认16
  375. >>num:数值(0~4294967295);
  376. * @return :void
  377. *
  378. * @date :2021/01/29
  379. * @design :
  380. **/
  381. void OLED_ShowNumber(uint8_t x,uint8_t y,uint32_t num,uint8_t len)
  382. {
  383. uint8_t size2 = 16;
  384. uint8_t t,temp;
  385. uint8_t enshow=0;
  386. for(t=0; t;>
  387. {
  388. temp=(num/oled_pow(10,len-t-1))%10;
  389. if(enshow==0&&t<(len-1))
  390. {
  391. if(temp==0)
  392. {
  393. OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
  394. continue;
  395. } else enshow=1;
  396. }
  397. OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
  398. }
  399. }
  400. //初始化SSD1306
  401. void OLED_Init(void)
  402. {
  403. // OLED_GPIO_Init();
  404. Delay32M_ms(1500);
  405. // OLED_WR_Byte(0xAE,OLED_CMD);//--display off
  406. // OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  407. // OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  408. // OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
  409. // OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
  410. // OLED_WR_Byte(0x81,OLED_CMD); // contract control
  411. // OLED_WR_Byte(0xFF,OLED_CMD);//--128
  412. // OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
  413. // OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
  414. // OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  415. // OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
  416. // OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
  417. // OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
  418. // OLED_WR_Byte(0x00,OLED_CMD);//
  419. // OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
  420. // OLED_WR_Byte(0x80,OLED_CMD);//
  421. // OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
  422. // OLED_WR_Byte(0x05,OLED_CMD);//
  423. // OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
  424. // OLED_WR_Byte(0xF1,OLED_CMD);//
  425. // OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
  426. // OLED_WR_Byte(0x12,OLED_CMD);//
  427. // OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
  428. // OLED_WR_Byte(0x30,OLED_CMD);//
  429. // OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
  430. // OLED_WR_Byte(0x14,OLED_CMD);//
  431. // OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
  432. OLED_Write_IIC_Command(0xAE); //display off
  433. OLED_Write_IIC_Command(0x20); //Set Memory Addressing Mode
  434. OLED_Write_IIC_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
  435. OLED_Write_IIC_Command(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
  436. OLED_Write_IIC_Command(0xc8); //Set COM Output Scan Direction
  437. OLED_Write_IIC_Command(0x00); //---set low column address
  438. OLED_Write_IIC_Command(0x10); //---set high column address
  439. OLED_Write_IIC_Command(0x40); //--set start line address
  440. OLED_Write_IIC_Command(0x81); //--set contrast control register
  441. OLED_Write_IIC_Command(0xff); //亮度调节 0x00~0xff
  442. OLED_Write_IIC_Command(0xa1); //--set segment re-map 0 to 127
  443. OLED_Write_IIC_Command(0xa6); //--set normal display
  444. OLED_Write_IIC_Command(0xa8); //--set multiplex ratio(1 to 64)
  445. OLED_Write_IIC_Command(0x3F); //
  446. OLED_Write_IIC_Command(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
  447. OLED_Write_IIC_Command(0xd3); //-set display offset
  448. OLED_Write_IIC_Command(0x00); //-not offset
  449. OLED_Write_IIC_Command(0xd5); //--set display clock divide ratio/oscillator frequency
  450. OLED_Write_IIC_Command(0xf0); //--set divide ratio
  451. OLED_Write_IIC_Command(0xd9); //--set pre-charge period
  452. OLED_Write_IIC_Command(0x22); //
  453. OLED_Write_IIC_Command(0xda); //--set com pins hardware configuration
  454. OLED_Write_IIC_Command(0x12);
  455. OLED_Write_IIC_Command(0xdb); //--set vcomh
  456. OLED_Write_IIC_Command(0x20); //0x20,0.77xVcc
  457. OLED_Write_IIC_Command(0x8d); //--set DC-DC enable
  458. OLED_Write_IIC_Command(0x14); //
  459. OLED_Write_IIC_Command(0xaf); //--turn on oled panel
  460. }
  461. uint8_t ReceiveBuff[RECV_LEN];
  462. int main(void)
  463. {
  464. uint16_t rlen=0;
  465. uart_dev.rxlen=0;
  466. ///----System Init ---------------------------------------------------------------------------------------------
  467. CLIC_Init();//系统中断配置
  468. System_Clock_Init();//系统时钟初始化
  469. ///----Chapter 3 LowPower Test Init ---------------------------------------------------------------------------------
  470. //低功耗测功耗需要IO不能悬空
  471. //Delay32M_ms(5000);
  472. //LowPower_Config_case1();//所有IO设置为输入,下拉
  473. //LowPower_Config_case2();//所有IO设置为输入,上拉
  474. //使用外部中断唤醒
  475. //GPIO_EXIT_Init_case1(GPIOA, PIN2);//检测高电平
  476. //Interrupt_Level(EXIT2_int_ID, INT_LEVEL0);//CLIC设置中断抢占级别
  477. //Interrupt_Enable(EXIT2_int_ID);//CLIC使能EXIT中断
  478. //SYS_Interrupt_Enable();//CLIC开总中断
  479. //配置不同低功耗模式
  480. //System_Halt();//待机模式 halt1
  481. //System_Sleep();//睡眠模式 halt2
  482. //System_Powerdown();//掉电模式 powerdown1
  483. //System_DeepPwd();//掉电模式 powerdown2
  484. ///----Chapter 5 GPIO Test Init ---------------------------------------------------------------------------------
  485. GPIO_MODE_Init(GPIOA,PIN8,GPIO_MODE_OUTPUT); //GPIO 模式
  486. GPIO_MODE_Init(GPIOA,PIN10,GPIO_MODE_OUTPUT); //GPIO 模式
  487. GPIO_MODE_Init(GPIOA,PIN12,GPIO_MODE_OUTPUT); //GPIO 模式
  488. //GPIO_MODE_Init(GPIOA,PIN14,GPIO_MODE_OUTPUT); //GPIO 模式
  489. //GPIO_MODE_Init(GPIOA,PIN15,GPIO_MODE_OUTPUT); //GPIO 模式
  490. //GPIO_Write(GPIOA,PIN8,GPIO_SET); //GPIO 输出
  491. //GPIO_Write(GPIOA,PIN10,GPIO_SET); //GPIO 输出
  492. //GPIO_Write(GPIOA,PIN12,GPIO_SET); //GPIO 输出
  493. //GPIO_Write(GPIOA,PIN14,GPIO_RESET); //GPIO 输出
  494. //GPIO_Write(GPIOA,PIN15,GPIO_RESET); //GPIO 输出
  495. //GPIO_Toggle(GPIOA,PIN15); //GPIO 翻转
  496. //GPIO_MODE_Init(GPIOA,PIN15,GPIO_MODE_INTPUT); //GPIO 模式
  497. for(uint8_t i=0;i<10;i++)
  498. {
  499. GPIO_Toggle(GPIOA,PIN8); //GPIO 翻转
  500. Delay32M_ms(100);
  501. }
  502. ///---- Chapter 6 EXIT Test Init -------------------------------------------------------------------------------------
  503. //GPIO_EXIT_Init_case1(GPIOA, PIN2);//检测高电平
  504. //GPIO_EXIT_Init_case2(GPIOA, PIN2);//检测低电平
  505. //GPIO_EXIT_Init_case3(GPIOA, PIN2);//检测上升沿
  506. //GPIO_EXIT_Init_case4(GPIOA, PIN2);//检测下降沿
  507. //Interrupt_Level(EXIT2_int_ID, INT_LEVEL0);//CLIC设置中断抢占级别
  508. //Interrupt_Enable(EXIT2_int_ID);//CLIC使能EXIT中断
  509. //载波检测中断
  510. //CAW_Init();//载波检测
  511. //Interrupt_Enable(CAW_int_ID);//CLIC使能中断
  512. //SYS_Interrupt_Enable();//CLIC开总中断
  513. ///---- Chapter 7 RTC Test Init --------------------------------------------------------------------------------------
  514. //RTC_Init_case1();
  515. RTC_Init_case2();
  516. Interrupt_Level(MTIMER_int_ID, INT_LEVEL2 );//CLIC设置中断抢占级别
  517. Interrupt_Enable(MTIMER_int_ID);//CLIC使能中断
  518. SYS_Interrupt_Enable();//CLIC开总中断
  519. ///---- Chapter 8 IWDG Test Init -------------------------------------------------------------------------------------
  520. //IWDG_Init(9000); //配置看门狗计数值(时钟频率3K)
  521. //Delay32M_ms(1000);
  522. //IWDG_Start(); //启动看门狗
  523. //IWDG_Refresh(); //喂狗
  524. ///---- Chapter 9 Timer Test Init ------------------------------------------------------------------------------------
  525. //GPIO_MODE_Init(GPIOB,PIN11,GPIO_MODE_OUTPUT); //GPIO 模式
  526. //GPIO_MODE_Init(GPIOA,PIN9,GPIO_MODE_OUTPUT);
  527. //GPIO_MODE_Init(GPIOA,PIN11,GPIO_MODE_OUTPUT);
  528. //GPIO_MODE_Init(GPIOA,PIN13,GPIO_MODE_OUTPUT);
  529. //外设配置
  530. //Timer1_UpCounting_Mode_Init();//向上计数
  531. //Timer1_6StepPWM_Mode_Init();//6stepPWM输出
  532. //Timer2_UpCounting_Mode_Init();//向上计数
  533. //Timer2_DownCounting_Mode_Init();//向下计数
  534. //Timer2_ExternalClock_Mode_Init();//外部时钟
  535. //Timer2_InputCapture_Mode_Init();//输入捕获
  536. //Timer2_PWM_InputCapture_Mode_Init();//PWM输入捕获
  537. //Timer2_Input_XOR_Mode_Init();//输入异或
  538. //Timer2_PWM_Mode_Init();//PWM输出
  539. //Timer2_6StepPWM_Mode_Init();//6stepPWM输出
  540. //设置中断优先级
  541. //Interrupt_Level(TIMER1_updata_int_ID, INT_LEVEL1);//CLIC设置中断抢占级别
  542. //使能外设中断
  543. //Interrupt_Enable(TIMER1_break_int_ID);//CLIC使能中断
  544. //Interrupt_Enable(TIMER1_updata_int_ID);//CLIC使能中断
  545. //Interrupt_Enable(TIMER1_capture_compare_int_ID);//CLIC使能中断
  546. //Interrupt_Enable(TIMER1_trigger_comm_int_ID);//CLIC使能中断
  547. //Interrupt_Enable(TIMER2_break_int_ID);//CLIC使能中断
  548. //Interrupt_Enable(TIMER2_updata_int_ID);//CLIC使能中断
  549. //Interrupt_Enable(TIMER2_capture_compare_int_ID);//CLIC使能中断
  550. //Interrupt_Enable(TIMER2_trigger_comm_int_ID);//CLIC使能中断
  551. //使能系统总中断
  552. //SYS_Interrupt_Enable();//CLIC开总中断
  553. ///---- Chapter 10 WUP Test Init -------------------------------------------------------------------------------------
  554. //GPIO_MODE_Init(GPIOA,PIN2,GPIO_MODE_OUTPUT);
  555. //GPIO_MODE_Init(GPIOA,PIN3,GPIO_MODE_OUTPUT);
  556. //WUP_Init_case1(9000);//设置中断周期,使能WUP中断
  557. //Interrupt_Enable(WUP_int_ID);//CLIC使能中断
  558. //SYS_Interrupt_Enable();//CLIC开总中断
  559. //配置不同低功耗模式
  560. //System_Halt();//待机模式 halt1
  561. //System_Sleep();//睡眠模式 halt2
  562. //System_Powerdown();//掉电模式 powerdown1
  563. //System_DeepPwd();//掉电模式 powerdown2
  564. ///---- Chapter 11 ADC Test Init -------------------------------------------------------------------------------------
  565. uint32_t adc_result;
  566. uint32_t adc_pack[16];
  567. uint32_t adc_sum;
  568. uint32_t adc_count;
  569. uint32_t adc_avr;
  570. uint32_t voltage_avr;
  571. ADC_Init_case1();//内部基准,测PA4
  572. //ADC_Init_case2();//外部基准,测PA4
  573. ///---- Chapter 12 I2C Test Init -------------------------------------------------------------------------------------
  574. uint8_t i2c_data;
  575. I2C_Init_case1();//非中断模式
  576. //I2C_Init_case2();//ready中断模式
  577. //I2C_Init_case3();//error中断模式
  578. //I2C_Init_case4();//ready & error中断模式
  579. //Interrupt_Enable(I2C_ready_int_ID);//CLIC使能i2c_ready中断
  580. //Interrupt_Enable(I2C_error_int_ID);//CLIC使能i2c_error中断
  581. //SYS_Interrupt_Enable();//CLIC开总中断
  582. OLED_Init();
  583. ///---- Chapter 13 SPI1 Test Init ------------------------------------------------------------------------------------
  584. //uint8_t sTxpack[10] = {0,1,2,3,4,5,6,7,8,9};
  585. //uint8_t sRxpack[10] = {0,1,2,3,4,5,6,7,8,9};
  586. //uint8_t REG_Data;
  587. //SPI1 Init Test
  588. //SPI_Init_case1(SPI1);//非中断模式
  589. //SPI1_CSN_Init_case1();//CFG: CE-GPIO7,CSN-GPIO8
  590. //SPI_Init_case2(SPI1);//中断模式
  591. //Interrupt_Enable(SPI1_int_ID);//CLIC使能单个中断
  592. //SPI2 Init Test
  593. //SPI_Init_case1(SPI2);//非中断模式
  594. //SPI2_CSN_Init_case1();//CFG: CE-GPIO7,CSN-GPIO8
  595. //SPI_Init_case2(SPI2);//中断模式
  596. //Interrupt_Enable(SPI2_int_ID);//CLIC使能单个中断
  597. ///---- Chapter 15 UART Test Init -------------------------------------------------------------------------------
  598. //uint8_t upack1[20] = {0,1,2,3,4,5,6,7,8,9};
  599. //uint8_t upack2[20] = {0,1,2,3,4,5,6,7,8,9};
  600. //uint8_t upack3[20] = {0,1,2,3,4,5,6,7,8,9};
  601. //uint8_t upack4[20] = {10,1,2,3,4,5,6,7,8,9};
  602. //UART_Init_case1(UART2);//非中断模式
  603. //UART_Init_case1(UART3);//非中断模式
  604. //UART_Init_case1(UART4);//非中断模式
  605. UART_Init_IT_case1(UART1);//中断模式
  606. //UART_Init_IT_case1(UART4);//中断模式
  607. Interrupt_Enable(UART1_int_ID);//CLIC使能单个中断
  608. UART1->CTRL |= 0x00000001U;//清除中断标志位,防止开机先进一次中断
  609. //Interrupt_Enable(UART4_int_ID);//CLIC使能单个中断
  610. SYS_Interrupt_Enable();//CLIC开总中断
  611. //printf("uart init:rn");
  612. ///---- Chapter 16 LV Test Init --------------------------------------------------------------------------------------
  613. //LV_Init_case1(12);//设置低压报警阈值
  614. //LV_Interrupt_Enable();//使能低压报警中断
  615. //Interrupt_Enable(LV_int_ID);//CLIC使能单个中断
  616. //SYS_Interrupt_Enable();//CLIC开总中断
  617. ///---- Chapter 17 RANDGEN Test Init ---------------------------------------------------------------------------------
  618. //uint32_t rand_data;
  619. ///---- Chapter 18 compare Test Init ---------------------------------------------------------------------------------
  620. //COPM1_Init();//COPM1
  621. //Interrupt_Enable(COMP1_int_ID);//CLIC使能单个中断
  622. //COPM2_Init();//COPM2
  623. //Interrupt_Enable(COMP2_int_ID);//CLIC使能单个中断
  624. //COPM3_Init();//COPM3
  625. //Interrupt_Enable(COMP3_int_ID);//CLIC使能单个中断
  626. //SYS_Interrupt_Enable();//CLIC开总中断
  627. ///---- Chapter 22 flash Test Init ----------------------------------------------------------------------------------
  628. //NVR_RW_Test();//NVR read and write test
  629. //Flash_RW_Test();
  630. ///---- 系统总中断控制 -------------------------------------------------------------------------------------------------
  631. //SYS_Interrupt_Enable();//CLIC开总中断
  632. //SYS_Interrupt_Disable();//CLIC关总中断
  633. adc_pack[0]=read_csr(mcycle);
  634. adc_pack[1]=read_csr(mcycle);
  635. ee_printf("nHello CSM32RV20:n");
  636. ee_printf("mcycle:%d n",read_csr(mcycle));//比如mcycle这一CSR用于处理器运行的时钟周期计数
  637. ee_printf("read_csr(mcycle):%d n",adc_pack[1]-adc_pack[0]);//比如mcycle这一CSR用于处理器运行的时钟周期计数
  638. ee_printf("CMU->OSC_SR:%x n",CMU->OSC_SR );
  639. if(CMU->OSC_SR==210 ) ee_printf("CMU->OSC_SR:210,OSC 时钟已稳定,RCOSC 时钟已稳定,:OSC 在为 MCU 提供时钟;OSC 在为外设提供时钟; n" );
  640. //printf("Hello CSM32RV20:rn");
  641. ee_printf("请输入:on 或者off (开灯/关灯)rn");
  642. uint32_t rt_tick1 = rt_tick_get();
  643. uint32_t rt_tick2 = rt_tick_get();
  644. OLED_Clear();
  645. Delay32M_ms(1000);
  646. // OLED_Light();
  647. // OLED_DrawBMP(0,0,128,8,BAD_APPLE);
  648. OLED_ShowString(0,0,"CSM32 TEST",16);
  649. while(1)
  650. {
  651. mp_receive_data(ReceiveBuff, &rlen);
  652. if(uart_dev.frameok==1)//如果接收到数据
  653. {
  654. ee_printf("收到数据:");
  655. OLED_ShowString(0,2,"in:",16);
  656. Uart_Send(UART1,(uint8_t *)ReceiveBuff,rlen);
  657. OLED_ShowString(28,2,(uint8_t *)ReceiveBuff,16);
  658. ee_printf("rn");
  659. uint8_t aton= (uint8_t)ReceiveBuff[0];
  660. uint32_t data=0;
  661. switch (aton) {
  662. case 111://"o"
  663. if(1==rlen) break;
  664. if(ReceiveBuff[1]=='n')
  665. {
  666. GPIO_Write(GPIOA,PIN8,GPIO_RESET);
  667. ee_printf("灯开了!rn");
  668. }
  669. else if((ReceiveBuff[1]=='f')&&(ReceiveBuff[2]=='f'))
  670. {
  671. GPIO_Write(GPIOA,PIN8,GPIO_SET);
  672. ee_printf("关灯了!rn");
  673. }
  674. else
  675. {
  676. ee_printf("请输入:on 或者off (开灯/关灯)rn");
  677. }
  678. break;
  679. case 48://"0"
  680. ee_printf("nRTC_MTIME->mtimelo:%u n",_REG32(RTC_MTIME,0));
  681. ee_printf("nRTC_MTIME->mtimehi:%u n",_REG32(0x0200bff8UL,4));
  682. // uint64_t mtime1=RTC_MTIME->mtime;
  683. // ee_printf("nRTC_MTIME->mtime-all:%lu n",mtime1);
  684. break;
  685. default:
  686. break;
  687. }
  688. // if((ReceiveBuff[0]=='o')&&(ReceiveBuff[1]=='n'))
  689. // {
  690. // GPIO_Write(GPIOA,PIN8,GPIO_RESET);
  691. // ee_printf("灯开了!rn");
  692. // }
  693. // else if((ReceiveBuff[0]=='o')&&(ReceiveBuff[1]=='f')&&(ReceiveBuff[2]=='f'))
  694. // {
  695. // GPIO_Write(GPIOA,PIN8,GPIO_SET);
  696. // ee_printf("关灯了!rn");
  697. // }
  698. // else
  699. // {
  700. // ee_printf("请输入:on 或者off (开灯/关灯)rn");
  701. // }
  702. uart_dev.frameok=0;
  703. uart_dev.rxlen=0;
  704. }
  705. if( rt_tick_get()%1000==0) ee_printf("time is %u s n",rt_tick_get()/1000);
  706. if(!( rt_tick_get()- rt_tick1< 10000)){
  707. rt_tick1 = rt_tick_get() ;
  708. GPIO_Toggle(GPIOB,PIN8);
  709. GPIO_Toggle(GPIOA,PIN10); //GPIO 翻转
  710. // ee_printf("mcycle:%u n",read_csr(mcycle));
  711. ee_printf("rt_tick_get:%u n", rt_tick_get());
  712. ee_printf("RTC_MTIME->mtime:%lu ",RTC_MTIME->mtime);
  713. // ee_printf("type?RTC_MTIME->mtime:%lu n",type(RTC_MTIME->mtime));
  714. ee_printf("RTC_MTIME->mtime0-7B:");
  715. for (uint8_t i = 0; i < 8; i++)
  716. {
  717. ee_printf("%x ",_REG8(0x0200bff8UL,i));
  718. }
  719. ee_printf("nRTC_MTIME->mtime:%u n",_REG32(0x0200bff8UL,4));
  720. ee_printf("RTC_MTIMECMP->mtimecmp:%lu n",RTC_MTIMECMP->mtimecmp);
  721. // ee_printf("type?RTC_MTIME->mtime:%lu n",type(RTC_MTIMECMP->mtimecmp));
  722. ee_printf("->?RTC_MTIME->mtime:%p n",RTC_MTIMECMP->mtimecmp);
  723. ee_printf("RTC_MTIMECMP->mtimecmp0-7B:");
  724. for (uint8_t i = 0; i < 8; i++)
  725. {
  726. ee_printf("%x ",_REG8(0x02004000UL,i));
  727. }
  728. ee_printf(" n");
  729. }
  730. // Delay32M_ms(500);
  731. //Delay16M_ms(500);
  732. //Delay16M_us(500000);
  733. //GPIO_Toggle(GPIOA,PIN15);
  734. //printf("main:rn");
  735. ///---- Chapter 6 EXIT test ---------------------------------------------------------------------------------
  736. //delay16M_ms(500);
  737. //GPIO_Toggle(GPIOA,PIN15);
  738. ///---- Chapter 8 IWDG test ---------------------------------------------------------------------------------
  739. //IWDG_Refresh();
  740. //delay16M_ms(500);
  741. //GPIO_Toggle(GPIOA,PIN15);
  742. ///---- Chapter 9 Timer test --------------------------------------------------------------------------------
  743. //---- soft break --------------------------------------------------------------------------------------
  744. //delay16M_ms(100);
  745. //TIMER2->BDTR |= 1 <<15;//BDTR[15]-MOE-主输出使能:0-关闭,1-使能
  746. //delay16M_ms(100);
  747. //TIMER2->EGR |= 1 <<7;//EGR[7]-BG-产生刹车事件
  748. //---- soft COM ----------------------------------------------------------------------------------------
  749. //delay16M_ms(100);
  750. //TIMER2->EGR = 1 <<5;//EGR[5]-COMG-捕获/比较事件,产生控制更新
  751. //---- generate oxr ------------------------------------------------------------------------------------
  752. /*
  753. Delay16M_ms(10);//1
  754. GPIO_Write(GPIOA,PIN9,GPIO_SET);
  755. GPIO_Write(GPIOA,PIN11,GPIO_RESET);
  756. GPIO_Write(GPIOA,PIN13,GPIO_SET);
  757. Delay16M_ms(10);//2
  758. GPIO_Write(GPIOA,PIN9,GPIO_SET);
  759. GPIO_Write(GPIOA,PIN11,GPIO_RESET);
  760. GPIO_Write(GPIOA,PIN13,GPIO_RESET);
  761. Delay16M_ms(10);//3
  762. GPIO_Write(GPIOA,PIN9,GPIO_SET);
  763. GPIO_Write(GPIOA,PIN11,GPIO_SET);
  764. GPIO_Write(GPIOA,PIN13,GPIO_RESET);
  765. Delay16M_ms(10);//4
  766. GPIO_Write(GPIOA,PIN9,GPIO_RESET);
  767. GPIO_Write(GPIOA,PIN11,GPIO_SET);
  768. GPIO_Write(GPIOA,PIN13,GPIO_RESET);
  769. Delay16M_ms(10);//5
  770. GPIO_Write(GPIOA,PIN9,GPIO_RESET);
  771. GPIO_Write(GPIOA,PIN11,GPIO_SET);
  772. GPIO_Write(GPIOA,PIN13,GPIO_SET);
  773. Delay16M_ms(10);//6
  774. GPIO_Write(GPIOA,PIN9,GPIO_RESET);
  775. GPIO_Write(GPIOA,PIN11,GPIO_RESET);
  776. GPIO_Write(GPIOA,PIN13,GPIO_SET);
  777. */
  778. ///---- Chapter 11 ADC test ---------------------------------------------------------------------------------
  779. ///---- Chapter 12 I2C test ---------------------------------------------------------------------------------
  780. //I2C_Write(0x2d,0x55);//适用于非中断模式
  781. //i2c_data = I2C_Read(0x2d);//适用于非中断模式
  782. //printf("data:%xrn",i2c_data);
  783. //I2C_Write(0x2d,0xaa);//适用于非中断模式
  784. //i2c_data = I2C_Read(0x2d);//适用于非中断模式
  785. //printf("data:%xrn",i2c_data);
  786. //I2C_Write_IT(0x2d,0x55);//适用于中断模式
  787. ///---- Chapter 13 SPI test --------------------------------------------------------------------------------
  788. //SPI1 Test
  789. //SPI_Transceive(SPI1,sTxpack,sRxpack,10);//非中断模式
  790. //SPI1_RW_reg(WRITE_REG+0x05,0x53);//读写Si24R1寄存器
  791. //REG_Data = SPI1_RW_reg(READ_REG+0x05,0);//读写Si24R1寄存器
  792. //printf("rnREG5:%02x",REG_Data);
  793. //delay16M_ms(500);
  794. //SPI2 Test
  795. //SPI_Transceive(SPI2,sTxpack,sRxpack,10);//非中断模式
  796. //SPI2_RW_reg(WRITE_REG+0x05,0x53);//读写Si24R1寄存器
  797. //REG_Data = SPI2_RW_reg(READ_REG+0x05,0);//读写Si24R1寄存器
  798. //printf("rnREG5:%02x",REG_Data);
  799. //delay16M_ms(500);
  800. ///---- Chapter 15 UART Test ------------------------------------------------------------------------------------
  801. //---- 非中断模式数据回环测试 -------------------------------------------------------------------------------------
  802. //Uart_Reveive(UART1,upack1,10);//适用于非中断发送模式
  803. //Uart_Send(UART1,upack1,10);//适用于非中断发送模式
  804. //Uart_Reveive(UART2,upack2,10);//适用于非中断发送模式
  805. //Uart_Send(UART2,upack2,10);//适用于非中断发送模式
  806. //Uart_Reveive(UART3,upack3,10);//适用于非中断发送模式
  807. //Uart_Send(UART3,upack3,10);//适用于非中断发送模式
  808. //Uart_Reveive(UART4,upack4,10);//适用于非中断发送模式
  809. //Uart_Send(UART4,upack4,10);//适用于非中断发送模式
  810. //---- 中断模式数据回环测试 --------------------------------------------------------------------------------------
  811. //UART1_putbuf(UART1_getbuf());
  812. //---- printf测试 ----------------------------------------------------------------------------------------
  813. //printf("Hellow-01234568789abcdefghijklmnopqrstuvwxyzrn");
  814. ///---- Chapter 17 RANDGEN test -----------------------------------------------------------------------------
  815. //rand_data = RAND_Get();//生成随机数
  816. //printf("rand:0x%08x,%urn",rand_data,rand_data);
  817. //delay16M_ms(500);
  818. ///---- Chapter 18 COMPARE test -----------------------------------------------------------------------------
  819. //if(COMP1->irq&0x1)
  820. //{
  821. //GPIO_Toggle(GPIOA,PIN15);
  822. //COMP1->irq = 1;
  823. //}
  824. //delay16M_ms(10);
  825. }
  826. return 0;
  827. }
复制代码

pYYBAGIDYJeAXnguAAJm6KpW4M4352.png
poYBAGIDYVCABk08AABEk5Mxom8209.jpg

com:

Hello CSM32RV20:
mcycle:112549883
read_csr(mcycle):2
CMU->OSC_SR:d2
CMU->OSC_SR:210,OSC 时钟已稳定,RCOSC 时钟已稳定,:OSC 在为 MCU 提供时钟;OSC 在为外设提供时钟;
请输入:on ���者off (开灯/关灯)

收到数据:

rt_tick_get:11529
RTC_MTIME->mtime:36899472 RTC_MTIME->mtime0-7B:4a 4c 33 2 0 0 0 0
RTC_MTIME->mtime:0
RTC_MTIMECMP->mtimecmp:36934400
->?RTC_MTIME->mtime:0233b880
RTC_MTIMECMP->mtimecmp0-7B:0 3 34 2 0 0 0 0
val:95avr:14062100 13.9mV 2047.5mV

time:0 day 0 hour' 0:16
收到数据:0


RTC_MTIME->mtimelo:63461288

RTC_MTIME->mtimehi:0
rt_tick_get:21537
RTC_MTIME->mtime:68924127 RTC_MTIME->mtime0-7B:99 f5 1b 4 0 0 0 0
RTC_MTIME->mtime:0
RTC_MTIMECMP->mtimecmp:68960000
->?RTC_MTIME->mtime:041c6480
RTC_MTIMECMP->mtimecmp0-7B:0 a3 1c 4 0 0 0 0

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 南京中科微
    +关注

    关注

    0

    文章

    60

    浏览量

    742
  • CSM32RV20
    +关注

    关注

    0

    文章

    40

    浏览量

    215
收藏 人收藏

    评论

    相关推荐

    【敏矽ME32G070开发板免费体验】开箱+点灯+点亮OLED

    ME32G070 支持硬件 I2C,这里偷个懒,不想使用繁琐的跳线,直接在开发板上随意插入 OLED 显示屏的引脚,如下: 直接插上 OLED 显示屏即可 由于 PB6、PB4
    发表于 12-19 00:25

    【敏矽ME32G070开发板免费体验】\\+Lora通信终端产品开发项目

    需求评估产品性能。 一.开发板申请之路—听我娓娓道来 2024年11月19日早,电子发烧友论坛信公众号发文,标题为《新品体验!敏矽ME32G070开发板免费
    发表于 12-15 18:26

    瑞芯主板/开发板Linux系统播放音频方法,触觉智能RK3562开发板演示

    本文介绍瑞芯方案主板/开发板Linux系统播放音频的方法,触觉智能RK3562开发板演示,通用RK3566、RK3568、RK3588等
    的头像 发表于 12-13 11:40 198次阅读
    瑞芯<b class='flag-5'>微</b>主板/<b class='flag-5'>开发板</b>Linux系统播放音频方法,触觉智能RK3562<b class='flag-5'>开发板</b>演示

    追加名额丨米尔瑞芯RK3576开发板有奖试用

    米尔与瑞芯合作发布的新品基于瑞芯RK3576应用处理器的MYD-LR3576开发板免费试用活动加码啦~~米尔追加了2块价值849元的MY
    的头像 发表于 11-22 01:00 173次阅读
    追加名额丨米尔瑞芯<b class='flag-5'>微</b>RK3576<b class='flag-5'>开发板</b>有奖<b class='flag-5'>试用</b>

    【RA8D1试用活动】RA8D1B-CPKCOR开发板移植linux

    【RA8D1试用活动】RA8D1B-CPKCOR开发板移植linux
    的头像 发表于 11-16 01:02 220次阅读
    【RA8D1<b class='flag-5'>试用</b>活动】RA8D1B-CPKCOR<b class='flag-5'>开发板</b>移植linux

    常用在工业控制系统上的MCU芯片资料:CSM32RV20

    CSM32RV20是一款基于RISC-V核的低功耗MCU芯片。 内置RISC-V RV32IMAC内核(2.6CoreMark/MHz); 蕞高32MHz工作频率; 内置4kB的SRAM; 内置8B
    的头像 发表于 11-15 17:19 203次阅读
    常用在工业控制系统上的MCU芯片资料:<b class='flag-5'>CSM32RV20</b>

    有奖丨米尔 瑞芯RK3576开发板免费试用

    米尔与瑞芯合作发布的新品基于瑞芯RK3576应用处理器的MYD-LR3576开发板免费试用活动来啦~~米尔提供了7块价值849元的MYD-LR3576
    的头像 发表于 11-12 01:00 303次阅读
    有奖丨米尔 瑞芯<b class='flag-5'>微</b>RK3576<b class='flag-5'>开发板</b>免费<b class='flag-5'>试用</b>

    有奖试用!!RA-Eco-RA4E2-64PIN-V1.0开发板试用活动开始报名

    有奖试用!!RA-Eco-RA4E2-64PIN-V1.0开发板试用活动开始报名
    的头像 发表于 11-09 01:02 241次阅读
    有奖<b class='flag-5'>试用</b>!!RA-Eco-RA4E<b class='flag-5'>2</b>-64PIN-V1.0<b class='flag-5'>开发板</b><b class='flag-5'>试用</b>活动开始报名

    【作品合集】龙芯2K0300蜂鸟开发板试用精选

    】+4.libmodbus移植【龙芯2K0300蜂鸟试用】+3.移植lua到loongarch【龙芯2K0300蜂鸟
    发表于 09-10 18:17

    【龙芯2K0300蜂鸟试用】开箱体验

    本帖最后由 ele2022 于 2024-8-13 19:54 编辑 首先感谢电子发烧友和龙芯中科提供的试用机会。 今天开箱体验龙芯中科的一款2K0300蜂鸟
    发表于 08-12 19:59

    点击参与米尔NXP i.MX 93开发板有奖试用

    米尔与NXP合作发布的新品基于NXPi.MX93应用处理器的MYD-LMX9X开发板免费试用活动来啦~~米尔提供了3块价值678元的MYD-LMX9X开发板发起试用活动您不仅可以免费体
    的头像 发表于 06-13 08:02 527次阅读
    点击参与米尔NXP i.MX 93<b class='flag-5'>开发板</b>有奖<b class='flag-5'>试用</b>

    免费!NXP i.MX 93开发板有奖试用

    米尔与NXP合作发布的新品基于NXPi.MX93应用处理器的MYD-LMX9X开发板免费试用活动来啦~~米尔提供了2块价值678
    的头像 发表于 05-23 08:01 725次阅读
    免费!NXP i.MX 93<b class='flag-5'>开发板</b>有奖<b class='flag-5'>试用</b>

    201型RV1126开发板开箱视频

    电路开发板
    易百纳
    发布于 :2024年04月12日 11:09:40

    香橙派发布首款RISC-V开发板OrangePi RV

    2024年3月,香橙派在全球开发者会议上发布了其首款基于RISC-V开发的OrangePi RV主板。这款开发板拥有四核RISC-V U74与S7协处理器,配备
    的头像 发表于 04-01 14:47 1050次阅读

    rv1126和rk3568对比

    视频编解码。而RK3568开发板创龙科技旗下工业开发板,基于瑞芯RK3568J/RK3568B2处理器设计,四核ARM Cortex-A55,每核主频高达1.8GHz/2.0GHz。
    的头像 发表于 01-23 18:05 1.1w次阅读
    <b class='flag-5'>rv</b>1126和rk3568对比