This repository has been archived on 2024-11-23. You can view files and clone it, but cannot push or open issues or pull requests.
SSTV-Decoder/main.c

52 lines
1.4 KiB
C
Raw Normal View History

2023-04-28 00:19:56 +08:00
#include "adc.h"
2023-04-17 21:56:42 +08:00
#include "derivative.h"
#include "systick.h"
2023-04-27 01:30:27 +08:00
#include "tftlcd.h"
2023-04-17 21:56:42 +08:00
#include "uart.h"
#include <stdio.h>
#include <string.h>
int main(void) {
// Initialize
2023-04-28 00:19:56 +08:00
uart_init(UART_MSG, 9600); // Initialize UART1 with PC
uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt
LCD_Init(); // Initialize LCD
adc0_Init(); // Initialize ADC0
2023-04-17 21:56:42 +08:00
uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK);
uart_printf(UART_MSG, "Bus Clock: %lu\r\n", BUSCLK);
2023-04-28 00:19:56 +08:00
LCD_ShowString(LCD_W / 3, 0, "Audio Sample", 16, 0, 1);
LCD_DrawLine(0, 16, LCD_W - 1, 16);
uint16_t x0 = 16, y0 = 32;
uint16_t x1 = LCD_W - 8, y1 = LCD_H - 16;
uint16_t ym = (y0 + y1) / 2;
LCD_DrawLine(x0, y0, x0, y1);
LCD_DrawLine(x0, ym, x1, ym);
LCD_ShowChar(0, y0, 'A', 16, 0);
LCD_ShowChar(x1, ym, 'T', 16, 0);
LCD_SetColor(BACK_COLOR);
int16_t res;
uint16_t pos[x1 - x0 - 1];
uint16_t x = x0 + 1, y;
2023-04-17 21:56:42 +08:00
uint32_t timer = 0;
2023-04-28 01:59:54 +08:00
fADC = 1;
2023-04-28 00:19:56 +08:00
2023-04-17 21:56:42 +08:00
for (;;) {
2023-04-28 01:59:54 +08:00
if (timer_expired_50us(&timer, 1)) {
2023-04-28 00:19:56 +08:00
LCD_DrawPoint(x, pos[x - x0 - 1], BACK_COLOR);
2023-04-28 01:59:54 +08:00
res = adc_buf[pADC];
y = ym + res * (y1 - ym) / 2048;
2023-04-28 00:19:56 +08:00
LCD_DrawPoint(x, y, RED);
LCD_DrawPoint(x, ym, BLACK);
pos[x - x0 - 1] = y;
x = x + 1 < x1 ? x + 1 : x0 + 1;
2023-04-17 21:56:42 +08:00
}
}
}