本文来源电子发烧友社区,作者:卢松涛, 帖子地址: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开总中断
复制代码
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
在"【南京中科微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开总中断
- #include "headfile.h"
- #ifndef __OLEDFONT_H
- #define __OLEDFONT_H
- //常用ASCII表
- //偏移量32
- //ASCII字符集
- //偏移量32
- //大小:12*6
- /************************************6*8的点阵************************************/
- const unsigned char F6x8[][6] =
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
- 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
- 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
- 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
- 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
- 0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
- 0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
- 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
- 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
- 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
- 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
- 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
- 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
- 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
- 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
- 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
- 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
- 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
- 0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
- 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
- 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
- 0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
- 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
- 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
- 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
- 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
- 0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
- 0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
- 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
- 0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
- 0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
- 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
- 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
- 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
- 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
- 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
- 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
- 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
- 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
- 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
- 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
- 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
- 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
- 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
- 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
- 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
- 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
- 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
- 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
- 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
- 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
- 0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
- 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
- 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
- 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
- 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
- 0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
- 0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
- 0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
- 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
- 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
- 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
- 0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
- 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
- 0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
- 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
- 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
- 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
- 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
- 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
- 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
- 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
- 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
- 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
- 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
- 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
- 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
- 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
- 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
- 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
- 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
- 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
- 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
- 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
- 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
- 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
- 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
- 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
- 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
- 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
- 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
- };
- /****************************************8*16的点阵************************************/
- const unsigned char F8X16[]=
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//0
- 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
- 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
- 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
- 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
- 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
- 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
- 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
- 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
- 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
- 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
- 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
- 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
- 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
- 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
- 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
- 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
- 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
- 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
- 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
- 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
- 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
- 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
- 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
- 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
- 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
- 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
- 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
- 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
- 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
- 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
- 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
- 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
- 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
- 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
- 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
- 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
- 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
- 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
- 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
- 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
- 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
- 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
- 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
- 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
- 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
- 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
- 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
- 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// 60
- 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
- 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
- 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
- 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
- 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
- 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
- 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
- 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
- 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
- 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
- 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
- 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
- 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
- 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
- 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
- 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
- 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
- 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
- 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
- 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
- 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
- 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
- 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
- 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
- };
- /***********************************************
- PCtoLCD2002设置
- 阴码,逆向,C51格式,十六进制数据,列行式,输出三个全选中
- 每行显示点阵9999,索引9999
- 格式: 段前缀 【无】;
- 段后缀 【无】;
- 注释前缀(右边空格去掉) 【/ *"】;
- 注释后缀 【",】;
- 数据后缀 【,】;
- 行前缀 【{】;
- 行后缀 【},】
- **********************************************/
- /***********************************
- 16x16汉字
- 取字软件:PCtoLCD2002
- 使用方法见文档
- ***********************************/
- const unsigned char Chinese_Word_16[][32]= {
- {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*/
- {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*/
- {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*/
- {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*/
- };
- #endif
- void mp_receive_data(uint8_t *buf, uint16_t *len)
- {
- uint8_t rxlen = UART1_RX_CNT;
- uint16_t i = 0;
- *len = 0; //默认为0
- Delay32M_ms(10); //等待40ms,连续超过10ms没有接收到一个数据,则认为接收结束
- if (rxlen == UART1_RX_CNT && rxlen) //接收到了数据,且接收完成了
- {
- for (i = 0; i < rxlen; i++)
- {
- buf[i] = uart_dev.rxbuf[i];
- }
- *len = UART1_RX_CNT; //记录本次数据长度
- UART1_RX_CNT = 0; //清零
- uart_dev.frameok=1; //标记完成一帧数据接收
- // getData=0;//数据接收完成,标志位清零
- }
- }
- #define Max_Column 128
- void OLED_Write_IIC_Command(uint8_t IIC_Command)
- {
- I2C_Write(0x00,IIC_Command);
- }
- void OLED_Write_IIC_Data(uint8_t IIC_Data)
- {
- I2C_Write(0x40,IIC_Data);
- }
- /**
- * @brief :OLED_Clear
- * [url=home.php?mod=space&uid=1902110]@NOTE[/url] : --清屏函数
- --清完屏,整个屏幕是黑色的!和没点亮一样
- * @param : >>
- >>
- * @return :void
- *
- * @date :2021/01/29
- * [url=home.php?mod=space&uid=44345]@design[/url] :
- **/
- void OLED_Clear(void)
- {
- uint8_t i,n;
- for(i=0; i<8; i++)
- {
- OLED_Write_IIC_Command (0xb0+i); //设置页地址(0~7)
- OLED_Write_IIC_Command (0x00); //设置显示位置—列低地址
- OLED_Write_IIC_Command (0x10); //设置显示位置—列高地址
- for(n=0; n<128; n++)
- {
- OLED_Write_IIC_Data(0x00);
- }
- }
- //更新显示
- }
- /**
- * @brief :OLED_Set_Pos
- * @note : --坐标设置
- * @param : >>
- >>
- * @return :void
- *
- * @date :2021/01/29
- * @design :
- **/
- void OLED_Set_Pos(uint8_t x, uint8_t y)
- { OLED_Write_IIC_Command(0xb0+y);
- OLED_Write_IIC_Command(((x&0xf0)>>4)|0x10);
- OLED_Write_IIC_Command((x&0x0f));
- }
- /**
- * @brief :OLED_ShowChar
- * @note : --在指定位置显示一个字符,包括部分字符
- --例如:OLED_ShowChar(20,6,'A',16);
- * @param : >>
- >>x:0~127
- >>y:0~6
- >>mode:0,反白显示;1,正常显示
- >>size:选择字体 8/16
- * @return :void
- *
- * @date :2021/01/29
- * @design :
- **/
- void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size)
- {
- uint8_t c=0,i=0;
- c=chr-' ';//得到偏移后的值
- if(x>Max_Column-1) {
- x=0;
- y=y+2;
- }
- if(Char_Size ==16)
- {
- OLED_Set_Pos(x,y);
- for(i=0; i<8; i++)
- OLED_Write_IIC_Data(F8X16[c*16+i]);
- OLED_Set_Pos(x,y+1);
- for(i=0; i<8; i++)
- OLED_Write_IIC_Data(F8X16[c*16+i+8]);
- }
- else
- {
- OLED_Set_Pos(x,y);
- for(i=0; i<6; i++)
- OLED_Write_IIC_Data(F6x8[c][i]);
- }
- }
- /**
- * @brief :OLED_ShowString
- * @note : --显示一个字符号串
- --例如:
- u8 SET[2][3] = {{"ON "},{"OFF"}};
- OLED_ShowString(0,0,SET[0],8);
- * @param : >>
- >>size:选择字体 8/16
- * @return :void
- *
- * @date :2021/01/29
- * @design :
- **/
- void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
- {
- while (*chr!='')
- { OLED_ShowChar(x,y,*chr,Char_Size);
- x+=8;
- if(x>120) {
- x=0;
- y+=2;
- }
- chr++;
- }
- }
- /**********************************************
- //m^n函数
- **********************************************/
- uint32_t oled_pow(uint8_t m,uint8_t n)
- {
- uint32_t result=1;
- while(n--)result*=m;
- return result;
- }
- /**
- * @brief :OLED_ShowNumber
- * @note : --显示数字
- --例如:OLED_ShowNumber(0,0,45125215,10);
- * @param : >>x,y :起点坐标
- >>len :数字的位数
- >>size:字体大小默认16
- >>num:数值(0~4294967295);
- * @return :void
- *
- * @date :2021/01/29
- * @design :
- **/
- void OLED_ShowNumber(uint8_t x,uint8_t y,uint32_t num,uint8_t len)
- {
- uint8_t size2 = 16;
- uint8_t t,temp;
- uint8_t enshow=0;
- for(t=0; t;>
- {
- temp=(num/oled_pow(10,len-t-1))%10;
- if(enshow==0&&t<(len-1))
- {
- if(temp==0)
- {
- OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
- continue;
- } else enshow=1;
- }
- OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
- }
- }
- //初始化SSD1306
- void OLED_Init(void)
- {
- // OLED_GPIO_Init();
- Delay32M_ms(1500);
- // OLED_WR_Byte(0xAE,OLED_CMD);//--display off
- // OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
- // OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
- // OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
- // OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
- // OLED_WR_Byte(0x81,OLED_CMD); // contract control
- // OLED_WR_Byte(0xFF,OLED_CMD);//--128
- // OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
- // OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
- // OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
- // OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
- // OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
- // OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
- // OLED_WR_Byte(0x00,OLED_CMD);//
- // OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
- // OLED_WR_Byte(0x80,OLED_CMD);//
- // OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
- // OLED_WR_Byte(0x05,OLED_CMD);//
- // OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
- // OLED_WR_Byte(0xF1,OLED_CMD);//
- // OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
- // OLED_WR_Byte(0x12,OLED_CMD);//
- // OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
- // OLED_WR_Byte(0x30,OLED_CMD);//
- // OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
- // OLED_WR_Byte(0x14,OLED_CMD);//
- // OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
- OLED_Write_IIC_Command(0xAE); //display off
- OLED_Write_IIC_Command(0x20); //Set Memory Addressing Mode
- OLED_Write_IIC_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
- OLED_Write_IIC_Command(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
- OLED_Write_IIC_Command(0xc8); //Set COM Output Scan Direction
- OLED_Write_IIC_Command(0x00); //---set low column address
- OLED_Write_IIC_Command(0x10); //---set high column address
- OLED_Write_IIC_Command(0x40); //--set start line address
- OLED_Write_IIC_Command(0x81); //--set contrast control register
- OLED_Write_IIC_Command(0xff); //亮度调节 0x00~0xff
- OLED_Write_IIC_Command(0xa1); //--set segment re-map 0 to 127
- OLED_Write_IIC_Command(0xa6); //--set normal display
- OLED_Write_IIC_Command(0xa8); //--set multiplex ratio(1 to 64)
- OLED_Write_IIC_Command(0x3F); //
- OLED_Write_IIC_Command(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
- OLED_Write_IIC_Command(0xd3); //-set display offset
- OLED_Write_IIC_Command(0x00); //-not offset
- OLED_Write_IIC_Command(0xd5); //--set display clock divide ratio/oscillator frequency
- OLED_Write_IIC_Command(0xf0); //--set divide ratio
- OLED_Write_IIC_Command(0xd9); //--set pre-charge period
- OLED_Write_IIC_Command(0x22); //
- OLED_Write_IIC_Command(0xda); //--set com pins hardware configuration
- OLED_Write_IIC_Command(0x12);
- OLED_Write_IIC_Command(0xdb); //--set vcomh
- OLED_Write_IIC_Command(0x20); //0x20,0.77xVcc
- OLED_Write_IIC_Command(0x8d); //--set DC-DC enable
- OLED_Write_IIC_Command(0x14); //
- OLED_Write_IIC_Command(0xaf); //--turn on oled panel
- }
- uint8_t ReceiveBuff[RECV_LEN];
- int main(void)
- {
- uint16_t rlen=0;
- uart_dev.rxlen=0;
- ///----System Init ---------------------------------------------------------------------------------------------
- CLIC_Init();//系统中断配置
- System_Clock_Init();//系统时钟初始化
- ///----Chapter 3 LowPower Test Init ---------------------------------------------------------------------------------
- //低功耗测功耗需要IO不能悬空
- //Delay32M_ms(5000);
- //LowPower_Config_case1();//所有IO设置为输入,下拉
- //LowPower_Config_case2();//所有IO设置为输入,上拉
- //使用外部中断唤醒
- //GPIO_EXIT_Init_case1(GPIOA, PIN2);//检测高电平
- //Interrupt_Level(EXIT2_int_ID, INT_LEVEL0);//CLIC设置中断抢占级别
- //Interrupt_Enable(EXIT2_int_ID);//CLIC使能EXIT中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- //配置不同低功耗模式
- //System_Halt();//待机模式 halt1
- //System_Sleep();//睡眠模式 halt2
- //System_Powerdown();//掉电模式 powerdown1
- //System_DeepPwd();//掉电模式 powerdown2
- ///----Chapter 5 GPIO Test Init ---------------------------------------------------------------------------------
- GPIO_MODE_Init(GPIOA,PIN8,GPIO_MODE_OUTPUT); //GPIO 模式
- GPIO_MODE_Init(GPIOA,PIN10,GPIO_MODE_OUTPUT); //GPIO 模式
- GPIO_MODE_Init(GPIOA,PIN12,GPIO_MODE_OUTPUT); //GPIO 模式
- //GPIO_MODE_Init(GPIOA,PIN14,GPIO_MODE_OUTPUT); //GPIO 模式
- //GPIO_MODE_Init(GPIOA,PIN15,GPIO_MODE_OUTPUT); //GPIO 模式
- //GPIO_Write(GPIOA,PIN8,GPIO_SET); //GPIO 输出
- //GPIO_Write(GPIOA,PIN10,GPIO_SET); //GPIO 输出
- //GPIO_Write(GPIOA,PIN12,GPIO_SET); //GPIO 输出
- //GPIO_Write(GPIOA,PIN14,GPIO_RESET); //GPIO 输出
- //GPIO_Write(GPIOA,PIN15,GPIO_RESET); //GPIO 输出
- //GPIO_Toggle(GPIOA,PIN15); //GPIO 翻转
- //GPIO_MODE_Init(GPIOA,PIN15,GPIO_MODE_INTPUT); //GPIO 模式
- for(uint8_t i=0;i<10;i++)
- {
- GPIO_Toggle(GPIOA,PIN8); //GPIO 翻转
- Delay32M_ms(100);
- }
- ///---- Chapter 6 EXIT Test Init -------------------------------------------------------------------------------------
- //GPIO_EXIT_Init_case1(GPIOA, PIN2);//检测高电平
- //GPIO_EXIT_Init_case2(GPIOA, PIN2);//检测低电平
- //GPIO_EXIT_Init_case3(GPIOA, PIN2);//检测上升沿
- //GPIO_EXIT_Init_case4(GPIOA, PIN2);//检测下降沿
- //Interrupt_Level(EXIT2_int_ID, INT_LEVEL0);//CLIC设置中断抢占级别
- //Interrupt_Enable(EXIT2_int_ID);//CLIC使能EXIT中断
- //载波检测中断
- //CAW_Init();//载波检测
- //Interrupt_Enable(CAW_int_ID);//CLIC使能中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- ///---- 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开总中断
- ///---- Chapter 8 IWDG Test Init -------------------------------------------------------------------------------------
- //IWDG_Init(9000); //配置看门狗计数值(时钟频率3K)
- //Delay32M_ms(1000);
- //IWDG_Start(); //启动看门狗
- //IWDG_Refresh(); //喂狗
- ///---- Chapter 9 Timer Test Init ------------------------------------------------------------------------------------
- //GPIO_MODE_Init(GPIOB,PIN11,GPIO_MODE_OUTPUT); //GPIO 模式
- //GPIO_MODE_Init(GPIOA,PIN9,GPIO_MODE_OUTPUT);
- //GPIO_MODE_Init(GPIOA,PIN11,GPIO_MODE_OUTPUT);
- //GPIO_MODE_Init(GPIOA,PIN13,GPIO_MODE_OUTPUT);
- //外设配置
- //Timer1_UpCounting_Mode_Init();//向上计数
- //Timer1_6StepPWM_Mode_Init();//6stepPWM输出
- //Timer2_UpCounting_Mode_Init();//向上计数
- //Timer2_DownCounting_Mode_Init();//向下计数
- //Timer2_ExternalClock_Mode_Init();//外部时钟
- //Timer2_InputCapture_Mode_Init();//输入捕获
- //Timer2_PWM_InputCapture_Mode_Init();//PWM输入捕获
- //Timer2_Input_XOR_Mode_Init();//输入异或
- //Timer2_PWM_Mode_Init();//PWM输出
- //Timer2_6StepPWM_Mode_Init();//6stepPWM输出
- //设置中断优先级
- //Interrupt_Level(TIMER1_updata_int_ID, INT_LEVEL1);//CLIC设置中断抢占级别
- //使能外设中断
- //Interrupt_Enable(TIMER1_break_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER1_updata_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER1_capture_compare_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER1_trigger_comm_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER2_break_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER2_updata_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER2_capture_compare_int_ID);//CLIC使能中断
- //Interrupt_Enable(TIMER2_trigger_comm_int_ID);//CLIC使能中断
- //使能系统总中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- ///---- Chapter 10 WUP Test Init -------------------------------------------------------------------------------------
- //GPIO_MODE_Init(GPIOA,PIN2,GPIO_MODE_OUTPUT);
- //GPIO_MODE_Init(GPIOA,PIN3,GPIO_MODE_OUTPUT);
- //WUP_Init_case1(9000);//设置中断周期,使能WUP中断
- //Interrupt_Enable(WUP_int_ID);//CLIC使能中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- //配置不同低功耗模式
- //System_Halt();//待机模式 halt1
- //System_Sleep();//睡眠模式 halt2
- //System_Powerdown();//掉电模式 powerdown1
- //System_DeepPwd();//掉电模式 powerdown2
- ///---- Chapter 11 ADC Test Init -------------------------------------------------------------------------------------
- uint32_t adc_result;
- uint32_t adc_pack[16];
- uint32_t adc_sum;
- uint32_t adc_count;
- uint32_t adc_avr;
- uint32_t voltage_avr;
- ADC_Init_case1();//内部基准,测PA4
- //ADC_Init_case2();//外部基准,测PA4
- ///---- Chapter 12 I2C Test Init -------------------------------------------------------------------------------------
- uint8_t i2c_data;
- I2C_Init_case1();//非中断模式
- //I2C_Init_case2();//ready中断模式
- //I2C_Init_case3();//error中断模式
- //I2C_Init_case4();//ready & error中断模式
- //Interrupt_Enable(I2C_ready_int_ID);//CLIC使能i2c_ready中断
- //Interrupt_Enable(I2C_error_int_ID);//CLIC使能i2c_error中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- OLED_Init();
- ///---- Chapter 13 SPI1 Test Init ------------------------------------------------------------------------------------
- //uint8_t sTxpack[10] = {0,1,2,3,4,5,6,7,8,9};
- //uint8_t sRxpack[10] = {0,1,2,3,4,5,6,7,8,9};
- //uint8_t REG_Data;
- //SPI1 Init Test
- //SPI_Init_case1(SPI1);//非中断模式
- //SPI1_CSN_Init_case1();//CFG: CE-GPIO7,CSN-GPIO8
- //SPI_Init_case2(SPI1);//中断模式
- //Interrupt_Enable(SPI1_int_ID);//CLIC使能单个中断
- //SPI2 Init Test
- //SPI_Init_case1(SPI2);//非中断模式
- //SPI2_CSN_Init_case1();//CFG: CE-GPIO7,CSN-GPIO8
- //SPI_Init_case2(SPI2);//中断模式
- //Interrupt_Enable(SPI2_int_ID);//CLIC使能单个中断
- ///---- Chapter 15 UART Test Init -------------------------------------------------------------------------------
- //uint8_t upack1[20] = {0,1,2,3,4,5,6,7,8,9};
- //uint8_t upack2[20] = {0,1,2,3,4,5,6,7,8,9};
- //uint8_t upack3[20] = {0,1,2,3,4,5,6,7,8,9};
- //uint8_t upack4[20] = {10,1,2,3,4,5,6,7,8,9};
- //UART_Init_case1(UART2);//非中断模式
- //UART_Init_case1(UART3);//非中断模式
- //UART_Init_case1(UART4);//非中断模式
- UART_Init_IT_case1(UART1);//中断模式
- //UART_Init_IT_case1(UART4);//中断模式
- Interrupt_Enable(UART1_int_ID);//CLIC使能单个中断
- UART1->CTRL |= 0x00000001U;//清除中断标志位,防止开机先进一次中断
- //Interrupt_Enable(UART4_int_ID);//CLIC使能单个中断
- SYS_Interrupt_Enable();//CLIC开总中断
- //printf("uart init:rn");
- ///---- Chapter 16 LV Test Init --------------------------------------------------------------------------------------
- //LV_Init_case1(12);//设置低压报警阈值
- //LV_Interrupt_Enable();//使能低压报警中断
- //Interrupt_Enable(LV_int_ID);//CLIC使能单个中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- ///---- Chapter 17 RANDGEN Test Init ---------------------------------------------------------------------------------
- //uint32_t rand_data;
- ///---- Chapter 18 compare Test Init ---------------------------------------------------------------------------------
- //COPM1_Init();//COPM1
- //Interrupt_Enable(COMP1_int_ID);//CLIC使能单个中断
- //COPM2_Init();//COPM2
- //Interrupt_Enable(COMP2_int_ID);//CLIC使能单个中断
- //COPM3_Init();//COPM3
- //Interrupt_Enable(COMP3_int_ID);//CLIC使能单个中断
- //SYS_Interrupt_Enable();//CLIC开总中断
- ///---- Chapter 22 flash Test Init ----------------------------------------------------------------------------------
- //NVR_RW_Test();//NVR read and write test
- //Flash_RW_Test();
- ///---- 系统总中断控制 -------------------------------------------------------------------------------------------------
- //SYS_Interrupt_Enable();//CLIC开总中断
- //SYS_Interrupt_Disable();//CLIC关总中断
- adc_pack[0]=read_csr(mcycle);
- adc_pack[1]=read_csr(mcycle);
- ee_printf("nHello CSM32RV20:n");
- ee_printf("mcycle:%d n",read_csr(mcycle));//比如mcycle这一CSR用于处理器运行的时钟周期计数
- ee_printf("read_csr(mcycle):%d n",adc_pack[1]-adc_pack[0]);//比如mcycle这一CSR用于处理器运行的时钟周期计数
- ee_printf("CMU->OSC_SR:%x n",CMU->OSC_SR );
- if(CMU->OSC_SR==210 ) ee_printf("CMU->OSC_SR:210,OSC 时钟已稳定,RCOSC 时钟已稳定,:OSC 在为 MCU 提供时钟;OSC 在为外设提供时钟; n" );
- //printf("Hello CSM32RV20:rn");
- ee_printf("请输入:on 或者off (开灯/关灯)rn");
- uint32_t rt_tick1 = rt_tick_get();
- uint32_t rt_tick2 = rt_tick_get();
- OLED_Clear();
- Delay32M_ms(1000);
- // OLED_Light();
- // OLED_DrawBMP(0,0,128,8,BAD_APPLE);
- OLED_ShowString(0,0,"CSM32 TEST",16);
- while(1)
- {
- mp_receive_data(ReceiveBuff, &rlen);
- if(uart_dev.frameok==1)//如果接收到数据
- {
- ee_printf("收到数据:");
- OLED_ShowString(0,2,"in:",16);
- Uart_Send(UART1,(uint8_t *)ReceiveBuff,rlen);
- OLED_ShowString(28,2,(uint8_t *)ReceiveBuff,16);
- ee_printf("rn");
- uint8_t aton= (uint8_t)ReceiveBuff[0];
- uint32_t data=0;
- switch (aton) {
- case 111://"o"
- if(1==rlen) break;
- if(ReceiveBuff[1]=='n')
- {
- GPIO_Write(GPIOA,PIN8,GPIO_RESET);
- ee_printf("灯开了!rn");
- }
- else if((ReceiveBuff[1]=='f')&&(ReceiveBuff[2]=='f'))
- {
- GPIO_Write(GPIOA,PIN8,GPIO_SET);
- ee_printf("关灯了!rn");
- }
- else
- {
- ee_printf("请输入:on 或者off (开灯/关灯)rn");
- }
- break;
- case 48://"0"
- ee_printf("nRTC_MTIME->mtimelo:%u n",_REG32(RTC_MTIME,0));
- ee_printf("nRTC_MTIME->mtimehi:%u n",_REG32(0x0200bff8UL,4));
- // uint64_t mtime1=RTC_MTIME->mtime;
- // ee_printf("nRTC_MTIME->mtime-all:%lu n",mtime1);
- break;
- default:
- break;
- }
- // if((ReceiveBuff[0]=='o')&&(ReceiveBuff[1]=='n'))
- // {
- // GPIO_Write(GPIOA,PIN8,GPIO_RESET);
- // ee_printf("灯开了!rn");
- // }
- // else if((ReceiveBuff[0]=='o')&&(ReceiveBuff[1]=='f')&&(ReceiveBuff[2]=='f'))
- // {
- // GPIO_Write(GPIOA,PIN8,GPIO_SET);
- // ee_printf("关灯了!rn");
- // }
- // else
- // {
- // ee_printf("请输入:on 或者off (开灯/关灯)rn");
- // }
- uart_dev.frameok=0;
- uart_dev.rxlen=0;
- }
- if( rt_tick_get()%1000==0) ee_printf("time is %u s n",rt_tick_get()/1000);
- if(!( rt_tick_get()- rt_tick1< 10000)){
- rt_tick1 = rt_tick_get() ;
- GPIO_Toggle(GPIOB,PIN8);
- GPIO_Toggle(GPIOA,PIN10); //GPIO 翻转
- // ee_printf("mcycle:%u n",read_csr(mcycle));
- ee_printf("rt_tick_get:%u n", rt_tick_get());
- ee_printf("RTC_MTIME->mtime:%lu ",RTC_MTIME->mtime);
- // ee_printf("type?RTC_MTIME->mtime:%lu n",type(RTC_MTIME->mtime));
- ee_printf("RTC_MTIME->mtime0-7B:");
- for (uint8_t i = 0; i < 8; i++)
- {
- ee_printf("%x ",_REG8(0x0200bff8UL,i));
- }
- ee_printf("nRTC_MTIME->mtime:%u n",_REG32(0x0200bff8UL,4));
- ee_printf("RTC_MTIMECMP->mtimecmp:%lu n",RTC_MTIMECMP->mtimecmp);
- // ee_printf("type?RTC_MTIME->mtime:%lu n",type(RTC_MTIMECMP->mtimecmp));
- ee_printf("->?RTC_MTIME->mtime:%p n",RTC_MTIMECMP->mtimecmp);
- ee_printf("RTC_MTIMECMP->mtimecmp0-7B:");
- for (uint8_t i = 0; i < 8; i++)
- {
- ee_printf("%x ",_REG8(0x02004000UL,i));
- }
- ee_printf(" n");
- }
- // Delay32M_ms(500);
- //Delay16M_ms(500);
- //Delay16M_us(500000);
- //GPIO_Toggle(GPIOA,PIN15);
- //printf("main:rn");
- ///---- Chapter 6 EXIT test ---------------------------------------------------------------------------------
- //delay16M_ms(500);
- //GPIO_Toggle(GPIOA,PIN15);
- ///---- Chapter 8 IWDG test ---------------------------------------------------------------------------------
- //IWDG_Refresh();
- //delay16M_ms(500);
- //GPIO_Toggle(GPIOA,PIN15);
- ///---- Chapter 9 Timer test --------------------------------------------------------------------------------
- //---- soft break --------------------------------------------------------------------------------------
- //delay16M_ms(100);
- //TIMER2->BDTR |= 1 <<15;//BDTR[15]-MOE-主输出使能:0-关闭,1-使能
- //delay16M_ms(100);
- //TIMER2->EGR |= 1 <<7;//EGR[7]-BG-产生刹车事件
- //---- soft COM ----------------------------------------------------------------------------------------
- //delay16M_ms(100);
- //TIMER2->EGR = 1 <<5;//EGR[5]-COMG-捕获/比较事件,产生控制更新
- //---- generate oxr ------------------------------------------------------------------------------------
- /*
- Delay16M_ms(10);//1
- GPIO_Write(GPIOA,PIN9,GPIO_SET);
- GPIO_Write(GPIOA,PIN11,GPIO_RESET);
- GPIO_Write(GPIOA,PIN13,GPIO_SET);
- Delay16M_ms(10);//2
- GPIO_Write(GPIOA,PIN9,GPIO_SET);
- GPIO_Write(GPIOA,PIN11,GPIO_RESET);
- GPIO_Write(GPIOA,PIN13,GPIO_RESET);
- Delay16M_ms(10);//3
- GPIO_Write(GPIOA,PIN9,GPIO_SET);
- GPIO_Write(GPIOA,PIN11,GPIO_SET);
- GPIO_Write(GPIOA,PIN13,GPIO_RESET);
- Delay16M_ms(10);//4
- GPIO_Write(GPIOA,PIN9,GPIO_RESET);
- GPIO_Write(GPIOA,PIN11,GPIO_SET);
- GPIO_Write(GPIOA,PIN13,GPIO_RESET);
- Delay16M_ms(10);//5
- GPIO_Write(GPIOA,PIN9,GPIO_RESET);
- GPIO_Write(GPIOA,PIN11,GPIO_SET);
- GPIO_Write(GPIOA,PIN13,GPIO_SET);
- Delay16M_ms(10);//6
- GPIO_Write(GPIOA,PIN9,GPIO_RESET);
- GPIO_Write(GPIOA,PIN11,GPIO_RESET);
- GPIO_Write(GPIOA,PIN13,GPIO_SET);
- */
- ///---- Chapter 11 ADC test ---------------------------------------------------------------------------------
- ///---- Chapter 12 I2C test ---------------------------------------------------------------------------------
- //I2C_Write(0x2d,0x55);//适用于非中断模式
- //i2c_data = I2C_Read(0x2d);//适用于非中断模式
- //printf("data:%xrn",i2c_data);
- //I2C_Write(0x2d,0xaa);//适用于非中断模式
- //i2c_data = I2C_Read(0x2d);//适用于非中断模式
- //printf("data:%xrn",i2c_data);
- //I2C_Write_IT(0x2d,0x55);//适用于中断模式
- ///---- Chapter 13 SPI test --------------------------------------------------------------------------------
- //SPI1 Test
- //SPI_Transceive(SPI1,sTxpack,sRxpack,10);//非中断模式
- //SPI1_RW_reg(WRITE_REG+0x05,0x53);//读写Si24R1寄存器
- //REG_Data = SPI1_RW_reg(READ_REG+0x05,0);//读写Si24R1寄存器
- //printf("rnREG5:%02x",REG_Data);
- //delay16M_ms(500);
- //SPI2 Test
- //SPI_Transceive(SPI2,sTxpack,sRxpack,10);//非中断模式
- //SPI2_RW_reg(WRITE_REG+0x05,0x53);//读写Si24R1寄存器
- //REG_Data = SPI2_RW_reg(READ_REG+0x05,0);//读写Si24R1寄存器
- //printf("rnREG5:%02x",REG_Data);
- //delay16M_ms(500);
- ///---- Chapter 15 UART Test ------------------------------------------------------------------------------------
- //---- 非中断模式数据回环测试 -------------------------------------------------------------------------------------
- //Uart_Reveive(UART1,upack1,10);//适用于非中断发送模式
- //Uart_Send(UART1,upack1,10);//适用于非中断发送模式
- //Uart_Reveive(UART2,upack2,10);//适用于非中断发送模式
- //Uart_Send(UART2,upack2,10);//适用于非中断发送模式
- //Uart_Reveive(UART3,upack3,10);//适用于非中断发送模式
- //Uart_Send(UART3,upack3,10);//适用于非中断发送模式
- //Uart_Reveive(UART4,upack4,10);//适用于非中断发送模式
- //Uart_Send(UART4,upack4,10);//适用于非中断发送模式
- //---- 中断模式数据回环测试 --------------------------------------------------------------------------------------
- //UART1_putbuf(UART1_getbuf());
- //---- printf测试 ----------------------------------------------------------------------------------------
- //printf("Hellow-01234568789abcdefghijklmnopqrstuvwxyzrn");
- ///---- Chapter 17 RANDGEN test -----------------------------------------------------------------------------
- //rand_data = RAND_Get();//生成随机数
- //printf("rand:0x%08x,%urn",rand_data,rand_data);
- //delay16M_ms(500);
- ///---- Chapter 18 COMPARE test -----------------------------------------------------------------------------
- //if(COMP1->irq&0x1)
- //{
- //GPIO_Toggle(GPIOA,PIN15);
- //COMP1->irq = 1;
- //}
- //delay16M_ms(10);
- }
- return 0;
- }
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等
常用在工业控制系统上的MCU芯片资料:CSM32RV20
CSM32RV20是一款基于RISC-V核的低功耗MCU芯片。 内置RISC-V RV32IMAC内核(2.6CoreMark/MHz); 蕞高32MHz工作频率; 内置4kB的SRAM; 内置8B
有奖丨米尔 瑞芯微RK3576开发板免费试用
米尔与瑞芯微合作发布的新品基于瑞芯微RK3576应用处理器的MYD-LR3576开发板免费试用活动来啦~~米尔提供了7块价值849元的MYD-LR3576
【作品合集】龙芯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开发板发起试用活动您不仅可以免费体
香橙派发布首款RISC-V开发板OrangePi RV
2024年3月,香橙派在全球开发者会议上发布了其首款基于RISC-V开发的OrangePi RV主板。这款开发板拥有四核RISC-V U74与S7协处理器,配备
rv1126和rk3568对比
视频编解码。而RK3568开发板创龙科技旗下工业开发板,基于瑞芯微RK3568J/RK3568B2处理器设计,四核ARM Cortex-A55,每核主频高达1.8GHz/2.0GHz。
评论