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

描述

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

南京中科微
南京中科微

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:95  avr: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     

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分