SSTV-Decoder/main.c

119 lines
6.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "MMA8451Q.h"
#include "derivative.h"
#include "systick.h"
#include "tftlcd.h"
#include "tpm.h"
#include "uart.h"
#include <stdio.h>
#define L1 M1 * 2 // 低八度
#define L2 M2 * 2
#define L3 M3 * 2
#define L4 M4 * 2
#define L5 M5 * 2
#define L6 M6 * 2
#define L7 M7 * 2
#define M1 (unsigned short)(PWMCLK / 523)
#define M2 (unsigned short)(PWMCLK / 587)
#define M3 (unsigned short)(PWMCLK / 659)
#define M4 (unsigned short)(PWMCLK / 698)
#define M5 (unsigned short)(PWMCLK / 784)
#define M6 (unsigned short)(PWMCLK / 880)
#define M7 (unsigned short)(PWMCLK / 988)
#define H1 M1 / 2 // 高八度
#define H2 M2 / 2
#define H3 M3 / 2
#define H4 M4 / 2
#define H5 M5 / 2
#define H6 M6 / 2
#define H7 M7 / 2
#define NN 0 // 休止符
// 晴天 4/4拍 (以1/4音符为1拍每小节4拍)
#define N 204
#define BPM 67 // Beats Per Minute
const unsigned short note[] = {
NN, M5, M5, M1, M1, M2, M3, // 故事的小黄花
NN, M5, M5, M1, M1, M2, M3, M2, M1, L5, // 从出生那年就飘着
NN, M5, M5, M1, M1, M2, M3, // 童年的荡秋千
NN, M3, M2, M3, M4, M3, M2, M4, M3, M2, M1, // 随记忆一直晃到现在
L5, M1, M1, M3, M4, M3, M2, M1, M2, // rui sou sou xi dou xi la sou la
M3, M3, M3, M3, M2, M3, M2, M1, // xi xi xi xi la xi la sou
L5, M1, M2, M3, M4, M3, M2, M1, M2, // 吹着前奏望着天空 我
M3, M3, M3, M3, M2, M3, M2, M1, L7, // 想起花瓣试着掉落 为
M1, M1, M1, M1, L7, M1, M1, M1, M1, M1, M1, L7, M1, M1, // 你翘课的那一天 花落的那一天
M1, M1, M1, M1, L7, M1, M1, M1, M1, M1, M1, M5, M5, M5, // 教室的那一间 我怎么看不见
NN, M5, M5, M5, M5, M5, M5, M5, M5, M5, M5, M5, M4, M3, M3, // 消失的下雨天 我好想再淋一遍
M3, M3, NN, M1, M1, M1, M1, // 没想到失
L6, L7, M1, M5, M4, M3, M1, M1, // 去的勇气我还留着
M1, NN, M1, M1, M1, M1, M3, M1, // 好想再问一遍
L6, L7, M1, M5, M4, M3, M1, M2, // 你会等待还是离开
M2, M2, NN, NN, // Null
M3, M2, M4, M3, M1, M5, M7, // 刮风这天 我试过
H1, M7, M1, M1, M1, M6, M6, // 握着你手 但偏偏
NN, M6, M5, M5, M5, M4, M3, // 雨渐渐 大到我
M2, M3, M4, M3, M3, M3, // 看你不见
M3, M4, M5, M3, M4, M5, M7, // 还有多久 我才能
H2, M7, H1, H1, NN, H1, // 在你身边 等
H1, M5, M5, M6, M5, M4, M4, M2, M3, // 到放晴的那天 也许
M4, M5, M6, M1, M6, M7, M7, // 我会比较好一点
};
const unsigned short duration[] = {
0x02, 0x02, 0x02, 0x02, 0x04, 0x02, 0x02, // 故事的小黄花
0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, // 从出生那年就飘着
0x02, 0x02, 0x02, 0x02, 0x04, 0x02, 0x02, // 童年的荡秋千
0x02, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, // 随记忆一直晃到现在
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, // rui sou sou xi dou xi la sou la
0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x04, // xi xi xi xi la xi la sou
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, // 吹着前奏望着天空 我
0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x03, 0x01, // 想起花瓣试着掉落 为
0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, // 你翘课的那一天 花落的那一天
0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, // 教室的那一间 我怎么看不见
0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, // 消失的下雨天 我好想再淋一遍
0x04, 0x04, 0x04, 0x01, 0x01, 0x01, 0x01, // 没想到失
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 去的勇气我还留着
0x04, 0x04, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, // 好想再问一遍
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 你会等待还是离开
0x04, 0x04, 0x00, 0x00, // Null
0x02, 0x02, 0x02, 0x04, 0x02, 0x02, 0x02, // 刮风这天 我试过
0x02, 0x02, 0x02, 0x04, 0x02, 0x02, 0x02, // 握着你手 但偏偏
0x02, 0x02, 0x02, 0x04, 0x02, 0x02, 0x02, // 雨渐渐 大到我
0x02, 0x02, 0x02, 0x02, 0x04, 0x04, // 看你不见
0x02, 0x02, 0x02, 0x04, 0x02, 0x02, 0x02, // 还有多久 我才能
0x02, 0x02, 0x02, 0x06, 0x02, 0x02, // 在你身边 等
0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x02, // 到放晴的那天 也许
0x02, 0x02, 0x02, 0x02, 0x03, 0x01, 0x04, // 我会比较好一点
}; // 1/4音符为0x04, 最短为1/16音符
int main(void) {
// Initialize
SysTick_Config(CORCLK / 1000); // Period of systick timer : 1 ms
tpm_init(TPM0, 4); // Initialize TPM0_CH4
LCD_Init(); // Initialize LCD
// TMP0_CH4 -> PTC8
SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK;
PORTC->PCR[8] = PORT_PCR_MUX(3); // Select TPM0_CH4
LCD_ShowChar(30, 30, 65, 12, 0);
// uint16_t beat_time = (uint16_t)(60 * 1000.0 / BPM);
// uint32_t timer, period;
// for (uint8_t i = 0;;) {
// period = (uint32_t)(duration[i] * beat_time / 0x04);
// timer = tick_cnt + period;
// while (tick_cnt < timer) {
// uint16_t delta = (uint16_t)(timer - tick_cnt);
// uint16_t val = (uint16_t)(note[i] / 2 * (period - delta) / period);
// tpm_set(TPM0, note[i], val, 4);
// }
// i = (uint8_t)((i + 1) % N);
// if (timer_expired(&timer, period)) {
// tpm_set(TPM0, note[i], note[i] / 2, 4);
// i = (uint8_t)((i + 1) % N);
// }
}