1
串口发送函数
u8 fput8bit(u8 Data)
{
while((UART5->SR&0X40)==0);//循环发送,直到发送完毕
UART5->DR = Data;
return Data;
}
2
初始化IO 串口1函数
//pclk2:PCLK2时钟频率(Mhz)
//bound:波特率
void uart_init(u32 pclk2,u32 bound)
{
float temp;
u16 mantissa;
u16 fraction;
temp=(float)(pclk2*1000000)/(bound*16);//得到USARTDIV@OVER8=0
mantissa=temp; //得到整数部分
fraction=(temp-mantissa)*16; //得到小数部分@OVER8=0
mantissa<<=4;
mantissa+=fraction;
RCC->AHB1ENR|=1<<2; //使能PORTC口时钟,TX
RCC->AHB1ENR|=1<<3; //使能PORTD口时钟,RX
RCC->APB1ENR|=1<<20; //使能串口1时钟,UART5 P245(EN)
GPIO_Set(GPIOC,PIN12,GPIO_MODE_AF,GPIO_OTYPE_PP,GPIO_SPEED_50M,GPIO_PUPD_PU);//PA9,PA10,复用功能,上拉输?
GPIO_Set(GPIOD,PIN2,GPIO_MODE_AF,GPIO_OTYPE_PP,GPIO_SPEED_50M,GPIO_PUPD_PU);//PA9,PA10,复用功能,上拉输出?
GPIO_AF_Set(GPIOC,12,8); //PA9,AF7 继续确认
GPIO_AF_Set(GPIOD,2,8);//PA10,AF7
//波特率设置
UART5->BRR=mantissa; //波特率设置
UART5->CR1&=~(1<<15); //设置OVER8=0
UART5->CR1|=1<<3; //串口发送使能
#if EN_UART5_RX //如果使能了接收
//使能接收中断
UART5->CR1|=1<<2; //串口接收使能
UART5->CR1|=1<<5; //接收缓冲区非空中断使能
MY_NVIC_Init(3,3,UART5_IRQn,2);//组2,最低优先级
#endif
UART5->CR1|=1<<13; //串口使能
}
3
ASCII码表
Bin Dec Hex 缩写/字符 解释
00000000 0 00 NUL(null) 空字符
00000001 1 01 SOH(start of headling) 标题开始
00000010 2 02 STX (start of text) 正文开始
00000011 3 03 ETX (end of text) 正文结束
00000100 4 04 EOT (end of transmission) 传输结束
00000101 5 05 ENQ (enquiry) 请求
00000110 6 06 ACK (acknowledge) 收到通知
00000111 7 07 BEL (bell) 响铃
00001000 8 08 BS (backspace) 退格
00001001 9 09 HT (horizontal tab) 水平制表符
00001010 10 0A LF (NL line feed, new line) 换行键
00001011 11 0B VT (vertical tab) 垂直制表符
00001100 12 0C FF (NP form feed, new page) 换页键
00001101 13 0D CR (carriage return) 回车键
00001110 14 0E SO (shift out) 不用切换
00001111 15 0F SI (shift in) 启用切换
00010000 16 10 DLE (data link escape) 数据链路转义
00010001 17 11 DC1 (device control 1) 设备控制1
00010010 18 12 DC2 (device control 2) 设备控制2
00010011 19 13 DC3 (device control 3) 设备控制3
00010100 20 14 DC4 (device control 4) 设备控制4
00010101 21 15 NAK (negative acknowledge) 拒绝接收
00010110 22 16 SYN (synchronous idle) 同步空闲
00010111 23 17 ETB (end of trans. block) 传输块结束
00011000 24 18 CAN (cancel) 取消
00011001 25 19 EM (end of medium) 介质中断
00011010 26 1A SUB (substitute) 替补
00011011 27 1B ESC (escape) 溢出
00011100 28 1C FS (file separator) 文件分割符
00011101 29 1D GS (group separator) 分组符
00011110 30 1E RS (record separator) 记录分离符
00011111 31 1F US (unit separator) 单元分隔符
00100000 32 20 (space) 空格
00100001 33 21 !
00100010 34 22 "
00100011 35 23 #
00100100 36 24 $
00100101 37 25 %
00100110 38 26 &
00100111 39 27 '
00101000 40 28 (
00101001 41 29 )
00101010 42 2A *
00101011 43 2B +
00101100 44 2C ,
00101101 45 2D -
00101110 46 2E .
00101111 47 2F /
00110000 48 30 0
00110001 49 31 1
00110010 50 32 2
00110011 51 33 3
00110100 52 34 4
00110101 53 35 5
00110110 54 36 6
00110111 55 37 7
00111000 56 38 8
00111001 57 39 9
00111010 58 3A :
00111011 59 3B ;
00111100 60 3C <
00111101 61 3D =
00111110 62 3E >
00111111 63 3F ?
01000000 64 40 @
01000001 65 41 A
01000010 66 42 B
01000011 67 43 C
01000100 68 44 D
01000101 69 45 E
01000110 70 46 F
01000111 71 47 G
01001000 72 48 H
01001001 73 49 I
01001010 74 4A J
01001011 75 4B K
01001100 76 4C L
01001101 77 4D M
01001110 78 4E N
01001111 79 4F O
01010000 80 50 P
01010001 81 51 Q
01010010 82 52 R
01010011 83 53 S
01010100 84 54 T
01010101 85 55 U
01010110 86 56 V
01010111 87 57 W
01011000 88 58 X
01011001 89 59 Y
01011010 90 5A Z
01011011 91 5B [
01011100 92 5C \
01011101 93 5D ]
01011110 94 5E ^
01011111 95 5F _
01100000 96 60 `
01100001 97 61 a
01100010 98 62 b
01100011 99 63 c
01100100 100 64 d
01100101 101 65 e
01100110 102 66 f
01100111 103 67 g
01101000 104 68 h
01101001 105 69 i
01101010 106 6A j
01101011 107 6B k
01101100 108 6C l
01101101 109 6D m
01101110 110 6E n
01101111 111 6F o
01110000 112 70 p
01110001 113 71 q
01110010 114 72 r
01110011 115 73 s
01110100 116 74 t
01110101 117 75 u
01110110 118 76 v
01110111 119 77 w
01111000 120 78 x
01111001 121 79 y
01111010 122 7A z
01111011 123 7B {
01111100 124 7C |
01111101 125 7D }
01111110 126 7E ~
01111111 127 7F DEL (delete) 删除
4
string数组的定义
String arr[] = new String[10]; //创建一个长度为10的String 类型数组。
String arr[] = {"张三","李四"};
String[] arr = new String[10];
5
String与int互转
将字串 String 转换成整数 int
int i = Integer.parseInt([String]);
i = Integer.parseInt([String],[int radix]);
int i = Integer.valueOf(my_str).intValue()。
将整数 int 转换成字串 String
String s = String.valueOf(i);
String s = Integer.toString(i);
String s = "" + i。
https://www.cnblogs.com/cnugis/p/7650111.html
https://blog.youkuaiyun.com/fendouaini/article/details/75209163
https://blog.youkuaiyun.com/yat_chiu/article/details/72851316?utm_source=itdadao&utm_medium=referral
https://blog.youkuaiyun.com/leviopku/article/details/78510977
6
tf.expand_dims()
在第axis位置增加一个维度
给定张量输入,此操作在输入形状的维度索引轴处插入1的尺寸。 尺寸索引轴从零开始; 如果您指定轴的负数,则从最后向后计数。
如果要将批量维度添加到单个元素,则此操作非常有用。
例如,如果您有一个单一的形状[height,width,channels],您可以使用expand_dims(image,0)使其成为1个图像,这将使形状[1,高度,宽度,通道]。
# 't' is a tensor of shape [2]
shape(expand_dims(t, 0)) ==> [1, 2]
shape(expand_dims(t, 1)) ==> [2, 1]
shape(expand_dims(t, -1)) ==> [2, 1]
# 't2' is a tensor of shape [2, 3, 5]
shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5]
shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5]
shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]
7
tf.squeeze()
从tensor中删除所有大小是1的维度
给定张量输入,此操作返回相同类型的张量,并删除所有尺寸为1的尺寸。
如果不想删除所有尺寸1尺寸,可以通过指定squeeze_dims来删除特定尺寸1尺寸。
如果不想删除所有大小是1的维度,可以通过squeeze_dims指定。
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
shape(squeeze(t)) ==> [2, 3]
Or, to remove specific size 1 dimensions:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
shape(squeeze(t, [2, 4])) ==> [1, 2, 3, 1]
8
用 TENSORFLOW 实现神经网络常见层
import tensorflow as tf
import numpy as np
sess = tf.Session()
data_size = 25
data_1d = np.random.normal(size=data_size)
x_input_1d = tf.placeholder(dtype=tf.float32, shape=[data_size])
def conv_layer_1d(input_1d, my_filter):
# make 1d input into 4d
input_2d = tf.expand_dims(input_1d, 0)
input_3d = tf.expand_dims(input_2d, 0)
input_4d = tf.expand_dims(input_3d, 3)
# perform convolution
convolution_output = tf.nn.conv2d(input_4d, filter=my_filter,
strides=[1,1,1,1], padding="VALID")
conv_output_1d = tf.squeeze(convolution_output)
return(conv_output_1d)
my_filter = tf.Variable(tf.random_normal(shape=[1,5,1,1]))
my_convolution_output = conv_layer_1d(x_input_1d, my_filter)
9
https://blog.youkuaiyun.com/m0_37167788/article/details/79066487